diff --git a/src/main/java/org/ultramine/mods/bukkit/mixin/entity/ai/MixinEntityAIEatGrass.java b/src/main/java/org/ultramine/mods/bukkit/mixin/entity/ai/MixinEntityAIEatGrass.java new file mode 100644 index 0000000..90e7c50 --- /dev/null +++ b/src/main/java/org/ultramine/mods/bukkit/mixin/entity/ai/MixinEntityAIEatGrass.java @@ -0,0 +1,49 @@ +package org.ultramine.mods.bukkit.mixin.entity.ai; + +import net.minecraft.block.Block; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.ai.EntityAIEatGrass; +import net.minecraft.init.Blocks; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; +import org.bukkit.Material; +import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; +import org.ultramine.mods.bukkit.interfaces.world.IMixinWorld; + +@Mixin(EntityAIEatGrass.class) +public class MixinEntityAIEatGrass +{ + @Shadow private EntityLiving field_151500_b; + @Shadow private World field_151501_c; + @Shadow int field_151502_a; + + @Overwrite + public void updateTask() + { + this.field_151502_a = Math.max(0, this.field_151502_a - 1); + if (this.field_151502_a == 4) + { + int i = MathHelper.floor_double(this.field_151500_b.posX); + int j = MathHelper.floor_double(this.field_151500_b.posY); + int k = MathHelper.floor_double(this.field_151500_b.posZ); + if (this.field_151501_c.getBlock(i, j, k) == Blocks.tallgrass) + { + if (!CraftEventFactory.callEntityChangeBlockEvent(this.field_151500_b, ((IMixinWorld) this.field_151500_b.worldObj).getWorld().getBlockAt(i, j, k), Material.AIR, !this.field_151501_c.getGameRules().getGameRuleBooleanValue("mobGriefing")).isCancelled()) + this.field_151501_c.func_147480_a(i, j, k, false); + this.field_151500_b.eatGrassBonus(); + } + else if (this.field_151501_c.getBlock(i, j - 1, k) == Blocks.grass) + { + if (!CraftEventFactory.callEntityChangeBlockEvent(this.field_151500_b, ((IMixinWorld) this.field_151500_b.worldObj).getWorld().getBlockAt(i, j - 1, k), Material.DIRT, !this.field_151501_c.getGameRules().getGameRuleBooleanValue("mobGriefing")).isCancelled()) + { + this.field_151501_c.playAuxSFX(2001, i, j - 1, k, Block.getIdFromBlock(Blocks.grass)); + this.field_151501_c.setBlock(i, j - 1, k, Blocks.dirt, 0, 2); + } + this.field_151500_b.eatGrassBonus(); + } + } + } +} diff --git a/src/main/java/org/ultramine/mods/bukkit/mixin/entity/boss/MixinEntityWither.java b/src/main/java/org/ultramine/mods/bukkit/mixin/entity/boss/MixinEntityWither.java index d3ec7f5..d6960ef 100644 --- a/src/main/java/org/ultramine/mods/bukkit/mixin/entity/boss/MixinEntityWither.java +++ b/src/main/java/org/ultramine/mods/bukkit/mixin/entity/boss/MixinEntityWither.java @@ -1,17 +1,166 @@ package org.ultramine.mods.bukkit.mixin.entity.boss; +import net.minecraft.block.Block; +import net.minecraft.command.IEntitySelector; +import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.monster.EntityMob; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.util.MathHelper; +import net.minecraft.world.EnumDifficulty; +import net.minecraft.world.World; +import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; import org.ultramine.mods.bukkit.interfaces.entity.IMixinEntityLivingBase; +import java.util.List; + @Mixin(net.minecraft.entity.boss.EntityWither.class) -public class MixinEntityWither +public abstract class MixinEntityWither extends EntityMob { - @Redirect(method = "updateAITasks", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/EntityLivingBase;heal(F)V")) - private void healRedir(EntityLivingBase entity, float value) + public MixinEntityWither(World p_i1738_1_) { - ((IMixinEntityLivingBase) entity).heal(value, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.WITHER_SPAWN); + super(p_i1738_1_); + } + + @Final + @Shadow private static IEntitySelector attackEntitySelector; + @Shadow private int[] field_82223_h = new int[2]; + @Shadow private int[] field_82224_i = new int[2]; + @Shadow private int field_82222_j; + @Shadow public abstract int func_82212_n(); + @Shadow public abstract void func_82215_s(int p_82215_1_); + @Shadow public abstract int getWatchedTargetId(int p_82203_1_); + @Shadow public abstract void func_82211_c(int p_82211_1_, int p_82211_2_); + @Shadow protected abstract void func_82216_a(int p_82216_1_, EntityLivingBase p_82216_2_); + @Shadow protected abstract void func_82209_a(int p_82209_1_, double p_82209_2_, double p_82209_4_, double p_82209_6_, boolean p_82209_8_); + + @Overwrite + protected void updateAITasks() + { + int i; + if (this.func_82212_n() > 0) + { + i = this.func_82212_n() - 1; + if (i <= 0) + { + this.worldObj.newExplosion(this, this.posX, this.posY + this.getEyeHeight(), this.posZ, 7.0F, false, this.worldObj.getGameRules().getGameRuleBooleanValue("mobGriefing")); + this.worldObj.playBroadcastSound(1013, (int) this.posX, (int) this.posY, (int) this.posZ, 0); + } + this.func_82215_s(i); + if (this.ticksExisted % 10 == 0) + ((IMixinEntityLivingBase) this).heal(10.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.WITHER_SPAWN); + } + else + { + super.updateAITasks(); + int i1; + int j1; + for (i = 1; i < 3; ++i) + { + if (this.ticksExisted >= this.field_82223_h[i - 1]) + { + this.field_82223_h[i - 1] = this.ticksExisted + 10 + this.rand.nextInt(10); + int k1; + if (this.worldObj.difficultySetting == EnumDifficulty.NORMAL || this.worldObj.difficultySetting == EnumDifficulty.HARD) + { + j1 = i - 1; + k1 = this.field_82224_i[i - 1]; + this.field_82224_i[j1] = this.field_82224_i[i - 1] + 1; + if (k1 > 15) + { + float f = 10.0F; + float f1 = 5.0F; + double d0 = MathHelper.getRandomDoubleInRange(this.rand, this.posX - f, this.posX + f); + double d1 = MathHelper.getRandomDoubleInRange(this.rand, this.posY - f1, this.posY + f1); + double d2 = MathHelper.getRandomDoubleInRange(this.rand, this.posZ - f, this.posZ + f); + this.func_82209_a(i + 1, d0, d1, d2, true); + this.field_82224_i[i - 1] = 0; + } + } + i1 = this.getWatchedTargetId(i); + if (i1 > 0) + { + Entity entity = this.worldObj.getEntityByID(i1); + if (entity != null && entity.isEntityAlive() && this.getDistanceSqToEntity(entity) <= 900.0D && this.canEntityBeSeen(entity)) + { + this.func_82216_a(i + 1, (EntityLivingBase) entity); + this.field_82223_h[i - 1] = this.ticksExisted + 40 + this.rand.nextInt(20); + this.field_82224_i[i - 1] = 0; + } + else + { + this.func_82211_c(i, 0); + } + } + else + { + List list = this.worldObj.selectEntitiesWithinAABB(EntityLivingBase.class, this.boundingBox.expand(20.0D, 8.0D, 20.0D), attackEntitySelector); + for (k1 = 0; k1 < 10 && !list.isEmpty(); ++k1) + { + EntityLivingBase entitylivingbase = (EntityLivingBase) list.get(this.rand.nextInt(list.size())); + if (entitylivingbase != this && entitylivingbase.isEntityAlive() && this.canEntityBeSeen(entitylivingbase)) + { + if (entitylivingbase instanceof EntityPlayer) + if (!((EntityPlayer) entitylivingbase).capabilities.disableDamage) + this.func_82211_c(i, entitylivingbase.getEntityId()); + else + this.func_82211_c(i, entitylivingbase.getEntityId()); + break; + } + list.remove(entitylivingbase); + } + } + } + } + if (this.getAttackTarget() != null) + this.func_82211_c(0, this.getAttackTarget().getEntityId()); + else + this.func_82211_c(0, 0); + if (this.field_82222_j > 0) + { + --this.field_82222_j; + if (this.field_82222_j == 0 && this.worldObj.getGameRules().getGameRuleBooleanValue("mobGriefing")) + { + i = MathHelper.floor_double(this.posY); + i1 = MathHelper.floor_double(this.posX); + j1 = MathHelper.floor_double(this.posZ); + boolean flag = false; + int l1 = -1; + while (true) + { + if (l1 > 1) + { + if (flag) + this.worldObj.playAuxSFXAtEntity(null, 1012, (int) this.posX, (int) this.posY, (int) this.posZ, 0); + break; + } + for (int i2 = -1; i2 <= 1; ++i2) + { + for (int j = 0; j <= 3; ++j) + { + int j2 = i1 + l1; + int k = i + j; + int l = j1 + i2; + Block block = this.worldObj.getBlock(j2, k, l); + if (!block.isAir(this.worldObj, j2, k, l) && block.canEntityDestroy(this.worldObj, j2, k, l, this)) + { + if (CraftEventFactory.callEntityChangeBlockEvent(this, j2, k, l, Blocks.air, 0).isCancelled()) + continue; + flag = this.worldObj.func_147480_a(j2, k, l, true) || flag; + } + } + } + ++l1; + } + } + } + if (this.ticksExisted % 20 == 0) + ((IMixinEntityLivingBase) this).heal(1.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.WITHER_SPAWN); + } } } diff --git a/src/main/java/org/ultramine/mods/bukkit/mixin/entity/item/MixinEntityBoat.java b/src/main/java/org/ultramine/mods/bukkit/mixin/entity/item/MixinEntityBoat.java new file mode 100644 index 0000000..54a0795 --- /dev/null +++ b/src/main/java/org/ultramine/mods/bukkit/mixin/entity/item/MixinEntityBoat.java @@ -0,0 +1,244 @@ +package org.ultramine.mods.bukkit.mixin.entity.item; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.item.EntityBoat; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; +import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +import java.util.List; + +@Mixin(EntityBoat.class) +public abstract class MixinEntityBoat extends Entity +{ + public MixinEntityBoat(World p_i1582_1_) + { + super(p_i1582_1_); + } + + @Shadow public abstract void setDamageTaken(float p_70266_1_); + @Shadow public abstract float getDamageTaken(); + @Shadow public abstract void setTimeSinceHit(int p_70265_1_); + @Shadow public abstract int getTimeSinceHit(); + @Shadow private boolean isBoatEmpty; + @Shadow private double speedMultiplier; + @Shadow private int boatPosRotationIncrements; + @Shadow private double boatX; + @Shadow private double boatY; + @Shadow private double boatZ; + @Shadow private double boatYaw; + @Shadow private double boatPitch; + + @Overwrite + public void onUpdate() + { + super.onUpdate(); + if (getTimeSinceHit() > 0) + this.setTimeSinceHit(this.getTimeSinceHit() - 1); + if (this.getDamageTaken() > 0.0F) + this.setDamageTaken(this.getDamageTaken() - 1.0F); + this.prevPosX = this.posX; + this.prevPosY = this.posY; + this.prevPosZ = this.posZ; + byte b0 = 5; + double d0 = 0.0D; + for (int i = 0; i < b0; ++i) + { + double d1 = this.boundingBox.minY + (this.boundingBox.maxY - this.boundingBox.minY) * i / b0 - 0.125D; + double d3 = this.boundingBox.minY + (this.boundingBox.maxY - this.boundingBox.minY) * (i + 1) / b0 - 0.125D; + AxisAlignedBB axisalignedbb = AxisAlignedBB.getBoundingBox(this.boundingBox.minX, d1, this.boundingBox.minZ, this.boundingBox.maxX, d3, this.boundingBox.maxZ); + if (this.worldObj.isAABBInMaterial(axisalignedbb, Material.water)) + d0 += 1.0D / b0; + } + double d10 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ); + double d2; + double d4; + int j; + double d11; + double d12; + if (d10 > 0.26249999999999996D) + { + d2 = Math.cos(this.rotationYaw * 3.141592653589793D / 180.0D); + d4 = Math.sin(this.rotationYaw * 3.141592653589793D / 180.0D); + + for (j = 0; j < 1.0D + d10 * 60.0D; ++j) + { + d11 = this.rand.nextFloat() * 2.0F - 1.0F; + d12 = (this.rand.nextInt(2) * 2 - 1) * 0.7D; + double d8; + double d9; + if (this.rand.nextBoolean()) + { + d8 = this.posX - d2 * d11 * 0.8D + d4 * d12; + d9 = this.posZ - d4 * d11 * 0.8D - d2 * d12; + this.worldObj.spawnParticle("splash", d8, this.posY - 0.125D, d9, this.motionX, this.motionY, this.motionZ); + } + else + { + d8 = this.posX + d2 + d4 * d11 * 0.7D; + d9 = this.posZ + d4 - d2 * d11 * 0.7D; + this.worldObj.spawnParticle("splash", d8, this.posY - 0.125D, d9, this.motionX, this.motionY, this.motionZ); + } + } + } + + if (this.worldObj.isRemote && this.isBoatEmpty) + { + if (this.boatPosRotationIncrements > 0) + { + d2 = this.posX + (this.boatX - this.posX) / this.boatPosRotationIncrements; + d4 = this.posY + (this.boatY - this.posY) / this.boatPosRotationIncrements; + d11 = this.posZ + (this.boatZ - this.posZ) / this.boatPosRotationIncrements; + d12 = MathHelper.wrapAngleTo180_double(this.boatYaw - this.rotationYaw); + this.rotationYaw = (float) (this.rotationYaw + d12 / this.boatPosRotationIncrements); + this.rotationPitch = (float) (this.rotationPitch + (this.boatPitch - this.rotationPitch) / this.boatPosRotationIncrements); + --this.boatPosRotationIncrements; + this.setPosition(d2, d4, d11); + this.setRotation(this.rotationYaw, this.rotationPitch); + } + else + { + d2 = this.posX + this.motionX; + d4 = this.posY + this.motionY; + d11 = this.posZ + this.motionZ; + this.setPosition(d2, d4, d11); + if (this.onGround) + { + this.motionX *= 0.5D; + this.motionY *= 0.5D; + this.motionZ *= 0.5D; + } + + this.motionX *= 0.9900000095367432D; + this.motionY *= 0.949999988079071D; + this.motionZ *= 0.9900000095367432D; + } + } + else + { + if (d0 < 1.0D) + { + d2 = d0 * 2.0D - 1.0D; + this.motionY += 0.03999999910593033D * d2; + } + else + { + if (this.motionY < 0.0D) + this.motionY /= 2.0D; + this.motionY += 0.007000000216066837D; + } + if (this.riddenByEntity != null && this.riddenByEntity instanceof EntityLivingBase) + { + EntityLivingBase entitylivingbase = (EntityLivingBase) this.riddenByEntity; + float f = this.riddenByEntity.rotationYaw + -entitylivingbase.moveStrafing * 90.0F; + this.motionX += -Math.sin(f * 3.1415927F / 180.0F) * this.speedMultiplier * entitylivingbase.moveForward * 0.05000000074505806D; + this.motionZ += Math.cos(f * 3.1415927F / 180.0F) * this.speedMultiplier * entitylivingbase.moveForward * 0.05000000074505806D; + } + d2 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ); + if (d2 > 0.35D) + { + d4 = 0.35D / d2; + this.motionX *= d4; + this.motionZ *= d4; + d2 = 0.35D; + } + if (d2 > d10 && this.speedMultiplier < 0.35D) + { + this.speedMultiplier += (0.35D - this.speedMultiplier) / 35.0D; + if (this.speedMultiplier > 0.35D) + this.speedMultiplier = 0.35D; + } + else + { + this.speedMultiplier -= (this.speedMultiplier - 0.07D) / 35.0D; + if (this.speedMultiplier < 0.07D) + this.speedMultiplier = 0.07D; + } + int l; + for (l = 0; l < 4; ++l) + { + int i1 = MathHelper.floor_double(this.posX + ((l % 2) - 0.5D) * 0.8D); + j = MathHelper.floor_double(this.posZ + ((l / 2) - 0.5D) * 0.8D); + for (int j1 = 0; j1 < 2; ++j1) + { + int k = MathHelper.floor_double(this.posY) + j1; + Block block = this.worldObj.getBlock(i1, k, j); + if (block == Blocks.snow_layer) + { + if (CraftEventFactory.callEntityChangeBlockEvent(this, i1, k, j, Blocks.air, 0).isCancelled()) + continue; + this.worldObj.setBlockToAir(i1, k, j); + this.isCollidedHorizontally = false; + } + else if (block == Blocks.waterlily) + { + if (CraftEventFactory.callEntityChangeBlockEvent(this, i1, k, j, Blocks.air, 0).isCancelled()) + continue; + this.worldObj.func_147480_a(i1, k, j, true); + this.isCollidedHorizontally = false; + } + } + } + if (this.onGround) + { + this.motionX *= 0.5D; + this.motionY *= 0.5D; + this.motionZ *= 0.5D; + } + this.moveEntity(this.motionX, this.motionY, this.motionZ); + if (this.isCollidedHorizontally && d10 > 0.2D) + { + if (!this.worldObj.isRemote && !this.isDead) + { + this.setDead(); + for (l = 0; l < 3; ++l) + this.func_145778_a(Item.getItemFromBlock(Blocks.planks), 1, 0.0F); + for (l = 0; l < 2; ++l) + this.func_145778_a(Items.stick, 1, 0.0F); + } + } + else + { + this.motionX *= 0.9900000095367432D; + this.motionY *= 0.949999988079071D; + this.motionZ *= 0.9900000095367432D; + } + this.rotationPitch = 0.0F; + d4 = (double) this.rotationYaw; + d11 = this.prevPosX - this.posX; + d12 = this.prevPosZ - this.posZ; + if (d11 * d11 + d12 * d12 > 0.001D) + d4 = (Math.atan2(d12, d11) * 180.0D / 3.141592653589793D); + double d7 = MathHelper.wrapAngleTo180_double(d4 - (double) this.rotationYaw); + if (d7 > 20.0D) + d7 = 20.0D; + if (d7 < -20.0D) + d7 = -20.0D; + this.rotationYaw = (float) (this.rotationYaw + d7); + this.setRotation(this.rotationYaw, this.rotationPitch); + if (!this.worldObj.isRemote) + { + List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.expand(0.20000000298023224D, 0.0D, 0.20000000298023224D)); + if (list != null && !list.isEmpty()) + for (Object aList : list) + { + Entity entity = (Entity) aList; + if (entity != this.riddenByEntity && entity.canBePushed() && entity instanceof EntityBoat) + entity.applyEntityCollision(this); + } + if (this.riddenByEntity != null && this.riddenByEntity.isDead) + this.riddenByEntity = null; + } + } + } +} diff --git a/src/main/java/org/ultramine/mods/bukkit/mixin/entity/item/MixinEntityFallingBlock.java b/src/main/java/org/ultramine/mods/bukkit/mixin/entity/item/MixinEntityFallingBlock.java new file mode 100644 index 0000000..72ec698 --- /dev/null +++ b/src/main/java/org/ultramine/mods/bukkit/mixin/entity/item/MixinEntityFallingBlock.java @@ -0,0 +1,117 @@ +package org.ultramine.mods.bukkit.mixin.entity.item; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockFalling; +import net.minecraft.block.ITileEntityProvider; +import net.minecraft.block.material.Material; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityFallingBlock; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; +import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(EntityFallingBlock.class) +public abstract class MixinEntityFallingBlock extends Entity +{ + public MixinEntityFallingBlock(World p_i1582_1_) + { + super(p_i1582_1_); + } + + @Shadow private Block field_145811_e; + @Shadow public int field_145814_a; + @Shadow public int field_145812_b; + @Shadow public boolean field_145813_c; + @Shadow private boolean field_145808_f; + @Shadow public NBTTagCompound field_145810_d; + + @Overwrite + public void onUpdate() + { + if (this.field_145811_e.getMaterial() == Material.air) + { + this.setDead(); + } + else + { + this.prevPosX = this.posX; + this.prevPosY = this.posY; + this.prevPosZ = this.posZ; + ++this.field_145812_b; + this.motionY -= 0.03999999910593033D; + this.moveEntity(this.motionX, this.motionY, this.motionZ); + this.motionX *= 0.9800000190734863D; + this.motionY *= 0.9800000190734863D; + this.motionZ *= 0.9800000190734863D; + if (!this.worldObj.isRemote) + { + int i = MathHelper.floor_double(this.posX); + int j = MathHelper.floor_double(this.posY); + int k = MathHelper.floor_double(this.posZ); + if (this.field_145812_b == 1) + { + if (this.worldObj.getBlock(i, j, k) != this.field_145811_e || this.worldObj.getBlockMetadata(i, j, k) != this.field_145814_a || CraftEventFactory.callEntityChangeBlockEvent(this, i, j, k, Blocks.air, 0).isCancelled()) + { + this.setDead(); + return; + } + this.worldObj.setBlockToAir(i, j, k); + } + if (this.onGround) + { + this.motionX *= 0.699999988079071D; + this.motionZ *= 0.699999988079071D; + this.motionY *= -0.5D; + if (this.worldObj.getBlock(i, j, k) != Blocks.piston_extension) + { + this.setDead(); + if (!this.field_145808_f && this.worldObj.canPlaceEntityOnSide(this.field_145811_e, i, j, k, true, 1, null, null) && !BlockFalling.func_149831_e(this.worldObj, i, j - 1, k)) + { + if (CraftEventFactory.callEntityChangeBlockEvent(this, i, j, k, this.field_145811_e, this.field_145814_a).isCancelled()) + return; + this.worldObj.setBlock(i, j, k, this.field_145811_e, this.field_145814_a, 3); + if (this.field_145811_e instanceof BlockFalling) + ((BlockFalling) this.field_145811_e).func_149828_a(this.worldObj, i, j, k, this.field_145814_a); + if (this.field_145810_d != null && this.field_145811_e instanceof ITileEntityProvider) + { + TileEntity tileentity = this.worldObj.getTileEntity(i, j, k); + if (tileentity != null) + { + NBTTagCompound nbttagcompound = new NBTTagCompound(); + tileentity.writeToNBT(nbttagcompound); + for (Object o : this.field_145810_d.func_150296_c()) + { + String s = (String) o; + NBTBase nbtbase = this.field_145810_d.getTag(s); + if (!s.equals("x") && !s.equals("y") && !s.equals("z")) + nbttagcompound.setTag(s, nbtbase.copy()); + } + tileentity.readFromNBT(nbttagcompound); + tileentity.markDirty(); + } + } + } + else if (this.field_145813_c && !this.field_145808_f) + { + this.entityDropItem(new ItemStack(this.field_145811_e, 1, this.field_145811_e.damageDropped(this.field_145814_a)), 0.0F); + } + } + } + else if (this.field_145812_b > 100 && !this.worldObj.isRemote && (j < 1 || j > 256) || this.field_145812_b > 600) + { + if (this.field_145813_c) + this.entityDropItem(new ItemStack(this.field_145811_e, 1, this.field_145811_e.damageDropped(this.field_145814_a)), 0.0F); + this.setDead(); + } + } + } + } +} diff --git a/src/main/java/org/ultramine/mods/bukkit/mixin/entity/monster/MixinEntityEnderman.java b/src/main/java/org/ultramine/mods/bukkit/mixin/entity/monster/MixinEntityEnderman.java new file mode 100644 index 0000000..3fce4f9 --- /dev/null +++ b/src/main/java/org/ultramine/mods/bukkit/mixin/entity/monster/MixinEntityEnderman.java @@ -0,0 +1,59 @@ +package org.ultramine.mods.bukkit.mixin.entity.monster; + +import net.minecraft.block.Block; +import net.minecraft.entity.monster.EntityEnderman; +import net.minecraft.init.Blocks; +import net.minecraft.world.World; +import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.ultramine.mods.bukkit.interfaces.world.IMixinWorld; + +@Mixin(EntityEnderman.class) +public abstract class MixinEntityEnderman +{ + private Block block; + + @Redirect(method = "onLivingUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/monster/EntityEnderman;func_146081_a(Lnet/minecraft/block/Block;)V")) + private void onLivingUpdateFunc_146081_aRedirect(EntityEnderman entityEnderman, Block argumentBlock) + { + if(this.block == null) + this.block = argumentBlock; + } + + @Redirect(method = "onLivingUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/monster/EntityEnderman;setCarryingData(I)V")) + private void onLivingUpdateSetCarryingDataRedirect(EntityEnderman entityEnderman, int p_70817_1_) + { + + } + + @Shadow public abstract int getCarryingData(); + @Shadow public abstract Block func_146080_bZ(); + @Shadow public abstract void func_146081_a(Block p_146081_1_); + @Shadow public abstract void setCarryingData(int p_70817_1_); + + @Redirect(method = "onLivingUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlock(IIILnet/minecraft/block/Block;)Z")) + private boolean onLivingUpdateSetBlockRedirect(World world, int x, int y, int z, Block block) + { + if (((IMixinWorld) world).getWorld() == null || !CraftEventFactory.callEntityChangeBlockEvent((EntityEnderman) (Object) this, ((IMixinWorld) world).getWorld().getBlockAt(x, y, z), org.bukkit.Material.AIR).isCancelled()) // Cauldron + { + this.func_146081_a(block); + this.setCarryingData(world.getBlockMetadata(x, y, z)); + world.setBlock(x, y, z, Blocks.air); + } + return false; + } + + @Redirect(method = "onLivingUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlock(IIILnet/minecraft/block/Block;II)Z")) + private boolean onLivingUpdateSetBlockRedirect(World world, int x, int y, int z, Block block, int meta, int flags) + { + if (!CraftEventFactory.callEntityChangeBlockEvent((EntityEnderman)(Object)this, x, y, z, this.func_146080_bZ(), this.getCarryingData()).isCancelled()) + { + world.setBlock(x, y, z, this.func_146080_bZ(), this.getCarryingData(), 3); + this.func_146081_a(Blocks.air); + } + return false; + } +} diff --git a/src/main/java/org/ultramine/mods/bukkit/mixin/entity/monster/MixinEntitySilverfish.java b/src/main/java/org/ultramine/mods/bukkit/mixin/entity/monster/MixinEntitySilverfish.java new file mode 100644 index 0000000..318368e --- /dev/null +++ b/src/main/java/org/ultramine/mods/bukkit/mixin/entity/monster/MixinEntitySilverfish.java @@ -0,0 +1,99 @@ +package org.ultramine.mods.bukkit.mixin.entity.monster; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockSilverfish; +import net.minecraft.entity.monster.EntityMob; +import net.minecraft.entity.monster.EntitySilverfish; +import net.minecraft.init.Blocks; +import net.minecraft.util.Facing; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(EntitySilverfish.class) +public class MixinEntitySilverfish extends EntityMob +{ + public MixinEntitySilverfish(World world) + { + super(world); + } + + @Shadow private int allySummonCooldown; + + @Overwrite + protected void updateEntityActionState() + { + super.updateEntityActionState(); + if (!this.worldObj.isRemote) + { + int i; + int j; + int k; + int i1; + if (this.allySummonCooldown > 0) + { + --this.allySummonCooldown; + if (this.allySummonCooldown == 0) + { + i = MathHelper.floor_double(this.posX); + j = MathHelper.floor_double(this.posY); + k = MathHelper.floor_double(this.posZ); + boolean flag = false; + for (int l = 0; !flag && l <= 5 && l >= -5; l = l <= 0 ? 1 - l : 0 - l) + for (i1 = 0; !flag && i1 <= 10 && i1 >= -10; i1 = i1 <= 0 ? 1 - i1 : 0 - i1) + for (int j1 = 0; !flag && j1 <= 10 && j1 >= -10; j1 = j1 <= 0 ? 1 - j1 : 0 - j1) + if (this.worldObj.getBlock(i + i1, j + l, k + j1) == Blocks.monster_egg) + { + if (CraftEventFactory.callEntityChangeBlockEvent(this, i + i1, j + l, k + j1, Blocks.air, 0).isCancelled()) + continue; + if (!this.worldObj.getGameRules().getGameRuleBooleanValue("mobGriefing")) + { + int k1 = this.worldObj.getBlockMetadata(i + i1, j + l, k + j1); + ImmutablePair immutablepair = BlockSilverfish.func_150197_b(k1); + this.worldObj.setBlock(i + i1, j + l, k + j1, (Block) immutablepair.getLeft(), (Integer) immutablepair.getRight(), 3); + } + else + { + this.worldObj.func_147480_a(i + i1, j + l, k + j1, false); + } + Blocks.monster_egg.onBlockDestroyedByPlayer(this.worldObj, i + i1, j + l, k + j1, 0); + if (this.rand.nextBoolean()) + { + flag = true; + break; + } + } + } + } + if (this.entityToAttack == null && !this.hasPath()) + { + i = MathHelper.floor_double(this.posX); + j = MathHelper.floor_double(this.posY + 0.5D); + k = MathHelper.floor_double(this.posZ); + int l1 = this.rand.nextInt(6); + Block block = this.worldObj.getBlock(i + Facing.offsetsXForSide[l1], j + Facing.offsetsYForSide[l1], k + Facing.offsetsZForSide[l1]); + i1 = this.worldObj.getBlockMetadata(i + Facing.offsetsXForSide[l1], j + Facing.offsetsYForSide[l1], k + Facing.offsetsZForSide[l1]); + if (BlockSilverfish.func_150196_a(block)) + { + if (CraftEventFactory.callEntityChangeBlockEvent(this, i + Facing.offsetsXForSide[l1], j + Facing.offsetsYForSide[l1], k + Facing.offsetsZForSide[l1], Blocks.monster_egg, Block.getIdFromBlock(BlockSilverfish.getBlockById(i1))).isCancelled()) + return; + this.worldObj.setBlock(i + Facing.offsetsXForSide[l1], j + Facing.offsetsYForSide[l1], k + Facing.offsetsZForSide[l1], Blocks.monster_egg, BlockSilverfish.func_150195_a(block, i1), 3); + this.spawnExplosionParticle(); + this.setDead(); + } + else + { + this.updateWanderPath(); + } + } + else if (this.entityToAttack != null && !this.hasPath()) + { + this.entityToAttack = null; + } + } + } +} diff --git a/src/main/resources/mixin.umbukkitimpl.json b/src/main/resources/mixin.umbukkitimpl.json index af7a338..b126d53 100644 --- a/src/main/resources/mixin.umbukkitimpl.json +++ b/src/main/resources/mixin.umbukkitimpl.json @@ -45,6 +45,8 @@ "entity.monster.MixinEntityPigZombie", "entity.monster.MixinEntityGhast", "entity.monster.MixinEntityCreeper", + "entity.monster.MixinEntityEnderman", + "entity.monster.MixinEntitySilverfish", "entity.passive.MixinEntityHorse", "entity.passive.MixinEntityPig", "entity.projectile.MixinThrowable", @@ -56,7 +58,10 @@ "entity.item.MixinEntityEnderCrystal", "entity.item.MixinEntityItemFrame", "entity.item.MixinEntityFireworkRocket", + "entity.item.MixinEntityBoat", + "entity.item.MixinEntityFallingBlock", "entity.effect.MixinEntityLightningBolt", + "entity.ai.MixinEntityAIEatGrass", "inventory.MixinContainer", "inventory.MixinInventoryLargeChest", "inventory.MixinInventoryMerchant",