Fixed filter not updating itself
This commit is contained in:
parent
913490587c
commit
9a9c6d7ab1
3 changed files with 90 additions and 73 deletions
|
@ -33,6 +33,7 @@ import resonantinduction.mechanical.logistic.belt.TileManipulator;
|
|||
import resonantinduction.mechanical.logistic.belt.TileRejector;
|
||||
import resonantinduction.mechanical.network.PacketNetwork;
|
||||
import resonantinduction.mechanical.process.BlockFilter;
|
||||
import resonantinduction.mechanical.process.TileFilter;
|
||||
import resonantinduction.mechanical.process.grinder.BlockGrindingWheel;
|
||||
import resonantinduction.mechanical.process.grinder.TileGrinderWheel;
|
||||
import resonantinduction.mechanical.process.purifier.BlockMixer;
|
||||
|
@ -138,7 +139,7 @@ public class Mechanical
|
|||
// Machines
|
||||
blockGrinderWheel = contentRegistry.createTile(BlockGrindingWheel.class, TileGrinderWheel.class);
|
||||
blockPurifier = contentRegistry.createTile(BlockMixer.class, TileMixer.class);
|
||||
blockFilter = contentRegistry.createBlock(BlockFilter.class);
|
||||
blockFilter = contentRegistry.createTile(BlockFilter.class, TileFilter.class);
|
||||
OreDictionary.registerOre("gear", itemGear);
|
||||
|
||||
proxy.preInit();
|
||||
|
|
|
@ -7,6 +7,7 @@ import net.minecraft.block.Block;
|
|||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
@ -38,79 +39,9 @@ public class BlockFilter extends BlockTile
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onBlockAdded(World world, int x, int y, int z)
|
||||
public TileEntity createNewTileEntity(World var1)
|
||||
{
|
||||
world.scheduleBlockUpdate(x, y, z, blockID, 20);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborBlockChange(World world, int x, int y, int z, int neighborID)
|
||||
{
|
||||
world.scheduleBlockUpdate(x, y, z, blockID, 20);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTick(World world, int x, int y, int z, Random random)
|
||||
{
|
||||
Vector3 position = new Vector3(x, y, z);
|
||||
Vector3 checkAbove = position.clone().translate(ForgeDirection.UP);
|
||||
Vector3 checkBelow = position.clone().translate(ForgeDirection.DOWN);
|
||||
|
||||
Block bAbove = Block.blocksList[checkAbove.getBlockID(world)];
|
||||
Block bBelow = Block.blocksList[checkAbove.getBlockID(world)];
|
||||
|
||||
world.scheduleBlockUpdate(x, y, z, blockID, 20);
|
||||
|
||||
if (bAbove instanceof BlockFluidMixture && (world.isAirBlock(checkBelow.intX(), checkBelow.intY(), checkBelow.intZ()) || checkBelow.getTileEntity(world) instanceof IFluidHandler))
|
||||
{
|
||||
world.spawnParticle("dripWater", x + 0.5, y, z + 0.5, 0, 0, 0);
|
||||
|
||||
if (checkBelow.getTileEntity(world) instanceof IFluidHandler)
|
||||
{
|
||||
IFluidHandler handler = ((IFluidHandler) checkBelow.getTileEntity(world));
|
||||
|
||||
if (handler.fill(ForgeDirection.UP, new FluidStack(FluidRegistry.WATER, FluidContainerRegistry.BUCKET_VOLUME), false) <= 0)
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Leak the fluid down.
|
||||
*/
|
||||
BlockFluidMixture fluidBlock = (BlockFluidMixture) bAbove;
|
||||
int amount = fluidBlock.getQuantaValue(world, checkAbove.intX(), checkAbove.intY(), checkAbove.intZ());
|
||||
int leakAmount = 2;
|
||||
|
||||
/**
|
||||
* Drop item from fluid.
|
||||
*/
|
||||
for (RecipeResource resoure : MachineRecipes.INSTANCE.getOutput(RecipeType.MIXER, "dust" + LanguageUtility.capitalizeFirst(ResourceGenerator.mixtureToMaterial(fluidBlock.getFluid().getName()))))
|
||||
{
|
||||
InventoryUtility.dropItemStack(world, checkAbove.clone().add(0.5), resoure.getItemStack().copy());
|
||||
}
|
||||
|
||||
// TODO: Check if this is correct?
|
||||
int remaining = amount - leakAmount;
|
||||
|
||||
/**
|
||||
* Remove liquid from top.
|
||||
*/
|
||||
fluidBlock.setQuanta(world, checkAbove.intX(), checkAbove.intY(), checkAbove.intZ(), remaining);
|
||||
world.scheduleBlockUpdate(x, y, z, blockID, 20);
|
||||
|
||||
/**
|
||||
* Add liquid to bottom.
|
||||
*/
|
||||
if (checkBelow.getTileEntity(world) instanceof IFluidHandler)
|
||||
{
|
||||
IFluidHandler handler = ((IFluidHandler) checkBelow.getTileEntity(world));
|
||||
handler.fill(ForgeDirection.UP, new FluidStack(FluidRegistry.WATER, FluidContainerRegistry.BUCKET_VOLUME), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
checkBelow.setBlock(world, Block.waterMoving.blockID);
|
||||
}
|
||||
}
|
||||
|
||||
return new TileFilter();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
package resonantinduction.mechanical.process;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
import resonantinduction.api.recipe.MachineRecipes;
|
||||
import resonantinduction.api.recipe.RecipeResource;
|
||||
import resonantinduction.api.recipe.MachineRecipes.RecipeType;
|
||||
import resonantinduction.core.resource.ResourceGenerator;
|
||||
import resonantinduction.core.resource.fluid.BlockFluidMixture;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
import calclavia.lib.prefab.tile.TileExternalInventory;
|
||||
import calclavia.lib.utility.LanguageUtility;
|
||||
import calclavia.lib.utility.inventory.InventoryUtility;
|
||||
|
||||
public class TileFilter extends TileExternalInventory
|
||||
{
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
super.updateEntity();
|
||||
|
||||
if (ticks % 60 == 0)
|
||||
{
|
||||
Vector3 position = new Vector3(this);
|
||||
Vector3 checkAbove = position.clone().translate(ForgeDirection.UP);
|
||||
Vector3 checkBelow = position.clone().translate(ForgeDirection.DOWN);
|
||||
|
||||
Block bAbove = Block.blocksList[checkAbove.getBlockID(worldObj)];
|
||||
Block bBelow = Block.blocksList[checkAbove.getBlockID(worldObj)];
|
||||
|
||||
if (bAbove instanceof BlockFluidMixture && (worldObj.isAirBlock(checkBelow.intX(), checkBelow.intY(), checkBelow.intZ()) || checkBelow.getTileEntity(worldObj) instanceof IFluidHandler))
|
||||
{
|
||||
worldObj.spawnParticle("dripWater", xCoord + 0.5, yCoord, zCoord + 0.5, 0, 0, 0);
|
||||
|
||||
if (checkBelow.getTileEntity(worldObj) instanceof IFluidHandler)
|
||||
{
|
||||
IFluidHandler handler = ((IFluidHandler) checkBelow.getTileEntity(worldObj));
|
||||
|
||||
if (handler.fill(ForgeDirection.UP, new FluidStack(FluidRegistry.WATER, FluidContainerRegistry.BUCKET_VOLUME), false) <= 0)
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Leak the fluid down.
|
||||
*/
|
||||
BlockFluidMixture fluidBlock = (BlockFluidMixture) bAbove;
|
||||
int amount = fluidBlock.getQuantaValue(worldObj, checkAbove.intX(), checkAbove.intY(), checkAbove.intZ());
|
||||
int leakAmount = 2;
|
||||
|
||||
/**
|
||||
* Drop item from fluid.
|
||||
*/
|
||||
for (RecipeResource resoure : MachineRecipes.INSTANCE.getOutput(RecipeType.MIXER, "dust" + LanguageUtility.capitalizeFirst(ResourceGenerator.mixtureToMaterial(fluidBlock.getFluid().getName()))))
|
||||
{
|
||||
InventoryUtility.dropItemStack(worldObj, checkAbove.clone().add(0.5), resoure.getItemStack().copy());
|
||||
}
|
||||
|
||||
// TODO: Check if this is correct?
|
||||
int remaining = amount - leakAmount;
|
||||
|
||||
/**
|
||||
* Remove liquid from top.
|
||||
*/
|
||||
fluidBlock.setQuanta(worldObj, checkAbove.intX(), checkAbove.intY(), checkAbove.intZ(), remaining);
|
||||
|
||||
/**
|
||||
* Add liquid to bottom.
|
||||
*/
|
||||
if (checkBelow.getTileEntity(worldObj) instanceof IFluidHandler)
|
||||
{
|
||||
IFluidHandler handler = ((IFluidHandler) checkBelow.getTileEntity(worldObj));
|
||||
handler.fill(ForgeDirection.UP, new FluidStack(FluidRegistry.WATER, FluidContainerRegistry.BUCKET_VOLUME), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
checkBelow.setBlock(worldObj, Block.waterMoving.blockID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue