mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 08:27:43 +01:00
Shears can defuse TNT
Shears can now defuse TNT. Each world can have a configured chance for the TNT to be defused when right clicking with a set of shears and damage dealt to the shears accordingly. If the TNT is defused then it will drop the TNT item instead and the entity removed from the world no longer existing. All the interaction is handled within the net.minecraft.world.entity.item.PrimedTnt class similar to how it is handled for when sheep are sheared. By default the option is disabled to avoid breaking any possible vanilla mechanics.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
--- a/net/minecraft/world/entity/item/PrimedTnt.java
|
||||
+++ b/net/minecraft/world/entity/item/PrimedTnt.java
|
||||
@@ -251,4 +_,32 @@
|
||||
return !this.level().paperConfig().fixes.preventTntFromMovingInWater && super.isPushedByFluid();
|
||||
}
|
||||
// Paper end - Option to prevent TNT from moving in water
|
||||
+
|
||||
+ // Purpur start - Shears can defuse TNT
|
||||
+ @Override
|
||||
+ public net.minecraft.world.InteractionResult interact(net.minecraft.world.entity.player.Player player, net.minecraft.world.InteractionHand hand) {
|
||||
+ Level world = this.level();
|
||||
+
|
||||
+ if (world instanceof ServerLevel serverWorld && level().purpurConfig.shearsCanDefuseTnt) {
|
||||
+ final net.minecraft.world.item.ItemStack inHand = player.getItemInHand(hand);
|
||||
+
|
||||
+ if (!inHand.is(net.minecraft.world.item.Items.SHEARS) || !player.getBukkitEntity().hasPermission("purpur.tnt.defuse") ||
|
||||
+ serverWorld.random.nextFloat() > serverWorld.purpurConfig.shearsCanDefuseTntChance) return net.minecraft.world.InteractionResult.PASS;
|
||||
+
|
||||
+ net.minecraft.world.entity.item.ItemEntity tntItem = new net.minecraft.world.entity.item.ItemEntity(serverWorld, getX(), getY(), getZ(),
|
||||
+ new net.minecraft.world.item.ItemStack(net.minecraft.world.item.Items.TNT));
|
||||
+ tntItem.setPickUpDelay(10);
|
||||
+
|
||||
+ inHand.hurtAndBreak(1, player, LivingEntity.getSlotForHand(hand));
|
||||
+ serverWorld.addFreshEntity(tntItem, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.CUSTOM);
|
||||
+
|
||||
+ this.playSound(net.minecraft.sounds.SoundEvents.SHEEP_SHEAR);
|
||||
+
|
||||
+ this.kill(serverWorld);
|
||||
+ return net.minecraft.world.InteractionResult.SUCCESS;
|
||||
+ }
|
||||
+
|
||||
+ return super.interact(player, hand);
|
||||
+ }
|
||||
+ // Purpur end - Shears can defuse TNT
|
||||
}
|
||||
Reference in New Issue
Block a user