mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 16:37:43 +01:00
83 lines
5.3 KiB
Diff
83 lines
5.3 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: 12emin34 <macanovic.emin@gmail.com>
|
|
Date: Sat, 12 Feb 2022 01:08:18 +0100
|
|
Subject: [PATCH] Anvil repair/damage options
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/AnvilBlock.java b/src/main/java/net/minecraft/world/level/block/AnvilBlock.java
|
|
index 50c907c962f936d2035bb7550750cdbd220b29c2..7f07a38553325056ab4ae65895c8c5c12cb41a1f 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/AnvilBlock.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/AnvilBlock.java
|
|
@@ -59,6 +59,53 @@ public class AnvilBlock extends FallingBlock {
|
|
return this.defaultBlockState().setValue(FACING, ctx.getHorizontalDirection().getClockWise());
|
|
}
|
|
|
|
+ // Purpur start - repairable/damageable anvils
|
|
+ @Override
|
|
+ protected net.minecraft.world.ItemInteractionResult 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.ItemInteractionResult.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.ItemInteractionResult.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.ItemInteractionResult.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.ItemInteractionResult.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.ItemInteractionResult.CONSUME;
|
|
+ }
|
|
+ return net.minecraft.world.ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
|
|
+ }
|
|
+ // Purpur end
|
|
+
|
|
@Override
|
|
protected InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) {
|
|
if (!world.isClientSide) {
|
|
diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
|
index bd48ba4acf41ec77f542ca7e8dfe6280bb2fbed1..9f4f3d94e6790b29cfda030780d95caf48eee0e5 100644
|
|
--- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
|
+++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
|
@@ -786,9 +786,13 @@ public class PurpurWorldConfig {
|
|
|
|
public boolean anvilAllowColors = false;
|
|
public boolean anvilColorsUseMiniMessage;
|
|
+ public int anvilRepairIngotsAmount = 0;
|
|
+ public int anvilDamageObsidianAmount = 0;
|
|
private void anvilSettings() {
|
|
anvilAllowColors = getBoolean("blocks.anvil.allow-colors", anvilAllowColors);
|
|
anvilColorsUseMiniMessage = getBoolean("blocks.anvil.use-mini-message", anvilColorsUseMiniMessage);
|
|
+ anvilRepairIngotsAmount = getInt("blocks.anvil.iron-ingots-used-for-repair", anvilRepairIngotsAmount);
|
|
+ anvilDamageObsidianAmount = getInt("blocks.anvil.obsidian-used-for-damage", anvilDamageObsidianAmount);
|
|
}
|
|
|
|
public double azaleaGrowthChance = 0.0D;
|