mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 16:37:43 +01:00
Anvil repair/damage options
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
--- a/net/minecraft/world/level/block/AnvilBlock.java
|
||||
+++ b/net/minecraft/world/level/block/AnvilBlock.java
|
||||
@@ -59,6 +_,53 @@
|
||||
return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getClockWise());
|
||||
}
|
||||
|
||||
+ // Purpur start - Anvil repair/damage options
|
||||
+ @Override
|
||||
+ protected net.minecraft.world.InteractionResult useItemOn(final net.minecraft.world.item.ItemStack stack, final BlockState state, final Level world, final BlockPos pos, final Player player, final net.minecraft.world.InteractionHand hand, final BlockHitResult hit) {
|
||||
+ if (world.purpurConfig.anvilRepairIngotsAmount > 0 && stack.is(net.minecraft.world.item.Items.IRON_INGOT)) {
|
||||
+ if (stack.getCount() < world.purpurConfig.anvilRepairIngotsAmount) {
|
||||
+ // not enough iron ingots, play "error" sound and consume
|
||||
+ world.playSound(null, pos, net.minecraft.sounds.SoundEvents.ANVIL_HIT, net.minecraft.sounds.SoundSource.BLOCKS, 1.0F, 1.0F);
|
||||
+ return net.minecraft.world.InteractionResult.CONSUME;
|
||||
+ }
|
||||
+ if (state.is(Blocks.DAMAGED_ANVIL)) {
|
||||
+ world.setBlock(pos, Blocks.CHIPPED_ANVIL.defaultBlockState().setValue(FACING, state.getValue(FACING)), 3);
|
||||
+ } else if (state.is(Blocks.CHIPPED_ANVIL)) {
|
||||
+ world.setBlock(pos, Blocks.ANVIL.defaultBlockState().setValue(FACING, state.getValue(FACING)), 3);
|
||||
+ } else if (state.is(Blocks.ANVIL)) {
|
||||
+ // anvil is already fully repaired, play "error" sound and consume
|
||||
+ world.playSound(null, pos, net.minecraft.sounds.SoundEvents.ANVIL_HIT, net.minecraft.sounds.SoundSource.BLOCKS, 1.0F, 1.0F);
|
||||
+ return net.minecraft.world.InteractionResult.CONSUME;
|
||||
+ }
|
||||
+ if (!player.getAbilities().instabuild) {
|
||||
+ stack.shrink(world.purpurConfig.anvilRepairIngotsAmount);
|
||||
+ }
|
||||
+ world.playSound(null, pos, net.minecraft.sounds.SoundEvents.ANVIL_PLACE, net.minecraft.sounds.SoundSource.BLOCKS, 1.0F, 1.0F);
|
||||
+ return net.minecraft.world.InteractionResult.CONSUME;
|
||||
+ }
|
||||
+ if (world.purpurConfig.anvilDamageObsidianAmount > 0 && stack.is(net.minecraft.world.item.Items.OBSIDIAN)) {
|
||||
+ if (stack.getCount() < world.purpurConfig.anvilDamageObsidianAmount) {
|
||||
+ // not enough obsidian, play "error" sound and consume
|
||||
+ world.playSound(null, pos, net.minecraft.sounds.SoundEvents.ANVIL_HIT, net.minecraft.sounds.SoundSource.BLOCKS, 1.0F, 1.0F);
|
||||
+ return net.minecraft.world.InteractionResult.CONSUME;
|
||||
+ }
|
||||
+ if (state.is(Blocks.DAMAGED_ANVIL)) {
|
||||
+ world.destroyBlock(pos, false);
|
||||
+ } else if (state.is(Blocks.CHIPPED_ANVIL)) {
|
||||
+ world.setBlock(pos, Blocks.DAMAGED_ANVIL.defaultBlockState().setValue(FACING, state.getValue(FACING)), 3);
|
||||
+ } else if (state.is(Blocks.ANVIL)) {
|
||||
+ world.setBlock(pos, Blocks.CHIPPED_ANVIL.defaultBlockState().setValue(FACING, state.getValue(FACING)), 3);
|
||||
+ }
|
||||
+ if (!player.getAbilities().instabuild) {
|
||||
+ stack.shrink(world.purpurConfig.anvilDamageObsidianAmount);
|
||||
+ }
|
||||
+ world.playSound(null, pos, net.minecraft.sounds.SoundEvents.ANVIL_LAND, net.minecraft.sounds.SoundSource.BLOCKS, 1.0F, 1.0F);
|
||||
+ return net.minecraft.world.InteractionResult.CONSUME;
|
||||
+ }
|
||||
+ return net.minecraft.world.InteractionResult.TRY_WITH_EMPTY_HAND;
|
||||
+ }
|
||||
+ // Purpur end - Anvil repair/damage options
|
||||
+
|
||||
@Override
|
||||
protected InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult hitResult) {
|
||||
if (!level.isClientSide) {
|
||||
Reference in New Issue
Block a user