craftbukkit/nms-patches/net/minecraft/world/level/block/BlockRedstoneOre.patch

104 lines
5 KiB
Diff
Raw Normal View History

2021-03-16 09:00:00 +11:00
--- a/net/minecraft/world/level/block/BlockRedstoneOre.java
+++ b/net/minecraft/world/level/block/BlockRedstoneOre.java
@@ -21,6 +21,11 @@
import net.minecraft.world.level.block.state.properties.BlockStateBoolean;
import net.minecraft.world.phys.MovingObjectPositionBlock;
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.EntityInteractEvent;
+// CraftBukkit end
+
public class BlockRedstoneOre extends Block {
2021-06-11 15:00:00 +10:00
public static final BlockStateBoolean LIT = BlockRedstoneTorch.LIT;
2022-06-08 02:00:00 +10:00
@@ -32,14 +37,27 @@
2019-04-23 12:00:00 +10:00
@Override
2018-07-15 10:00:00 +10:00
public void attack(IBlockData iblockdata, World world, BlockPosition blockposition, EntityHuman entityhuman) {
- interact(iblockdata, world, blockposition);
+ interact(iblockdata, world, blockposition, entityhuman); // CraftBukkit - add entityhuman
super.attack(iblockdata, world, blockposition, entityhuman);
}
2019-04-23 12:00:00 +10:00
@Override
2021-06-11 15:00:00 +10:00
public void stepOn(World world, BlockPosition blockposition, IBlockData iblockdata, Entity entity) {
2022-06-08 02:00:00 +10:00
if (!entity.isSteppingCarefully()) {
- interact(iblockdata, world, blockposition);
+ // CraftBukkit start
+ if (entity instanceof EntityHuman) {
+ org.bukkit.event.player.PlayerInteractEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEvent((EntityHuman) entity, org.bukkit.event.block.Action.PHYSICAL, blockposition, null, null, null);
+ if (!event.isCancelled()) {
+ interact(world.getBlockState(blockposition), world, blockposition, entity); // add entity
+ }
+ } else {
+ EntityInteractEvent event = new EntityInteractEvent(entity.getBukkitEntity(), world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()));
+ world.getCraftServer().getPluginManager().callEvent(event);
+ if (!event.isCancelled()) {
+ interact(world.getBlockState(blockposition), world, blockposition, entity); // add entity
+ }
+ }
2022-06-08 02:00:00 +10:00
+ // CraftBukkit end
}
2022-06-08 02:00:00 +10:00
super.stepOn(world, blockposition, iblockdata, entity);
@@ -50,7 +68,7 @@
2020-06-25 10:00:00 +10:00
if (world.isClientSide) {
2021-11-22 09:00:00 +11:00
spawnParticles(world, blockposition);
2019-12-11 09:00:00 +11:00
} else {
- interact(iblockdata, world, blockposition);
+ interact(iblockdata, world, blockposition, entityhuman); // CraftBukkit - add entityhuman
}
2020-06-25 10:00:00 +10:00
2021-11-22 09:00:00 +11:00
ItemStack itemstack = entityhuman.getItemInHand(enumhand);
2022-06-08 02:00:00 +10:00
@@ -58,9 +76,14 @@
2021-11-22 09:00:00 +11:00
return itemstack.getItem() instanceof ItemBlock && (new BlockActionContext(entityhuman, enumhand, itemstack, movingobjectpositionblock)).canPlace() ? EnumInteractionResult.PASS : EnumInteractionResult.SUCCESS;
}
2018-07-15 10:00:00 +10:00
- private static void interact(IBlockData iblockdata, World world, BlockPosition blockposition) {
+ private static void interact(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) { // CraftBukkit - add Entity
2021-11-22 09:00:00 +11:00
spawnParticles(world, blockposition);
if (!(Boolean) iblockdata.getValue(BlockRedstoneOre.LIT)) {
+ // CraftBukkit start
2023-06-24 17:15:05 +10:00
+ if (!CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, iblockdata.setValue(BlockRedstoneOre.LIT, true))) {
+ return;
+ }
+ // CraftBukkit end
2021-11-22 09:00:00 +11:00
world.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockRedstoneOre.LIT, true), 3);
}
2022-06-08 02:00:00 +10:00
@@ -74,6 +97,11 @@
2019-04-23 12:00:00 +10:00
@Override
2022-06-08 02:00:00 +10:00
public void randomTick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) {
2021-11-22 09:00:00 +11:00
if ((Boolean) iblockdata.getValue(BlockRedstoneOre.LIT)) {
+ // CraftBukkit start
2021-11-22 09:00:00 +11:00
+ if (CraftEventFactory.callBlockFadeEvent(worldserver, blockposition, iblockdata.setValue(BlockRedstoneOre.LIT, false)).isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
2021-11-22 09:00:00 +11:00
worldserver.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockRedstoneOre.LIT, false), 3);
}
2022-06-08 02:00:00 +10:00
@@ -82,12 +110,20 @@
2019-04-23 12:00:00 +10:00
@Override
2022-06-08 02:00:00 +10:00
public void spawnAfterBreak(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, ItemStack itemstack, boolean flag) {
super.spawnAfterBreak(iblockdata, worldserver, blockposition, itemstack, flag);
2021-11-22 09:00:00 +11:00
+ // CraftBukkit start - Delegated to getExpDrop
2019-12-11 09:00:00 +11:00
+ }
2021-11-22 09:00:00 +11:00
+
+ @Override
2022-06-08 02:00:00 +10:00
+ public int getExpDrop(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, ItemStack itemstack, boolean flag) {
if (flag && EnchantmentManager.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, itemstack) == 0) {
2021-11-22 09:00:00 +11:00
int i = 1 + worldserver.random.nextInt(5);
- this.popExperience(worldserver, blockposition, i);
+ // this.popExperience(worldserver, blockposition, i);
2019-04-23 12:00:00 +10:00
+ return i;
2021-11-22 09:00:00 +11:00
}
+ return 0;
+ // CraftBukkit end
2019-12-11 09:00:00 +11:00
}
2021-06-11 15:00:00 +10:00
@Override