-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from florian-berger/feature-4
feature-4: Multi-Tool
- Loading branch information
Showing
17 changed files
with
261 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/main/java/biz/berger_media/indestructibletools/events/RightClickBlockEventListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/main/java/biz/berger_media/indestructibletools/item/ItemIndestructibleMultiTool.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/main/resources/assets/indestructibletools/models/item/indestructible_multitool.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"parent": "minecraft:item/handheld", | ||
"textures": { | ||
"layer0": "indestructibletools:items/indestructible_multitool" | ||
} | ||
} |
Binary file added
BIN
+5.28 KB
...esources/assets/indestructibletools/textures/items/indestructible_multitool.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions
34
...ain/resources/data/indestructibletools/advancements/recipes/indestructible_multitool.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
] | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/resources/data/indestructibletools/recipes/indestructible_multitool.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |