Skip to content

Commit

Permalink
Fix some block breaking problems.
Browse files Browse the repository at this point in the history
- Bibliocraft locks are respected.
- Fixes Thaumcraft node drops.
- Fixes strange auto-smelt drops sometimes.
- Probably fixes sync issues somewhere.
  • Loading branch information
blue42u committed Jun 14, 2014
1 parent 01ac924 commit b16b79a
Show file tree
Hide file tree
Showing 11 changed files with 214 additions and 666 deletions.
1 change: 0 additions & 1 deletion src/main/java/tconstruct/TConstruct.java
Expand Up @@ -105,7 +105,6 @@ public TConstruct()
}

EnvironmentChecks.verifyEnvironmentSanity();
MinecraftForge.EVENT_BUS.register(events = new TEventHandler());
PluginController.registerModules();
}

Expand Down
59 changes: 15 additions & 44 deletions src/main/java/tconstruct/items/tools/Battleaxe.java
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.EnumAction;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -247,56 +248,26 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl
if (!stack.hasTagCompound())
return false;

World world = player.worldObj;
final Block wood = world.getBlock(x, y, z);
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
final int meta = world.getBlockMetadata(x, y, z);
for (int yPos = y + 1; yPos < y + 9; yPos++)
if (player instanceof EntityPlayerMP)
{
Block block = world.getBlock(x, yPos, z);
if (!(tags.getBoolean("Broken")) && block != null && block.getMaterial() == Material.wood)
EntityPlayerMP mplayer = (EntityPlayerMP)player;
World world = player.worldObj;
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
if (!tags.hasKey("AOEBreaking") || !tags.getBoolean("AOEBreaking"))
{
Block localblock = world.getBlock(x, yPos, z);
int localMeta = world.getBlockMetadata(x, yPos, z);
int hlvl = block.getHarvestLevel(meta);

if (hlvl <= tags.getInteger("HarvestLevel"))
tags.setBoolean("AOEBreaking", true);
for (int yPos = y + 1; yPos < y + 9; yPos++)
{
boolean cancelHarvest = false;
for (ActiveToolMod mod : TConstructRegistry.activeModifiers)
{
if (mod.beforeBlockBreak(this, stack, x, yPos, z, player))
cancelHarvest = true;
}

if (!cancelHarvest)
{
if (block != null && block.getMaterial() == Material.wood)
{
localMeta = world.getBlockMetadata(x, yPos, z);
if (!player.capabilities.isCreativeMode)
{
if (block.removedByPlayer(world, player, x, yPos, z))
{
block.onBlockDestroyedByPlayer(world, x, yPos, z, localMeta);
}
block.harvestBlock(world, player, x, yPos, z, localMeta);
block.onBlockHarvested(world, x, yPos, z, localMeta, player);
onBlockDestroyed(stack, world, block, x, yPos, z, player);
}
else
{
WorldHelper.setBlockToAir(world, x, yPos, z);
}
}
}
Block block = world.getBlock(x, yPos, z);
if (block != null && block.getMaterial() == Material.wood
&& block.getPlayerRelativeBlockHardness(mplayer, world, x, yPos, z) > 0)
mplayer.theItemInWorldManager.tryHarvestBlock(x, yPos, z);
else
break;
}
tags.setBoolean("AOEBreaking", false);
}
else
break;
}
if (!world.isRemote)
world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(wood) + (meta << 12));
return super.onBlockStartBreak(stack, x, y, z, player);
}
}
122 changes: 35 additions & 87 deletions src/main/java/tconstruct/items/tools/Excavator.java
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
Expand Down Expand Up @@ -141,107 +142,54 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl
return false;

World world = player.worldObj;
final int meta = world.getBlockMetadata(x, y, z);
Block block = world.getBlock(x, y, z);
if (!stack.hasTagCompound())
return false;

if (block == null)
return super.onBlockStartBreak(stack, x, y, z, player);

float blockHardness = block.getBlockHardness(world, x, y, z);

boolean validStart = false;
for (int iter = 0; iter < materials.length; iter++)
MovingObjectPosition mop = AbilityHelper.raytraceFromEntity(world, player, true, 5.0D);
if (mop != null && player instanceof EntityPlayerMP)
{
if (materials[iter] == block.getMaterial())
EntityPlayerMP mplayer = (EntityPlayerMP) player;
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
if (!tags.hasKey("AOEBreaking") || !tags.getBoolean("AOEBreaking"))
{
validStart = true;
break;
}
}
tags.setBoolean("AOEBreaking", true);

MovingObjectPosition mop = AbilityHelper.raytraceFromEntity(world, player, true, 5.0D);
if (mop == null || !validStart)
return super.onBlockStartBreak(stack, x, y, z, player);
int xRange = 1;
int yRange = 1;
int zRange = 1;
switch (mop.sideHit)
{
case 0:
case 1:
yRange = 0;
break;
case 2:
case 3:
zRange = 0;
break;
case 4:
case 5:
xRange = 0;
break;
}

int xRange = 1;
int yRange = 1;
int zRange = 1;
switch (mop.sideHit)
{
case 0:
case 1:
yRange = 0;
break;
case 2:
case 3:
zRange = 0;
break;
case 4:
case 5:
xRange = 0;
break;
}
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
for (int xPos = x - xRange; xPos <= x + xRange; xPos++)
{
for (int yPos = y - yRange; yPos <= y + yRange; yPos++)
{
for (int zPos = z - zRange; zPos <= z + zRange; zPos++)
for (int xPos = x - xRange; xPos <= x + xRange; xPos++)
{
if (!(tags.getBoolean("Broken")))
for (int yPos = y - yRange; yPos <= y + yRange; yPos++)
{
Block localblock = world.getBlock(xPos, yPos, zPos);
block = localblock;
int localMeta = world.getBlockMetadata(xPos, yPos, zPos);
int hlvl = block.getHarvestLevel(meta);
float localHardness = block == null ? Float.MAX_VALUE : block.getBlockHardness(world, xPos, yPos, zPos);

if (hlvl <= tags.getInteger("HarvestLevel") && localHardness - 1.5 <= blockHardness)
for (int zPos = z - zRange; zPos <= z + zRange; zPos++)
{
boolean cancelHarvest = false;
for (ActiveToolMod mod : TConstructRegistry.activeModifiers)
{
if (mod.beforeBlockBreak(this, stack, xPos, yPos, zPos, player))
cancelHarvest = true;
}

if (!cancelHarvest)
Block block = world.getBlock(xPos, yPos, zPos);
for (Material mat : this.materials)
{
if (block != null && !(localHardness < 0))
{
for (int iter = 0; iter < materials.length; iter++)
{
if (materials[iter] == block.getMaterial())
{
if (!player.capabilities.isCreativeMode)
{
if (block.removedByPlayer(world, player, xPos, yPos, zPos))
{
block.onBlockDestroyedByPlayer(world, xPos, yPos, zPos, localMeta);
}
block.harvestBlock(world, player, xPos, yPos, zPos, localMeta);
block.onBlockHarvested(world, xPos, yPos, zPos, localMeta, player);
if (blockHardness > 0f)
onBlockDestroyed(stack, world, localblock, xPos, yPos, zPos, player);
}
else
{
WorldHelper.setBlockToAir(world, xPos, yPos, zPos);
}
}
}
}
if (block != null && mat == block.getMaterial()
&& block.getPlayerRelativeBlockHardness(mplayer, world, x, yPos, z) > 0)
mplayer.theItemInWorldManager.tryHarvestBlock(xPos, yPos, zPos);
}
}
}
}
tags.setBoolean("AOEBreaking", false);
}
}
if (!world.isRemote)
world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block) + (meta << 12));
return true;
return super.onBlockStartBreak(stack, x, y, z, player);
}

@Override
Expand Down
130 changes: 35 additions & 95 deletions src/main/java/tconstruct/items/tools/Hammer.java
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -235,115 +236,54 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl
return false;

World world = player.worldObj;
final Block block = world.getBlock(x, y, z);
final int meta = world.getBlockMetadata(x, y, z);
if (!stack.hasTagCompound())
return false;

if (block == null)
return super.onBlockStartBreak(stack, x, y, z, player);

float blockHardness = block.getBlockHardness(world, x, y, z);

