Update some MekanismUtils functions to use Coord4D

This commit is contained in:
Ben Spiers 2015-07-28 04:58:04 +01:00
parent de0cdd5334
commit c9f51bd970
8 changed files with 60 additions and 102 deletions

View file

@ -10,6 +10,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
@ -76,6 +77,13 @@ public class Coord4D
dimensionId = dimension;
}
public Coord4D(MovingObjectPosition mop)
{
xCoord = mop.blockX;
yCoord = mop.blockY;
zCoord = mop.blockZ;
}
/**
* Gets the metadata of the block representing this Coord4D.
* @param world - world this Coord4D is in

View file

@ -180,7 +180,7 @@ public class EntityFlame extends Entity implements IEntityAdditionalSpawnData
else {
Block block = worldObj.getBlock(mop.blockX, mop.blockY, mop.blockZ);
int meta = worldObj.getBlockMetadata(mop.blockX, mop.blockY, mop.blockZ);
boolean fluid = MekanismUtils.isFluid(worldObj, mop.blockX, mop.blockY, mop.blockZ) || MekanismUtils.isDeadFluid(worldObj, mop.blockX, mop.blockY, mop.blockZ);
boolean fluid = MekanismUtils.isFluid(worldObj, new Coord4D(mop)) || MekanismUtils.isDeadFluid(worldObj, new Coord4D(mop));
Coord4D sideCoord = new Coord4D(mop.blockX, mop.blockY, mop.blockZ, worldObj.provider.dimensionId).getFromSide(ForgeDirection.getOrientation(mop.sideHit));

View file

@ -538,7 +538,7 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, ISpec
return itemstack;
}
FluidStack fluid = MekanismUtils.getFluid(world, coord.xCoord, coord.yCoord, coord.zCoord, false);
FluidStack fluid = MekanismUtils.getFluid(world, coord, false);
if(fluid != null && (getFluidStack(itemstack) == null || getFluidStack(itemstack).isFluidEqual(fluid)))
{

View file

@ -1098,7 +1098,7 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I
continue;
}
MekanismUtils.makeAdvancedBoundingBlock(worldObj, x, y, z, Coord4D.get(this));
MekanismUtils.makeAdvancedBoundingBlock(worldObj, new Coord4D(x, y, z), Coord4D.get(this));
worldObj.func_147453_f(x, y, z, getBlockType());
}
}

View file

@ -166,15 +166,15 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I
{
Coord4D wrapper = Coord4D.get(this).getFromSide(orientation);
if(MekanismUtils.isFluid(worldObj, wrapper.xCoord, wrapper.yCoord, wrapper.zCoord))
if(MekanismUtils.isFluid(worldObj, wrapper))
{
if(fluidTank.getFluid() == null || MekanismUtils.getFluid(worldObj, wrapper.xCoord, wrapper.yCoord, wrapper.zCoord, hasFilter()).isFluidEqual(fluidTank.getFluid()))
if(fluidTank.getFluid() == null || MekanismUtils.getFluid(worldObj, wrapper, hasFilter()).isFluidEqual(fluidTank.getFluid()))
{
if(take)
{
setEnergy(getEnergy() - usage.electricPumpUsage);
recurringNodes.add(wrapper.clone());
fluidTank.fill(MekanismUtils.getFluid(worldObj, wrapper.xCoord, wrapper.yCoord, wrapper.zCoord, hasFilter()), true);
fluidTank.fill(MekanismUtils.getFluid(worldObj, wrapper, hasFilter()), true);
worldObj.setBlockToAir(wrapper.xCoord, wrapper.yCoord, wrapper.zCoord);
}
@ -187,14 +187,14 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I
//and then add the adjacent block to the recurring list
for(Coord4D wrapper : tempPumpList)
{
if(MekanismUtils.isFluid(worldObj, wrapper.xCoord, wrapper.yCoord, wrapper.zCoord))
if(MekanismUtils.isFluid(worldObj, wrapper))
{
if(fluidTank.getFluid() == null || MekanismUtils.getFluid(worldObj, wrapper.xCoord, wrapper.yCoord, wrapper.zCoord, hasFilter()).isFluidEqual(fluidTank.getFluid()))
if(fluidTank.getFluid() == null || MekanismUtils.getFluid(worldObj, wrapper, hasFilter()).isFluidEqual(fluidTank.getFluid()))
{
if(take)
{
setEnergy(getEnergy() - usage.electricPumpUsage);
fluidTank.fill(MekanismUtils.getFluid(worldObj, wrapper.xCoord, wrapper.yCoord, wrapper.zCoord, hasFilter()), true);
fluidTank.fill(MekanismUtils.getFluid(worldObj, wrapper, hasFilter()), true);
worldObj.setBlockToAir(wrapper.xCoord, wrapper.yCoord, wrapper.zCoord);
}
@ -209,15 +209,15 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I
if(Coord4D.get(this).distanceTo(side) <= 80)
{
if(MekanismUtils.isFluid(worldObj, side.xCoord, side.yCoord, side.zCoord))
if(MekanismUtils.isFluid(worldObj, side))
{
if(fluidTank.getFluid() == null || MekanismUtils.getFluid(worldObj, side.xCoord, side.yCoord, side.zCoord, hasFilter()).isFluidEqual(fluidTank.getFluid()))
if(fluidTank.getFluid() == null || MekanismUtils.getFluid(worldObj, side, hasFilter()).isFluidEqual(fluidTank.getFluid()))
{
if(take)
{
setEnergy(getEnergy() - usage.electricPumpUsage);
recurringNodes.add(side);
fluidTank.fill(MekanismUtils.getFluid(worldObj, side.xCoord, side.yCoord, side.zCoord, hasFilter()), true);
fluidTank.fill(MekanismUtils.getFluid(worldObj, side, hasFilter()), true);
worldObj.setBlockToAir(side.xCoord, side.yCoord, side.zCoord);
}

View file

@ -227,12 +227,12 @@ public class TileEntityFluidicPlenisher extends TileEntityElectricBlock implemen
return false;
}
if(coord.isAirBlock(worldObj) || MekanismUtils.isDeadFluid(worldObj, coord.xCoord, coord.yCoord, coord.zCoord))
if(coord.isAirBlock(worldObj) || MekanismUtils.isDeadFluid(worldObj, coord))
{
return true;
}
if(MekanismUtils.isFluid(worldObj, coord.xCoord, coord.yCoord, coord.zCoord))
if(MekanismUtils.isFluid(worldObj, coord))
{
return isPathfinding;
}

View file

@ -548,7 +548,6 @@ public final class MekanismUtils
}
TileEntity tile = (TileEntity)config;
Coord4D coord = Coord4D.get(tile).getFromSide(ForgeDirection.getOrientation(MekanismUtils.getBaseOrientation(side, config.getOrientation())));
tile.markDirty();
}
@ -574,8 +573,6 @@ public final class MekanismUtils
}
TileEntity tile = (TileEntity)config;
Coord4D coord = Coord4D.get(tile).getFromSide(ForgeDirection.getOrientation(MekanismUtils.getBaseOrientation(side, config.getOrientation())));
tile.markDirty();
}
@ -749,97 +746,88 @@ public final class MekanismUtils
/**
* Places a fake bounding block at the defined location.
* @param world - world to place block in
* @param x - x coordinate
* @param y - y coordinate
* @param z - z coordinate
* @param boundingLocation - coordinates of bounding block
* @param orig - original block
*/
public static void makeBoundingBlock(World world, int x, int y, int z, Coord4D orig)
public static void makeBoundingBlock(World world, Coord4D boundingLocation, Coord4D orig)
{
world.setBlock(x, y, z, MekanismBlocks.BoundingBlock);
world.setBlock(boundingLocation.xCoord, boundingLocation.yCoord, boundingLocation.zCoord, MekanismBlocks.BoundingBlock);
if(!world.isRemote)
{
((TileEntityBoundingBlock)world.getTileEntity(x, y, z)).setMainLocation(orig.xCoord, orig.yCoord, orig.zCoord);
((TileEntityBoundingBlock)boundingLocation.getTileEntity(world)).setMainLocation(orig.xCoord, orig.yCoord, orig.zCoord);
}
}
/**
* Places a fake advanced bounding block at the defined location.
* @param world - world to place block in
* @param x - x coordinate
* @param y - y coordinate
* @param z - z coordinate
* @param boundingLocation - coordinates of bounding block
* @param orig - original block
*/
public static void makeAdvancedBoundingBlock(World world, int x, int y, int z, Coord4D orig)
public static void makeAdvancedBoundingBlock(World world, Coord4D boundingLocation, Coord4D orig)
{
world.setBlock(x, y, z, MekanismBlocks.BoundingBlock, 1, 0);
world.setBlock(boundingLocation.xCoord, boundingLocation.yCoord, boundingLocation.zCoord, MekanismBlocks.BoundingBlock, 1, 0);
if(!world.isRemote)
{
((TileEntityAdvancedBoundingBlock)world.getTileEntity(x, y, z)).setMainLocation(orig.xCoord, orig.yCoord, orig.zCoord);
((TileEntityAdvancedBoundingBlock)boundingLocation.getTileEntity(world)).setMainLocation(orig.xCoord, orig.yCoord, orig.zCoord);
}
}
/**
* Updates a block's light value and marks it for a render update.
* @param world - world the block is in
* @param x - x coord
* @param y - y coord
* @param z - z coord
* @param x - x coordinate
* @param y - y coordinate
* @param z - z coordinate
*/
public static void updateBlock(World world, int x, int y, int z)
{
if(!(world.getTileEntity(x, y, z) instanceof IActiveState) || ((IActiveState)world.getTileEntity(x, y, z)).renderUpdate())
Coord4D pos = new Coord4D(x, y, z);
if(!(pos.getTileEntity(world) instanceof IActiveState) || ((IActiveState)pos.getTileEntity(world)).renderUpdate())
{
world.func_147479_m(x, y, z);
world.func_147479_m(pos.xCoord, pos.yCoord, pos.zCoord);
}
if(!(world.getTileEntity(x, y, z) instanceof IActiveState) || ((IActiveState)world.getTileEntity(x, y, z)).lightUpdate() && client.machineEffects)
if(!(pos.getTileEntity(world) instanceof IActiveState) || ((IActiveState)pos.getTileEntity(world)).lightUpdate() && client.machineEffects)
{
updateAllLightTypes(world, x, y, z);
updateAllLightTypes(world, pos);
}
}
/**
* Updates all light types at the given coordinates.
* @param world - the world to perform the lighting update in
* @param x - x coordinate of the block to update
* @param y - y coordinate of the block to update
* @param z - z coordinate of the block to update
* @param pos - coordinates of the block to update
*/
public static void updateAllLightTypes(World world, int x, int y, int z)
public static void updateAllLightTypes(World world, Coord4D pos)
{
world.updateLightByType(EnumSkyBlock.Block, x, y, z);
world.updateLightByType(EnumSkyBlock.Sky, x, y, z);
world.updateLightByType(EnumSkyBlock.Block, pos.xCoord, pos.yCoord, pos.zCoord);
world.updateLightByType(EnumSkyBlock.Sky, pos.xCoord, pos.yCoord, pos.zCoord);
}
/**
* Whether or not a certain block is considered a fluid.
* @param world - world the block is in
* @param x - x coordinate
* @param y - y coordinate
* @param z - z coordinate
* @param pos - coordinates
* @return if the block is a fluid
*/
public static boolean isFluid(World world, int x, int y, int z)
public static boolean isFluid(World world, Coord4D pos)
{
return getFluid(world, x, y, z, false) != null;
return getFluid(world, pos, false) != null;
}
/**
* Gets a fluid from a certain location.
* @param world - world the block is in
* @param x - x coordinate
* @param y - y coordinate
* @param z - z coordinate
* @param pos - location of the block
* @return the fluid at the certain location, null if it doesn't exist
*/
public static FluidStack getFluid(World world, int x, int y, int z, boolean filter)
public static FluidStack getFluid(World world, Coord4D pos, boolean filter)
{
Block block = world.getBlock(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
Block block = pos.getBlock(world);
int meta = pos.getMetadata(world);
if(block == null)
{
@ -866,63 +854,23 @@ public final class MekanismUtils
if(meta == 0)
{
return fluid.drain(world, x, y, z, false);
return fluid.drain(world, pos.xCoord, pos.yCoord, pos.zCoord, false);
}
}
return null;
}
/**
* Gets the fluid ID at a certain location, 0 if there isn't one
* @param world - world the block is in
* @param x - x coordinate
* @param y - y coordinate
* @param z - z coordinate
* @return fluid ID
*/
public static int getFluidId(World world, int x, int y, int z)
{
Block block = world.getBlock(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
if(block == null)
{
return 0;
}
if(block == Blocks.water || block == Blocks.flowing_water)
{
return FluidRegistry.WATER.getID();
}
else if(block == Blocks.lava || block == Blocks.flowing_lava)
{
return FluidRegistry.LAVA.getID();
}
for(Fluid fluid : FluidRegistry.getRegisteredFluids().values())
{
if(fluid.getBlock() == block)
{
return fluid.getID();
}
}
return 0;
}
/**
* Whether or not a block is a dead fluid.
* @param world - world the block is in
* @param x - x coordinate
* @param y - y coordinate
* @param z - z coordinate
* @param pos - coordinates
* @return if the block is a dead fluid
*/
public static boolean isDeadFluid(World world, int x, int y, int z)
public static boolean isDeadFluid(World world, Coord4D pos)
{
Block block = world.getBlock(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
Block block = pos.getBlock(world);
int meta = pos.getMetadata(world);
if(block == null || meta == 0)
{

View file

@ -8,6 +8,7 @@ import mekanism.common.base.IBoundingBlock;
import mekanism.common.util.ChargeUtils;
import mekanism.common.util.MekanismUtils;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityWindTurbine extends TileEntityGenerator implements IBoundingBlock
{
@ -107,10 +108,11 @@ public class TileEntityWindTurbine extends TileEntityGenerator implements IBound
@Override
public void onPlace()
{
MekanismUtils.makeBoundingBlock(worldObj, xCoord, yCoord+1, zCoord, Coord4D.get(this));
MekanismUtils.makeBoundingBlock(worldObj, xCoord, yCoord+2, zCoord, Coord4D.get(this));
MekanismUtils.makeBoundingBlock(worldObj, xCoord, yCoord+3, zCoord, Coord4D.get(this));
MekanismUtils.makeBoundingBlock(worldObj, xCoord, yCoord+4, zCoord, Coord4D.get(this));
Coord4D pos = Coord4D.get(this);
MekanismUtils.makeBoundingBlock(worldObj, pos.getFromSide(ForgeDirection.UP, 1), pos);
MekanismUtils.makeBoundingBlock(worldObj, pos.getFromSide(ForgeDirection.UP, 2), pos);
MekanismUtils.makeBoundingBlock(worldObj, pos.getFromSide(ForgeDirection.UP, 3), pos);
MekanismUtils.makeBoundingBlock(worldObj, pos.getFromSide(ForgeDirection.UP, 4), pos);
}
@Override