Files
Purpur/patches/server/0244-Anvil-repair-damage-options.patch
granny 642956fe61 Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@850b736 Close PRs opened from orgs or bot accounts (#10281)
PaperMC/Paper@54a2340 check if itemstack is stackable first (#10285)
PaperMC/Paper@9c4bb0d add rich message component support to configuration (#10225)
PaperMC/Paper@8870d22 Fire EntityDamageByEntityEvent for unowned wither skulls patch (#10244)
PaperMC/Paper@bbc03d8 improve BanList types (#10239)
PaperMC/Paper@ce5c8dd Configurable max block/fluid ticks (#10266)
PaperMC/Paper@880fef7 Deprecate extra ban methods with raw BanEntry (#9580)
PaperMC/Paper@60218cd Don't tick empty worlds (#9025)
PaperMC/Paper@b21eb4d add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta (#10245)
PaperMC/Paper@89d51d5 Allow enabling sand duping (#10191)
PaperMC/Paper@6ad63fb Per world ticks per spawn settings (#6891)
2024-03-03 23:38:36 -08:00

84 lines
5.2 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 9fca247f51e8b4d445f61ab5c16faf3928626deb..583bb1282fedcab75dbe4359a9f53b76a538d903 100644
--- a/src/main/java/net/minecraft/world/level/block/AnvilBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/AnvilBlock.java
@@ -62,6 +62,54 @@ public class AnvilBlock extends FallingBlock {
@Override
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
+ // Purpur start - repairable/damageable anvils
+ if (world.purpurConfig.anvilRepairIngotsAmount > 0) {
+ net.minecraft.world.item.ItemStack itemstack = player.getItemInHand(hand);
+ if (itemstack.is(net.minecraft.world.item.Items.IRON_INGOT)) {
+ if (itemstack.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 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 InteractionResult.CONSUME;
+ }
+ if (!player.getAbilities().instabuild) {
+ itemstack.shrink(world.purpurConfig.anvilRepairIngotsAmount);
+ }
+ world.playSound(null, pos, net.minecraft.sounds.SoundEvents.ANVIL_PLACE, net.minecraft.sounds.SoundSource.BLOCKS, 1.0F, 1.0F);
+ return InteractionResult.CONSUME;
+ }
+ }
+ if (world.purpurConfig.anvilDamageObsidianAmount > 0) {
+ net.minecraft.world.item.ItemStack itemstack = player.getItemInHand(hand);
+ if (itemstack.is(net.minecraft.world.item.Items.OBSIDIAN)) {
+ if (itemstack.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 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) {
+ itemstack.shrink(world.purpurConfig.anvilDamageObsidianAmount);
+ }
+ world.playSound(null, pos, net.minecraft.sounds.SoundEvents.ANVIL_LAND, net.minecraft.sounds.SoundSource.BLOCKS, 1.0F, 1.0F);
+ return InteractionResult.CONSUME;
+ }
+ }
+ // Purpur end
if (world.isClientSide) {
return InteractionResult.SUCCESS;
} else {
diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
index 2b5475c0032171fec4a5e8a7b435168c5b95b17b..d00d9068134957fb76740e94e7cce055d8ea9f43 100644
--- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
+++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
@@ -820,9 +820,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;