Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature-4: Multi-Tool #5

Merged
merged 6 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Florian Berger
Copyright (c) 2021-2022 Florian Berger

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
31 changes: 27 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,38 @@ The 'Mending' enchantment isn't enough for me. So I created a mod that adds such


## Recipes
The following recipes are added to the game:\
To craft the ingot, use the following shapeless recipe:\
![Recipe_Ingot](/curseforge/images/Recipe_Ingot.png?raw=true)

With these ingots, you are able to craft the known tools by using the known patterns:\
![Recipes_Gif](/curseforge/images/tools-recipes.gif?raw=true)


<details>
<summary>Recipes as static images</summary>

**Axe**\
![Recipe_Axe](/curseforge/images/Recipe_Axe.png?raw=true)

**Hoe**\
![Recipe_Hoe](/curseforge/images/Recipe_Hoe.png?raw=true)

**Pickaxe**\
![Recipe_Pickaxe](/curseforge/images/Recipe_Pickaxe.png?raw=true)

**Shovel**\
![Recipe_Shovel](/curseforge/images/Recipe_Shovel.png?raw=true)

**Sword**\
![Recipe_Sword](/curseforge/images/Recipe_Sword.png?raw=true)
</details>

## Multi-Tool
From **Version 2022.1**, this modification contains a multi-tool. It combines the capabilities of the pickaxe, the shovel and the axe. You can craft it by using the following recipe:\
![Recipe_MultiTool](/curseforge/images/Recipe_Multitool.png?raw=true)
\
Thanks to [Fundryi](https://github.com/Fundryi) for the [Multi-Tool suggestion](https://github.com/florian-berger/indestructible-tools/issues/4)!

### Using in modpacks
You can use this mod in every modpack that is available for free. You are allowed to distribute the mod file in an own ModPack launcher.
Just add a link to this repository, [my website](https://berger-media.biz/downloads/10/minecraft/indestructible-tools) or the [CurseForge page](https://www.curseforge.com/minecraft/mc-mods/indestructible-tools) of this modification.
## Usage in modpacks
You can use this mod in every modpack that is available for free. You are allowed to distribute the mod file in an own ModPack launcher.\
If the modpack is not distributed via CurseForge, you need to add a link to this repository, [my website](https://berger-media.biz/downloads/10/minecraft/indestructible-tools) or the [CurseForge page](https://www.curseforge.com/minecraft/mc-mods/indestructible-tools) of this modification.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'

version = '2021.2.1'
version = '2022.1.0'
group = 'biz.berger_media.indestructibletools' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'indestructibletools'

Expand All @@ -27,7 +27,7 @@ minecraft {
// stable_# Stables are built at the discretion of the MCP team.
// Use non-default mappings at your own risk. they may not always work.
// Simply re-run your setup task after changing the mappings to update your workspace.
mappings channel: 'official', version: '1.18'
mappings channel: 'official', version: '1.18.1'
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.

// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
Expand Down Expand Up @@ -113,7 +113,7 @@ dependencies {
// Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed
// that the dep is a ForgeGradle 'patcher' dependency. And it's patches will be applied.
// The userdev artifact is a special name and will get all sorts of transformations applied to it.
minecraft 'net.minecraftforge:forge:1.18-38.0.14'
minecraft 'net.minecraftforge:forge:1.18.1-39.0.59'

// Real mod deobf dependency examples - these get remapped to your current mappings
// compileOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}:api") // Adds JEI API as a compile dependency
Expand All @@ -136,7 +136,7 @@ jar {
"Specification-Vendor": "indestructibletoolssareus",
"Specification-Version": "1", // We are version 1 of ourselves
"Implementation-Title": project.name,
"Implementation-Version": "${version}",
"Implementation-Version": project.jar.archiveVersion,
"Implementation-Vendor" :"indestructibletoolssareus",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
])
Expand Down
Binary file added curseforge/images/Recipe_Multitool.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added curseforge/images/tools-recipes.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gimp/indestructible_multitool.xcf
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package biz.berger_media.indestructibletools;

import biz.berger_media.indestructibletools.events.RightClickBlockEventListener;
import biz.berger_media.indestructibletools.item.IndestructibleItems;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.common.Mod;
Expand All @@ -20,6 +23,8 @@ public class IndestructibleTools {
*/
public static final String MOD_ID = "indestructibletools";

public static final BlockState DirtPathState = Blocks.DIRT_PATH.defaultBlockState();

/**
* Creates an instance of the mod
*/
Expand All @@ -30,6 +35,7 @@ public IndestructibleTools() {
IndestructibleItems.ITEMS.register(bus);

MinecraftForge.EVENT_BUS.register(this);
MinecraftForge.EVENT_BUS.register(new RightClickBlockEventListener());
}

private void setup(final FMLCommonSetupEvent event) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package biz.berger_media.indestructibletools.events;

import biz.berger_media.indestructibletools.IndestructibleTools;
import biz.berger_media.indestructibletools.item.ItemIndestructibleMultiTool;
import net.minecraft.core.BlockPos;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.eventbus.api.SubscribeEvent;

public class RightClickBlockEventListener {
/**
* Listener for the RightClick event on a block
*/
@SubscribeEvent
public void onRightClick(PlayerInteractEvent.RightClickBlock event) {
if (event.getResult() != Event.Result.DEFAULT || event.isCanceled()) {
return;
}

Player player = event.getPlayer();
Level world = event.getWorld();
InteractionHand hand = event.getHand();

if (player.getItemInHand(hand).getItem() instanceof ItemIndestructibleMultiTool) {
BlockPos pos = event.getPos();
if (world.getBlockState(pos.above()).getMaterial() == Material.AIR) {
BlockState state = world.getBlockState(pos);
if (isConvertible(state)) {
convertToPath(world, pos, player, hand);
}
}
}
}

/**
* Checks if the target block can be converted to a Dirt Path
*/
private static boolean isConvertible(BlockState state) {
Block block = state.getBlock();
return block == Blocks.COARSE_DIRT || block == Blocks.DIRT ||
block == Blocks.MYCELIUM || block == Blocks.PODZOL ||
block == Blocks.GRASS_BLOCK;
}

/**
* Replaces a block at position with a dirt path and plays a sound
*
* @param world World where the block should be replaced
* @param pos Position that should be replaced
* @param player Player that is replacing the block
* @param hand Hand that should swing
*/
private static void convertToPath(Level world, BlockPos pos, Player player, InteractionHand hand) {
world.playSound(player, pos, SoundEvents.SHOVEL_FLATTEN, SoundSource.BLOCKS, 1.0F, 1.0F);
player.swing(hand);

if (!world.isClientSide) {
world.setBlock(pos, IndestructibleTools.DirtPathState, 11);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ public class IndestructibleItems {
public static final RegistryObject<HoeItem> INDESTRUCTIBLE_HOE =
ITEMS.register("indestructible_hoe", ItemIndestructibleHoe::new);

public static final RegistryObject<Item> INDESTRUCTIBLE_MULTITOOL =
ITEMS.register("indestructible_multitool", ItemIndestructibleMultiTool::new);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package biz.berger_media.indestructibletools.item;

import biz.berger_media.indestructibletools.helpers.EnchantmentHelper;
import biz.berger_media.indestructibletools.helpers.ItemHelper;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.PickaxeItem;
import net.minecraft.world.item.Tiers;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.level.block.state.BlockState;

/**
* Class that represents the Multi-Tool (can be used as different tool)
*/
public class ItemIndestructibleMultiTool extends PickaxeItem {
public ItemIndestructibleMultiTool() {
super(Tiers.NETHERITE, 4, -1.5F, ItemHelper.getProperties());
}

@Override
public boolean isFireResistant() {
return true;
}

@Override
public boolean isDamageable(ItemStack stack) {
return false;
}

@Override
public float getDestroySpeed(ItemStack stack, BlockState state) {
if (state.is(BlockTags.MINEABLE_WITH_AXE)) {
return this.speed;
}

if (state.is(BlockTags.MINEABLE_WITH_SHOVEL)) {
return this.speed;
}

return super.getDestroySpeed(stack, state);
}

@Override
public boolean isCorrectToolForDrops(ItemStack stack, BlockState state) {
if (state.is(BlockTags.MINEABLE_WITH_AXE)) {
return true;
}

if (state.is(BlockTags.MINEABLE_WITH_SHOVEL)) {
return true;
}

return super.isCorrectToolForDrops(stack, state);
}

@Override
public boolean isEnchantable(ItemStack stack) {
return !stack.isEnchanted();
}

@Override
public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) {
if (EnchantmentHelper.isInvalidEnchantment(enchantment)) {
return false;
}

return super.canApplyAtEnchantingTable(stack, enchantment);
}

@Override
public boolean isBookEnchantable(ItemStack stack, ItemStack book) {
if (EnchantmentHelper.isBookEnchantedWithInvalidSpell(book)) {
return false;
}

return super.isBookEnchantable(stack, book);
}
}
6 changes: 3 additions & 3 deletions src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
modLoader="javafml" #mandatory

loaderVersion="[38,)"
loaderVersion="[39,)"

license="https://github.com/florian-berger/indestructible-tools/blob/master/LICENSE"
issueTrackerURL="https://github.com/florian-berger/indestructible-tools/issues"


[[mods]]
modId="indestructibletools"
version="2021.2.1"
version="2022.1.0"
displayName="Indestructible Tools"
logoFile="indestructibletools.png"

Expand All @@ -22,7 +22,7 @@ This mod is adding some indestructible tools to Minecraft. They are crafted by u
# the modid of the dependency
modId="forge"
mandatory=true
versionRange="[38,)"
versionRange="[39,)"
ordering="NONE"
side="BOTH"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"item.indestructibletools.indestructible_shovel": "Unzerstörbare Schaufel",
"item.indestructibletools.indestructible_sword": "Unzerstörbares Schwert",
"item.indestructibletools.indestructible_hoe": "Unzerstörbare Hacke",
"item.indestructibletools.indestructible_multitool": "Unzerstörbares Mehrfach-Werkzeug",
"item.indestructibletools.indestructible_ingot": "Unzerstörbarer Barren"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"item.indestructibletools.indestructible_shovel": "Indestructible shovel",
"item.indestructibletools.indestructible_sword": "Indestructible sword",
"item.indestructibletools.indestructible_hoe": "Indestructible hoe",
"item.indestructibletools.indestructible_multitool": "Indestructible multitool",
"item.indestructibletools.indestructible_ingot": "Indestructible ingot"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "indestructibletools:items/indestructible_multitool"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"parent": "minecraft:recipes/root",
"rewards": {
"recipes": [
"indestructibletools:indestructible_multitool"
]
},
"criteria": {
"has_ingot": {
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{
"items": [
"indestructibletools:indestructible_pickaxe"
]
}
]
}
},
"has_the_recipe": {
"trigger": "minecraft:recipe_unlocked",
"conditions": {
"recipe": "indestructibletools:indestructible_multitool"
}
}
},
"requirements": [
[
"has_ingot",
"has_the_recipe"
]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
"PSA",
"#I#",
" I "
],
"key": {
"#": {
"item": "minecraft:string"
},
"I": {
"item": "minecraft:stick"
},
"P": {
"item": "indestructibletools:indestructible_pickaxe"
},
"S": {
"item": "indestructibletools:indestructible_shovel"
},
"A": {
"item": "indestructibletools:indestructible_axe"
}
},
"result": {
"item": "indestructibletools:indestructible_multitool"
}
}