diff --git a/src/main/java/org/ultramine/mods/bukkit/EventImplProgress.java b/src/main/java/org/ultramine/mods/bukkit/EventImplProgress.java index 504e1b5..53ed7a6 100644 --- a/src/main/java/org/ultramine/mods/bukkit/EventImplProgress.java +++ b/src/main/java/org/ultramine/mods/bukkit/EventImplProgress.java @@ -92,7 +92,7 @@ reg(true, org.bukkit.event.entity.EntityDamageEvent.class); reg(true, org.bukkit.event.entity.EntityDeathEvent.class); reg(true, org.bukkit.event.entity.EntityExplodeEvent.class); - reg(false, org.bukkit.event.entity.EntityInteractEvent.class); + reg(true, org.bukkit.event.entity.EntityInteractEvent.class); reg(false, org.bukkit.event.entity.EntityPortalEnterEvent.class); reg(false, org.bukkit.event.entity.EntityPortalEvent.class); reg(false, org.bukkit.event.entity.EntityPortalExitEvent.class); diff --git a/src/main/java/org/ultramine/mods/bukkit/mixin/block/MixinBlockButton.java b/src/main/java/org/ultramine/mods/bukkit/mixin/block/MixinBlockButton.java new file mode 100644 index 0000000..591713b --- /dev/null +++ b/src/main/java/org/ultramine/mods/bukkit/mixin/block/MixinBlockButton.java @@ -0,0 +1,44 @@ +package org.ultramine.mods.bukkit.mixin.block; + +import net.minecraft.block.BlockButton; +import net.minecraft.world.World; +import org.bukkit.Bukkit; +import org.bukkit.block.Block; +import org.bukkit.event.entity.EntityInteractEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.At.Shift; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; +import org.ultramine.mods.bukkit.interfaces.entity.IMixinEntity; +import org.ultramine.mods.bukkit.interfaces.world.IMixinWorld; + +import java.util.List; + +@Mixin(BlockButton.class) +public class MixinBlockButton +{ + @Inject(method = "func_150046_n", cancellable = true, at = @At(value = "INVOKE", target = "Ljava/util/List;isEmpty()Z", ordinal = 0, shift = Shift.BY, by = 11), locals = LocalCapture.CAPTURE_FAILEXCEPTION) + private void func_150046_nInject(World world, int x, int y, int z, CallbackInfo ci, int l, int i1, boolean flag, List list, boolean flag1) + { + if (flag != flag1 && flag1) + { + Block block = ((IMixinWorld) world).getWorld().getBlockAt(x, y, z); + boolean allowed = false; + for (Object entityObject : list) + if (entityObject != null) + { + EntityInteractEvent event = new EntityInteractEvent(((IMixinEntity) entityObject).getBukkitEntity(), block); + Bukkit.getPluginManager().callEvent(event); + if (!event.isCancelled()) + { + allowed = true; + break; + } + } + if (!allowed) + ci.cancel(); + } + } +} diff --git a/src/main/java/org/ultramine/mods/bukkit/mixin/block/MixinBlockFarmland.java b/src/main/java/org/ultramine/mods/bukkit/mixin/block/MixinBlockFarmland.java index b765d39..21b03ab 100644 --- a/src/main/java/org/ultramine/mods/bukkit/mixin/block/MixinBlockFarmland.java +++ b/src/main/java/org/ultramine/mods/bukkit/mixin/block/MixinBlockFarmland.java @@ -1,14 +1,20 @@ package org.ultramine.mods.bukkit.mixin.block; import net.minecraft.block.BlockFarmland; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.world.World; +import org.bukkit.Bukkit; import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.event.Cancellable; +import org.bukkit.event.entity.EntityInteractEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At.Shift; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.ultramine.mods.bukkit.interfaces.entity.IMixinEntity; import org.ultramine.mods.bukkit.interfaces.world.IMixinWorld; import java.util.Random; @@ -26,4 +32,24 @@ if (CraftEventFactory.callBlockFadeEvent(block, Blocks.dirt).isCancelled()) ci.cancel(); } + + @Inject(method = "onFallenUpon", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlock(IIILnet/minecraft/block/Block;)Z")) + private void onFallenUponInject(World world, int x, int y, int z, Entity entity, float p_149746_6_, CallbackInfo ci) + { + if (entity != null) + { + Cancellable cancellable = null; + if (entity instanceof EntityPlayer) + { + cancellable = CraftEventFactory.callPlayerInteractEvent((EntityPlayer) entity, org.bukkit.event.block.Action.PHYSICAL, x, y, z, -1, null); + } + else if (((IMixinWorld) world).getWorld() != null) + { + cancellable = new EntityInteractEvent(((IMixinEntity) entity).getBukkitEntity(), ((IMixinWorld) world).getWorld().getBlockAt(x, y, z)); + Bukkit.getPluginManager().callEvent((EntityInteractEvent) cancellable); + } + if (cancellable != null && cancellable.isCancelled()) + ci.cancel(); + } + } } diff --git a/src/main/java/org/ultramine/mods/bukkit/mixin/block/MixinBlockPressurePlate.java b/src/main/java/org/ultramine/mods/bukkit/mixin/block/MixinBlockPressurePlate.java new file mode 100644 index 0000000..4e1de3e --- /dev/null +++ b/src/main/java/org/ultramine/mods/bukkit/mixin/block/MixinBlockPressurePlate.java @@ -0,0 +1,67 @@ +package org.ultramine.mods.bukkit.mixin.block; + +import net.minecraft.block.BlockBasePressurePlate; +import net.minecraft.block.BlockPressurePlate; +import net.minecraft.block.material.Material; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.event.Cancellable; +import org.bukkit.event.block.Action; +import org.bukkit.event.entity.EntityInteractEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; +import org.ultramine.mods.bukkit.interfaces.entity.IMixinEntity; +import org.ultramine.mods.bukkit.interfaces.world.IMixinWorld; + +import java.util.List; + +@Mixin(BlockPressurePlate.class) +public abstract class MixinBlockPressurePlate extends BlockBasePressurePlate +{ + @Shadow private BlockPressurePlate.Sensitivity field_150069_a; + + protected MixinBlockPressurePlate(String p_i45387_1_, Material p_i45387_2_) + { + super(p_i45387_1_, p_i45387_2_); + } + + @Overwrite + protected int func_150065_e(World world, int x, int y, int z) + { + List entityList = null; + if (this.field_150069_a == BlockPressurePlate.Sensitivity.everything) + entityList = world.getEntitiesWithinAABBExcludingEntity(null, this.func_150061_a(x, y, z)); + if (this.field_150069_a == BlockPressurePlate.Sensitivity.mobs) + entityList = world.getEntitiesWithinAABB(EntityLivingBase.class, this.func_150061_a(x, y, z)); + if (this.field_150069_a == BlockPressurePlate.Sensitivity.players) + entityList = world.getEntitiesWithinAABB(EntityPlayer.class, this.func_150061_a(x, y, z)); + if (entityList != null && !entityList.isEmpty()) + for (Object entityObject : entityList) + { + Entity entity = (Entity) entityObject; + if (this.func_150060_c(world.getBlockMetadata(x, y, z)) == 0) + { + Cancellable cancellable; + if (entity instanceof EntityPlayer) + { + cancellable = CraftEventFactory.callPlayerInteractEvent((EntityPlayer) entity, Action.PHYSICAL, x, y, z, -1, null); + } + else + { + cancellable = new EntityInteractEvent(((IMixinEntity) entity).getBukkitEntity(), ((IMixinWorld) world).getWorld().getBlockAt(x, y, z)); + Bukkit.getPluginManager().callEvent((EntityInteractEvent) cancellable); + } + if (cancellable.isCancelled()) + continue; + } + if (!entity.doesEntityNotTriggerPressurePlate()) + return 15; + } + return 0; + } +} diff --git a/src/main/java/org/ultramine/mods/bukkit/mixin/block/MixinBlockPressurePlateWeighted.java b/src/main/java/org/ultramine/mods/bukkit/mixin/block/MixinBlockPressurePlateWeighted.java new file mode 100644 index 0000000..3c8deca --- /dev/null +++ b/src/main/java/org/ultramine/mods/bukkit/mixin/block/MixinBlockPressurePlateWeighted.java @@ -0,0 +1,59 @@ +package org.ultramine.mods.bukkit.mixin.block; + +import net.minecraft.block.BlockBasePressurePlate; +import net.minecraft.block.BlockPressurePlateWeighted; +import net.minecraft.block.material.Material; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.event.Cancellable; +import org.bukkit.event.block.Action; +import org.bukkit.event.entity.EntityInteractEvent; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; +import org.ultramine.mods.bukkit.interfaces.entity.IMixinEntity; +import org.ultramine.mods.bukkit.interfaces.world.IMixinWorld; + +@Mixin(BlockPressurePlateWeighted.class) +public abstract class MixinBlockPressurePlateWeighted extends BlockBasePressurePlate +{ + @Final + @Shadow private int field_150068_a; + + protected MixinBlockPressurePlateWeighted(String p_i45387_1_, Material p_i45387_2_) + { + super(p_i45387_1_, p_i45387_2_); + } + + @Overwrite + protected int func_150065_e(World world, int x, int y, int z) + { + int l = 0; + for (Object entityObject : world.getEntitiesWithinAABB(Entity.class, this.func_150061_a(x, y, z))) + { + Entity entity = (Entity) entityObject; + Cancellable cancellable; + if (entity instanceof EntityPlayer) + { + cancellable = CraftEventFactory.callPlayerInteractEvent((EntityPlayer) entity, Action.PHYSICAL, x, y, z, -1, null); + } + else + { + cancellable = new EntityInteractEvent(((IMixinEntity) entity).getBukkitEntity(), ((IMixinWorld) world).getWorld().getBlockAt(x, y, z)); + Bukkit.getPluginManager().callEvent((EntityInteractEvent) cancellable); + } + if (!cancellable.isCancelled()) + l++; + } + l = Math.min(l, this.field_150068_a); + if (l <= 0) + return 0; + float f = Math.min(this.field_150068_a, l) / this.field_150068_a; + return MathHelper.ceiling_float_int(f * 15.0F); + } +} diff --git a/src/main/java/org/ultramine/mods/bukkit/mixin/block/MixinBlockRedstoneOre.java b/src/main/java/org/ultramine/mods/bukkit/mixin/block/MixinBlockRedstoneOre.java new file mode 100644 index 0000000..380c143 --- /dev/null +++ b/src/main/java/org/ultramine/mods/bukkit/mixin/block/MixinBlockRedstoneOre.java @@ -0,0 +1,53 @@ +package org.ultramine.mods.bukkit.mixin.block; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockRedstoneOre; +import net.minecraft.block.material.Material; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.event.block.Action; +import org.bukkit.event.entity.EntityInteractEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; +import org.ultramine.mods.bukkit.interfaces.entity.IMixinEntity; +import org.ultramine.mods.bukkit.interfaces.world.IMixinWorld; + +@Mixin(BlockRedstoneOre.class) +public abstract class MixinBlockRedstoneOre extends Block +{ + @Shadow protected abstract void func_150185_e(net.minecraft.world.World p_150185_1_, int p_150185_2_, int p_150185_3_, int p_150185_4_); + + protected MixinBlockRedstoneOre(Material p_i45394_1_) + { + super(p_i45394_1_); + } + + @Overwrite + public void onEntityWalking(World world, int x, int y, int z, Entity entity) + { + if (entity instanceof EntityPlayer) + { + PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent((EntityPlayer) entity, Action.PHYSICAL, x, y, z, -1, null); + if (!event.isCancelled()) + { + this.func_150185_e(world, x, y, z); + super.onEntityWalking(world, x, y, z, entity); + } + } + else + { + EntityInteractEvent event = new EntityInteractEvent(((IMixinEntity) entity).getBukkitEntity(), ((IMixinWorld) world).getWorld().getBlockAt(x, y, z)); + Bukkit.getPluginManager().callEvent(event); + if (!event.isCancelled()) + { + this.func_150185_e(world, x, y, z); + super.onEntityWalking(world, x, y, z, entity); + } + } + } +} diff --git a/src/main/java/org/ultramine/mods/bukkit/mixin/block/MixinBlockTripWire.java b/src/main/java/org/ultramine/mods/bukkit/mixin/block/MixinBlockTripWire.java new file mode 100644 index 0000000..013ad5e --- /dev/null +++ b/src/main/java/org/ultramine/mods/bukkit/mixin/block/MixinBlockTripWire.java @@ -0,0 +1,53 @@ +package org.ultramine.mods.bukkit.mixin.block; + +import net.minecraft.block.BlockTripWire; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; +import org.bukkit.Bukkit; +import org.bukkit.event.Cancellable; +import org.bukkit.event.entity.EntityInteractEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.At.Shift; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; +import org.ultramine.mods.bukkit.interfaces.entity.IMixinEntity; +import org.ultramine.mods.bukkit.interfaces.world.IMixinWorld; + +import java.util.List; + +@Mixin(BlockTripWire.class) +public abstract class MixinBlockTripWire +{ + @Inject(method = "func_150140_e", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;doesEntityNotTriggerPressurePlate()Z", shift = Shift.BY, by = 15), locals = LocalCapture.CAPTURE_FAILEXCEPTION) + private void func_150140_e(World world, int x, int y, int z, CallbackInfo ci, int l, boolean flag, boolean flag1, List list) + { + if (flag != flag1 && flag1 && ((world.getBlockMetadata(x, y, z) & 4) == 4 || world.getBlockMetadata(x, y, z) == 0)) + { + boolean allowed = false; + for (Object entityObject : list) + if (entityObject != null && entityObject instanceof Entity) + { + Cancellable cancellable; + if (entityObject instanceof EntityPlayer) + { + cancellable = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEvent((EntityPlayer) entityObject, org.bukkit.event.block.Action.PHYSICAL, x, y, z, -1, null); + } + else + { + cancellable = new EntityInteractEvent(((IMixinEntity) entityObject).getBukkitEntity(), ((IMixinWorld) world).getWorld().getBlockAt(x, y, z)); + Bukkit.getPluginManager().callEvent((EntityInteractEvent) cancellable); + } + if (!cancellable.isCancelled()) + { + allowed = true; + break; + } + } + if (!allowed) + ci.cancel(); + } + } +} diff --git a/src/main/resources/mixin.umbukkitimpl.json b/src/main/resources/mixin.umbukkitimpl.json index ae37565..6be48b2 100644 --- a/src/main/resources/mixin.umbukkitimpl.json +++ b/src/main/resources/mixin.umbukkitimpl.json @@ -31,6 +31,11 @@ "block.MixinBlockMushroom", "block.MixinBlockVine", "block.MixinBlockDropper", + "block.MixinBlockButton", + "block.MixinBlockPressurePlate", + "block.MixinBlockPressurePlateWeighted", + "block.MixinBlockRedstoneOre", + "block.MixinBlockTripWire", "entity.MixinEntity", "entity.MixinEntityLiving", "entity.MixinEntityLivingBase",