Preventing conflicting wheels to be placed together
This commit is contained in:
parent
9cce3f302e
commit
c9bd412bb8
2 changed files with 40 additions and 1 deletions
|
@ -8,6 +8,7 @@ import net.minecraft.util.DamageSource;
|
|||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import resonantinduction.core.base.BlockRotatableBase;
|
||||
import universalelectricity.api.vector.VectorWorld;
|
||||
|
||||
/**
|
||||
* A block used to build machines.
|
||||
|
@ -23,6 +24,43 @@ public class BlockGrinderWheel extends BlockRotatableBase implements ITileEntity
|
|||
this.setBlockBounds(0.05f, 0.05f, 0.05f, 0.95f, 0.95f, 0.95f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockAdded(World world, int x, int y, int z)
|
||||
{
|
||||
this.checkConflicts(world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborBlockChange(World world, int x, int y, int z, int par5)
|
||||
{
|
||||
this.checkConflicts(world, x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for any conflicting directions with other grinders.
|
||||
*/
|
||||
private void checkConflicts(World world, int x, int y, int z)
|
||||
{
|
||||
ForgeDirection facing = this.getDirection(world, x, y, z);
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
if (dir == facing || dir == facing.getOpposite())
|
||||
{
|
||||
VectorWorld checkPos = (VectorWorld) new VectorWorld(world, x, y, z).modifyPositionFromSide(dir);
|
||||
TileEntity tileEntity = checkPos.getTileEntity();
|
||||
|
||||
if (tileEntity instanceof TileGrinderWheel)
|
||||
{
|
||||
if (this.getDirection(world, checkPos.intX(), checkPos.intY(), checkPos.intZ()) == facing)
|
||||
{
|
||||
this.dropBlockAsItem(world, x, y, z, 0, 0);
|
||||
world.setBlockToAir(x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity)
|
||||
{
|
||||
|
|
|
@ -10,6 +10,7 @@ import resonantinduction.api.MachineRecipes.RecipeType;
|
|||
import resonantinduction.api.RecipeUtils.ItemStackResource;
|
||||
import resonantinduction.api.RecipeUtils.Resource;
|
||||
import universalelectricity.api.energy.EnergyStorageHandler;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
import calclavia.lib.prefab.tile.TileElectrical;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
@ -56,7 +57,7 @@ public class TileGrinderWheel extends TileElectrical
|
|||
|
||||
if (grindingItem != null)
|
||||
{
|
||||
if (getTimer().containsKey(grindingItem) && !grindingItem.isDead)
|
||||
if (getTimer().containsKey(grindingItem) && !grindingItem.isDead && new Vector3(this).add(0.5).distance(new Vector3(grindingItem)) < 1)
|
||||
{
|
||||
int timeLeft = getTimer().get(grindingItem) - 1;
|
||||
getTimer().put(grindingItem, timeLeft);
|
||||
|
|
Loading…
Reference in a new issue