boolean validStart = false;
for (int iter = 0; iter < materials.length; iter++)
MovingObjectPosition mop = AbilityHelper.raytraceFromEntity(world, player, true, 4.5D);
if (mop != null && player instanceof EntityPlayerMP)
{
if (materials[iter] == block.getMaterial())
EntityPlayerMP mplayer = (EntityPlayerMP) player;
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
if (!tags.hasKey("AOEBreaking") || !tags.getBoolean("AOEBreaking"))
{
validStart = true;
break;
}
}

if (block == Blocks.monster_egg)
validStart = true;

MovingObjectPosition mop = AbilityHelper.raytraceFromEntity(world, player, true, 4.5D);
if (mop == null || !validStart)
return super.onBlockStartBreak(stack, x, y, z, player);
tags.setBoolean("AOEBreaking", true);

int xRange = 1;
int yRange = 1;
int zRange = 1;
switch (mop.sideHit)
{
case 0:
case 1:
yRange = 0;
break;
case 2:
case 3:
zRange = 0;
break;
case 4:
case 5:
xRange = 0;
break;
}
int xRange = 1;
int yRange = 1;
int zRange = 1;
switch (mop.sideHit)
{
case 0:
case 1:
yRange = 0;
break;
case 2:
case 3:
zRange = 0;
break;
case 4:
case 5:
xRange = 0;
break;
}

NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
int toolLevel = tags.getInteger("HarvestLevel");
for (int xPos = x - xRange; xPos <= x + xRange; xPos++)
{
for (int yPos = y - yRange; yPos <= y + yRange; yPos++)
{
for (int zPos = z - zRange; zPos <= z + zRange; zPos++)
for (int xPos = x - xRange; xPos <= x + xRange; xPos++)
{
if (!(tags.getBoolean("Broken")))
for (int yPos = y - yRange; yPos <= y + yRange; yPos++)
{
Block localBlock = world.getBlock(xPos, yPos, zPos);
int localMeta = world.getBlockMetadata(xPos, yPos, zPos);
int hlvl = -1;
if (localBlock.getHarvestTool(localMeta) != null && localBlock.getHarvestTool(localMeta).equals(this.getHarvestType()))
hlvl = localBlock.getHarvestLevel(localMeta);
float localHardness = localBlock == null ? Float.MAX_VALUE : localBlock.getBlockHardness(world, xPos, yPos, zPos);

if (hlvl <= toolLevel && localHardness - 1.5 <= blockHardness)
for (int zPos = z - zRange; zPos <= z + zRange; zPos++)
{
boolean cancelHarvest = false;
for (ActiveToolMod mod : TConstructRegistry.activeModifiers)
{
if (mod.beforeBlockBreak(this, stack, xPos, yPos, zPos, player))
cancelHarvest = true;
}

if (!cancelHarvest)
Block block = world.getBlock(xPos, yPos, zPos);
for (Material mat : this.materials)
{
if (localBlock != null && !(localHardness < 0))
{
for (int iter = 0; iter < materials.length; iter++)
{
if (materials[iter] == localBlock.getMaterial() || localBlock == Blocks.monster_egg)
{
if (!player.capabilities.isCreativeMode)
{
if (localBlock.removedByPlayer(world, player, xPos, yPos, zPos))
{
localBlock.onBlockDestroyedByPlayer(world, xPos, yPos, zPos, localMeta);
}
localBlock.harvestBlock(world, player, xPos, yPos, zPos, localMeta);
localBlock.onBlockHarvested(world, xPos, yPos, zPos, localMeta, player);
if (blockHardness > 0f)
onBlockDestroyed(stack, world, localBlock, xPos, yPos, zPos, player);
world.func_147479_m(x, y, z);
}
else
{
WorldHelper.setBlockToAir(world, xPos, yPos, zPos);
world.func_147479_m(x, y, z);
}
}
}
}
if (block != null && mat == block.getMaterial()
&& block.getPlayerRelativeBlockHardness(mplayer, world, x, yPos, z) > 0)
mplayer.theItemInWorldManager.tryHarvestBlock(xPos, yPos, zPos);
}
}
}
}
tags.setBoolean("AOEBreaking", false);
}
}
if (!world.isRemote)
world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block) + (meta << 12));
return true;
return super.onBlockStartBreak(stack, x, y, z, player);
}

@Override
Expand Down

0 comments on commit b16b79a

Please sign in to comment.