Add hook for EntityWither trying to destroy a block.

This commit is contained in:
LexManos 2013-07-03 20:29:41 -07:00
parent 83504eb2e1
commit d4ba95f606
3 changed files with 43 additions and 16 deletions

View File

@ -1,6 +1,6 @@
--- ../src_base/minecraft/net/minecraft/block/Block.java
+++ ../src_work/minecraft/net/minecraft/block/Block.java
@@ -1,15 +1,20 @@
@@ -1,15 +1,22 @@
package net.minecraft.block;
-import cpw.mods.fml.relauncher.Side;
@ -20,10 +20,12 @@
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
+import net.minecraft.entity.EnumCreatureType;
+import net.minecraft.entity.boss.EntityDragon;
+import net.minecraft.entity.boss.EntityWither;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.entity.player.EntityPlayer;
@@ -26,8 +31,10 @@
@@ -26,8 +33,10 @@
import net.minecraft.item.ItemSnow;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
@ -34,7 +36,7 @@
import net.minecraft.util.Icon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.StatCollector;
@@ -35,9 +42,19 @@
@@ -35,9 +44,19 @@
import net.minecraft.world.Explosion;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
@ -54,7 +56,7 @@
/**
* used as foreach item, if item.tab = current tab, display it on the screen
*/
@@ -460,9 +477,10 @@
@@ -460,9 +479,10 @@
return this.needsRandomTick;
}
@ -66,7 +68,7 @@
}
/**
@@ -485,7 +503,7 @@
@@ -485,7 +505,7 @@
*/
public float getBlockBrightness(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
{
@ -75,7 +77,7 @@
}
@SideOnly(Side.CLIENT)
@@ -495,7 +513,7 @@
@@ -495,7 +515,7 @@
*/
public int getMixedBrightnessForBlock(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
{
@ -84,7 +86,7 @@
}
@SideOnly(Side.CLIENT)
@@ -645,7 +663,13 @@
@@ -645,7 +665,13 @@
/**
* ejects contained items into the world, and notifies neighbours of an update, as appropriate
*/
@ -99,7 +101,7 @@
/**
* Returns the quantity of items to drop on block destruction.
@@ -670,7 +694,7 @@
@@ -670,7 +696,7 @@
public float getPlayerRelativeBlockHardness(EntityPlayer par1EntityPlayer, World par2World, int par3, int par4, int par5)
{
float f = this.getBlockHardness(par2World, par3, par4, par5);
@ -108,7 +110,7 @@
}
/**
@@ -688,18 +712,13 @@
@@ -688,18 +714,13 @@
{
if (!par1World.isRemote)
{
@ -131,7 +133,7 @@
}
}
}
@@ -932,7 +951,8 @@
@@ -932,7 +953,8 @@
public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4)
{
int l = par1World.getBlockId(par2, par3, par4);
@ -141,7 +143,7 @@
}
/**
@@ -1092,7 +1112,7 @@
@@ -1092,7 +1114,7 @@
par2EntityPlayer.addStat(StatList.mineBlockStatArray[this.blockID], 1);
par2EntityPlayer.addExhaustion(0.025F);
@ -150,7 +152,7 @@
{
ItemStack itemstack = this.createStackedBlock(par6);
@@ -1108,12 +1128,13 @@
@@ -1108,12 +1130,13 @@
}
}
@ -165,7 +167,7 @@
}
/**
@@ -1453,4 +1474,939 @@
@@ -1453,4 +1476,952 @@
canBlockGrass[0] = true;
StatList.initBreakableStats();
}
@ -1006,8 +1008,7 @@
+ }
+
+ /**
+ * Determines if this block is destroyed when a ender dragon tries to fly through it.
+ * The block will be set to 0, nothing will drop.
+ * Determines if this block is can be destroyed by the specified entities normal behavior.
+ *
+ * @param world The current world
+ * @param x X Position
@ -1015,6 +1016,20 @@
+ * @param z Z position
+ * @return True to allow the ender dragon to destroy this block
+ */
+ public boolean canEntityDestroy(World world, int x, int y, int z, Entity entity)
+ {
+ if (entity instanceof EntityWither)
+ {
+ return blockID != Block.bedrock.blockID && blockID != Block.endPortal.blockID && blockID != Block.endPortalFrame.blockID;
+ }
+ else if (entity instanceof EntityDragon)
+ {
+ return canDragonDestroy(world, x, y, z);
+ }
+
+ return true;
+ }
+ @Deprecated
+ public boolean canDragonDestroy(World world, int x, int y, int z)
+ {
+ return blockID != obsidian.blockID && blockID != whiteStone.blockID && blockID != bedrock.blockID;

View File

@ -11,7 +11,7 @@
+ if (block != null)
{
- if (j2 != Block.obsidian.blockID && j2 != Block.whiteStone.blockID && j2 != Block.bedrock.blockID && this.worldObj.getGameRules().getGameRuleBooleanValue("mobGriefing"))
+ if (block.canDragonDestroy(worldObj, k1, l1, i2) && this.worldObj.getGameRules().getGameRuleBooleanValue("mobGriefing"))
+ if (block.canEntityDestroy(worldObj, k1, l1, i2, this) && this.worldObj.getGameRules().getGameRuleBooleanValue("mobGriefing"))
{
flag1 = this.worldObj.setBlockToAir(k1, l1, i2) || flag1;
}

View File

@ -0,0 +1,12 @@
--- ../src_base/minecraft/net/minecraft/entity/boss/EntityWither.java
+++ ../src_work/minecraft/net/minecraft/entity/boss/EntityWither.java
@@ -355,7 +355,8 @@
int l2 = j1 + l1;
int i3 = this.worldObj.getBlockId(j2, k2, l2);
- if (i3 > 0 && i3 != Block.bedrock.blockID && i3 != Block.endPortal.blockID && i3 != Block.endPortalFrame.blockID)
+ Block block = Block.blocksList[i3];
+ if (block != null && block.canEntityDestroy(worldObj, j2, k2, l2, this))
{
flag = this.worldObj.destroyBlock(j2, k2, l2, true) || flag;
}