Skip to content

Commit

Permalink
Add an AOE-Tool implementation that correctly calls everything vanill…
Browse files Browse the repository at this point in the history
…a style, yay.
  • Loading branch information
bonii-xx committed Sep 17, 2014
1 parent b74776d commit 0e76fa9
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 200 deletions.
5 changes: 5 additions & 0 deletions resources/META-INF/TConstruct_at.cfg
Expand Up @@ -31,4 +31,9 @@ public net.minecraft.client.renderer.ThreadDownloadImageData field_110560_d #fie
public net.minecraft.world.gen.structure.StructureVillagePieces$Village #cant make village houses w/o this
public net.minecraft.client.renderer.Tessellator field_78415_z
public net.minecraft.client.renderer.entity.RenderPlayer field_77109_a #modelBipedMain
# PlayerControllerMP and ItemInWorldManager for blockbreaking
public net.minecraft.client.multiplayer.PlayerControllerMP func_85182_a(III)Z #sameToolAndBlock
public net.minecraft.server.management.ItemInWorldManager field_73086_f
public net.minecraft.server.management.ItemInWorldManager field_73087_g
public net.minecraft.server.management.ItemInWorldManager field_73099_h
# needs to have a space at the end of every line or SS will derp
202 changes: 2 additions & 200 deletions src/main/java/tconstruct/items/tools/Hammer.java
Expand Up @@ -21,11 +21,11 @@
import tconstruct.library.tools.*;
import tconstruct.tools.TinkerTools;

public class Hammer extends HarvestTool
public class Hammer extends AOEHarvestTool
{
public Hammer()
{
super(2);
super(2, 1, 0);
this.setUnlocalizedName("InfiTool.Hammer");
}

Expand Down Expand Up @@ -225,206 +225,8 @@ public void getSubItems (Item id, CreativeTabs tab, List list)
list.add(tool);
}

//@Override
public boolean onBlockDestroyed2(ItemStack itemstack, World world, Block block, int x, int y, int z, EntityLivingBase player) {
int sideHit = Minecraft.getMinecraft().objectMouseOver.sideHit;

// we successfully destroyed a block. time to do AOE!
int xRange = 1;
int yRange = 1;
int zRange = 1;
switch (sideHit)
{
case 0:
case 1:
yRange = 0;
break;
case 2:
case 3:
zRange = 0;
break;
case 4:
case 5:
xRange = 0;
break;
}

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++) {
// don't break the originally already broken block, duh
if(xPos == x && yPos == y && zPos == z)
continue;
breakExtraBlock(world, xPos, yPos, zPos, sideHit, (EntityPlayer)player); // no player needed because it's local
}

return super.onBlockDestroyed(itemstack, world, block, x,y,z, player);
}


boolean antiRecurse;

@Override
public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPlayer player) {
// the code below initiates block breaks, which again call this function. But we don't want to do the aoe-break-stuff again. This is to prevent recursive, infinite-range aoe blockbreaking.
if(!antiRecurse) {
antiRecurse = true;
int sideHit = Minecraft.getMinecraft().objectMouseOver.sideHit;

// we successfully destroyed a block. time to do AOE!
int xRange = 1;
int yRange = 1;
int zRange = 1;
switch (sideHit) {
case 0:
case 1:
yRange = 0;
break;
case 2:
case 3:
zRange = 0;
break;
case 4:
case 5:
xRange = 0;
break;
}

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++) {
// don't break the originally already broken block, duh
if (xPos == x && yPos == y && zPos == z)
continue;
breakExtraBlock(player.worldObj, xPos, yPos, zPos, sideHit, player);
}
antiRecurse = false;
}
return super.onBlockStartBreak(stack, x, y, z, player);
}

/*
@Override
public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPlayer player)
{
if (!stack.hasTagCompound())
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++)
{
if (materials[iter] == block.getMaterial())
{
validStart = true;
break;
}
}
if (block == Blocks.monster_egg)
validStart = true;
MovingObjectPosition mop = AbilityHelper.raytraceFromEntity(world, player, false, 4.5D);
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;
}
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++)
{
if (!(tags.getBoolean("Broken")))
{
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.getBlockHardness(world, xPos, yPos, zPos);
//Choose blocks that aren't too much harder than the first block. Stone: 2.0, Ores: 3.0
if (hlvl <= toolLevel && localHardness - 1.5 <= blockHardness)
{
boolean cancelHarvest = false;
for (ActiveToolMod mod : TConstructRegistry.activeModifiers)
{
if (mod.beforeBlockBreak(this, stack, xPos, yPos, zPos, player))
cancelHarvest = true;
}
// send blockbreak event
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(x, y, z, world, localBlock, localMeta, player);
event.setCanceled(cancelHarvest);
MinecraftForge.EVENT_BUS.post(event);
cancelHarvest = event.isCanceled();
if (!cancelHarvest)
{
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)
{
mineBlock(world, xPos, yPos, zPos, localMeta, player, localBlock);
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 (!world.isRemote)
world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block) + (meta << 12));
return true;
}
*/
@Override
public float breakSpeedModifier ()
{
Expand Down
84 changes: 84 additions & 0 deletions src/main/java/tconstruct/library/tools/AOEHarvestTool.java
@@ -0,0 +1,84 @@
package tconstruct.library.tools;

import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.PlayerControllerMP;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.server.management.ItemInWorldManager;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public abstract class AOEHarvestTool extends HarvestTool {
public int breakRadius;
public int breakDepth;

public AOEHarvestTool(int baseDamage, int breakRadius, int breakDepth) {
super(baseDamage);

this.breakRadius = breakRadius;
this.breakDepth = breakDepth;
}

boolean antiRecurse;

@Override
public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPlayer player) {
boolean originalBlock = true;
// check if we're breaking the block we hit, or if this call belongs to one of the surrounding blocks broken by the AOE
if(player.worldObj.isRemote)
{
originalBlock = Minecraft.getMinecraft().playerController.sameToolAndBlock(x,y,z);
}
// same check serverside
else {
ItemInWorldManager iiiwm = ((EntityPlayerMP) player).theItemInWorldManager;

if(x != iiiwm.partiallyDestroyedBlockX || y != iiiwm.partiallyDestroyedBlockY || z != iiiwm.partiallyDestroyedBlockZ)
originalBlock = false;
}

// the code below initiates block breaks, which again call this function. But we don't want to do the aoe-break-stuff again. This is to prevent recursive, infinite-range aoe blockbreaking.
if(originalBlock) {
antiRecurse = true;
int sideHit = Minecraft.getMinecraft().objectMouseOver.sideHit;

// we successfully destroyed a block. time to do AOE!
int xRange = breakRadius;
int yRange = breakRadius;
int zRange = breakDepth;
switch (sideHit) {
case 0:
case 1:
yRange = breakDepth;
zRange = breakRadius;
break;
case 2:
case 3:
xRange = breakRadius;
zRange = breakDepth;
break;
case 4:
case 5:
xRange = breakDepth;
zRange = breakRadius;
break;
}

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++) {
// don't break the originally already broken block, duh
if (xPos == x && yPos == y && zPos == z)
continue;
breakExtraBlock(player.worldObj, xPos, yPos, zPos, sideHit, player);
}

antiRecurse = false;
}
return super.onBlockStartBreak(stack, x, y, z, player);
}

}

0 comments on commit 0e76fa9

Please sign in to comment.