mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-11-26 06:52:58 +00:00
Reorganize folders for modules
This commit is contained in:
1 parent
2c14f315de
commit
e2f0558b6f
370 files changed
+4274
-4788
No files matched your search
@@ -1,182 +0,0 @@
|
||||
package tconstruct.blocks.logic;
|
||||
|
||||
import tconstruct.TConstruct;
|
||||
import tconstruct.library.crafting.AlloyMix;
|
||||
import mantle.blocks.abstracts.MultiServantLogic;
|
||||
import mantle.blocks.iface.IFacingLogic;
|
||||
import mantle.blocks.iface.IMasterLogic;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
|
||||
public class AdaptiveDrainLogic extends MultiServantLogic implements IFluidHandler, IFacingLogic// , ISwitchableMaster
|
||||
{
|
||||
byte direction;
|
||||
|
||||
public boolean canUpdate ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setPotentialMaster (IMasterLogic master, World world, int x, int y, int z)
|
||||
{
|
||||
// TConstruct.logger.info("Master: "+master);
|
||||
return (master instanceof AdaptiveSmelteryLogic || master instanceof AdaptiveDrainLogic) && !getHasMaster();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill (ForgeDirection from, FluidStack resource, boolean doFill)
|
||||
{
|
||||
if (hasValidMaster() && canDrain(from, null))
|
||||
{
|
||||
AdaptiveSmelteryLogic smeltery = (AdaptiveSmelteryLogic) worldObj.getTileEntity(getMasterPosition().x, getMasterPosition().y, getMasterPosition().z);
|
||||
return smeltery.fill(from, resource, doFill);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain (ForgeDirection from, int maxDrain, boolean doDrain)
|
||||
{
|
||||
// TConstruct.logger.info("Attempting drain " + hasValidMaster());
|
||||
if (hasValidMaster() && canDrain(from, null))
|
||||
{
|
||||
AdaptiveSmelteryLogic smeltery = (AdaptiveSmelteryLogic) worldObj.getTileEntity(getMasterPosition().x, getMasterPosition().y, getMasterPosition().z);
|
||||
// TConstruct.logger.info("Found master");
|
||||
return smeltery.drain(from, maxDrain, doDrain);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain (ForgeDirection from, FluidStack resource, boolean doDrain)
|
||||
{
|
||||
if (hasValidMaster() && canDrain(from, null))
|
||||
{
|
||||
AdaptiveSmelteryLogic smeltery = (AdaptiveSmelteryLogic) worldObj.getTileEntity(getMasterPosition().x, getMasterPosition().y, getMasterPosition().z);
|
||||
return smeltery.drain(from, resource, doDrain);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFill (ForgeDirection from, Fluid fluid)
|
||||
{
|
||||
if (hasValidMaster())
|
||||
{
|
||||
AdaptiveSmelteryLogic smeltery = (AdaptiveSmelteryLogic) worldObj.getTileEntity(getMasterPosition().x, getMasterPosition().y, getMasterPosition().z);
|
||||
return smeltery.getFillState() < 2;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDrain (ForgeDirection from, Fluid fluid)
|
||||
{
|
||||
if (hasValidMaster())
|
||||
{
|
||||
AdaptiveSmelteryLogic smeltery = (AdaptiveSmelteryLogic) worldObj.getTileEntity(getMasterPosition().x, getMasterPosition().y, getMasterPosition().z);
|
||||
return smeltery.getFillState() > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo[] getTankInfo (ForgeDirection from)
|
||||
{
|
||||
if (hasValidMaster() && (from == getForgeDirection() || from == getForgeDirection().getOpposite() || from == ForgeDirection.UNKNOWN))
|
||||
{
|
||||
AdaptiveSmelteryLogic smeltery = (AdaptiveSmelteryLogic) worldObj.getTileEntity(getMasterPosition().x, getMasterPosition().y, getMasterPosition().z);
|
||||
return smeltery.getTankInfo(ForgeDirection.UNKNOWN);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getRenderDirection ()
|
||||
{
|
||||
return direction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForgeDirection getForgeDirection ()
|
||||
{
|
||||
return ForgeDirection.VALID_DIRECTIONS[direction];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDirection (int side)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDirection (float yaw, float pitch, EntityLivingBase player)
|
||||
{
|
||||
if (pitch > 45)
|
||||
direction = 1;
|
||||
else if (pitch < -45)
|
||||
direction = 0;
|
||||
else
|
||||
{
|
||||
int facing = MathHelper.floor_double((double) (yaw / 360) + 0.5D) & 3;
|
||||
switch (facing)
|
||||
{
|
||||
case 0:
|
||||
direction = 2;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
direction = 5;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
direction = 3;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
direction = 4;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void readFromNBT (NBTTagCompound tags)
|
||||
{
|
||||
super.readFromNBT(tags);
|
||||
direction = tags.getByte("Direction");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT (NBTTagCompound tags)
|
||||
{
|
||||
super.writeToNBT(tags);
|
||||
tags.setByte("Direction", direction);
|
||||
}
|
||||
|
||||
/* Packets */
|
||||
@Override
|
||||
public Packet getDescriptionPacket ()
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
writeToNBT(tag);
|
||||
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket (NetworkManager net, S35PacketUpdateTileEntity packet)
|
||||
{
|
||||
readFromNBT(packet.func_148857_g());
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
}
|
||||
}
|
||||
@@ -1,614 +0,0 @@
|
||||
package tconstruct.blocks.logic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import mantle.blocks.abstracts.AdaptiveInventoryLogic;
|
||||
import mantle.blocks.iface.IActiveLogic;
|
||||
import mantle.blocks.iface.IMasterLogic;
|
||||
import mantle.blocks.iface.IServantLogic;
|
||||
import mantle.world.CoordTuple;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
import tconstruct.TConstruct;
|
||||
import tconstruct.blocks.component.SmelteryComponent;
|
||||
import tconstruct.blocks.component.SmelteryScan;
|
||||
import tconstruct.common.TRepo;
|
||||
import tconstruct.inventory.AdaptiveSmelteryContainer;
|
||||
import tconstruct.library.component.IComponentHolder;
|
||||
import tconstruct.library.component.LogicComponent;
|
||||
import tconstruct.library.component.MultiFluidTank;
|
||||
|
||||
public class AdaptiveSmelteryLogic extends AdaptiveInventoryLogic implements IActiveLogic, IMasterLogic, IComponentHolder, IFluidHandler
|
||||
{
|
||||
byte direction;
|
||||
boolean updateFluids = false;
|
||||
boolean recheckStructure = false;
|
||||
boolean updateAir = false;
|
||||
SmelteryScan structure = new SmelteryScan(this, TRepo.smeltery, TRepo.lavaTank);
|
||||
MultiFluidTank multitank = new MultiFluidTank();
|
||||
SmelteryComponent smeltery = new SmelteryComponent(this, structure, multitank, 800);
|
||||
HashMap<CoordTuple, LiquidDataInstance> airUpdates = new HashMap<CoordTuple, LiquidDataInstance>();
|
||||
int tick = 0;
|
||||
|
||||
public MultiFluidTank getMultiTank ()
|
||||
{
|
||||
return multitank;
|
||||
}
|
||||
|
||||
public SmelteryComponent getSmeltery ()
|
||||
{
|
||||
return smeltery;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity ()
|
||||
{
|
||||
tick++;
|
||||
if (tick % 4 == 0)
|
||||
smeltery.heatItems();
|
||||
|
||||
if (!worldObj.isRemote)
|
||||
{
|
||||
if (tick % 20 == 0)
|
||||
{
|
||||
if (structure.isComplete())
|
||||
smeltery.update();
|
||||
|
||||
if (updateFluids)
|
||||
{
|
||||
distributeFluids();
|
||||
updateFluids = false;
|
||||
}
|
||||
|
||||
if (updateAir)
|
||||
{
|
||||
updateAir();
|
||||
updateAir = false;
|
||||
}
|
||||
|
||||
if (recheckStructure)
|
||||
{
|
||||
structure.recheckStructure();
|
||||
recheckStructure = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (tick >= 60)
|
||||
{
|
||||
if (!structure.isComplete())
|
||||
{
|
||||
structure.checkValidStructure();
|
||||
if (structure.isComplete())
|
||||
{
|
||||
validateSmeltery();
|
||||
}
|
||||
}
|
||||
tick = 0;
|
||||
}
|
||||
|
||||
if (airUpdates.size() > 0)
|
||||
updateFluidBlocks();
|
||||
}
|
||||
}
|
||||
|
||||
public void setUpdateFluids ()
|
||||
{
|
||||
updateFluids = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LogicComponent> getComponents ()
|
||||
{
|
||||
ArrayList<LogicComponent> ret = new ArrayList<LogicComponent>(3);
|
||||
ret.add(structure);
|
||||
ret.add(multitank);
|
||||
ret.add(smeltery);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Structure */
|
||||
|
||||
@Override
|
||||
public void setWorldObj (World world)
|
||||
{
|
||||
super.setWorldObj(world);
|
||||
structure.setWorld(world);
|
||||
smeltery.setWorld(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyChange (IServantLogic servant, int x, int y, int z)
|
||||
{
|
||||
if (!worldObj.isRemote)
|
||||
{
|
||||
// System.out.println("Notifying of change from "+new CoordTuple(x,
|
||||
// y, z));
|
||||
recheckStructure = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void placeBlock (EntityLivingBase entity, ItemStack itemstack)
|
||||
{
|
||||
structure.checkValidStructure();
|
||||
if (structure.isComplete())
|
||||
{
|
||||
validateSmeltery();
|
||||
}
|
||||
}
|
||||
|
||||
void validateSmeltery ()
|
||||
{
|
||||
adjustInventory(structure.getAirSize(), true);
|
||||
smeltery.adjustSize(structure.getAirSize(), true);
|
||||
multitank.setCapacity(structure.getAirSize() * (TConstruct.ingotLiquidValue * 18));
|
||||
smeltery.setActiveLavaTank(structure.lavaTanks.get(0));
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeBlock ()
|
||||
{
|
||||
structure.cleanup();
|
||||
}
|
||||
|
||||
/* Direction */
|
||||
|
||||
@Override
|
||||
public byte getRenderDirection ()
|
||||
{
|
||||
return direction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForgeDirection getForgeDirection ()
|
||||
{
|
||||
return ForgeDirection.VALID_DIRECTIONS[direction];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDirection (int side)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDirection (float yaw, float pitch, EntityLivingBase player)
|
||||
{
|
||||
int facing = MathHelper.floor_double((double) (yaw / 360) + 0.5D) & 3;
|
||||
switch (facing)
|
||||
{
|
||||
case 0:
|
||||
direction = 2;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
direction = 5;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
direction = 3;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
direction = 4;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getActive ()
|
||||
{
|
||||
return structure.isComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActive (boolean flag)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/* Inventory */
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit ()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents (int slot, ItemStack itemstack)
|
||||
{
|
||||
inventory[slot] = itemstack;
|
||||
if (itemstack != null && itemstack.stackSize > getInventoryStackLimit())
|
||||
{
|
||||
itemstack.stackSize = getInventoryStackLimit();
|
||||
}
|
||||
updateWorldBlock(slot, itemstack);
|
||||
updateAir = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize (int slot, int quantity)
|
||||
{
|
||||
if (inventory[slot] != null)
|
||||
{
|
||||
if (inventory[slot].stackSize <= quantity)
|
||||
{
|
||||
ItemStack stack = inventory[slot];
|
||||
inventory[slot] = null;
|
||||
updateWorldBlock(slot, inventory[slot]);
|
||||
return stack;
|
||||
}
|
||||
ItemStack split = inventory[slot].splitStack(quantity);
|
||||
if (inventory[slot].stackSize == 0)
|
||||
{
|
||||
inventory[slot] = null;
|
||||
}
|
||||
|
||||
updateWorldBlock(slot, inventory[slot]);
|
||||
return split;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty ()
|
||||
{
|
||||
smeltery.updateTemperatures();
|
||||
updateAir = true;
|
||||
super.markDirty();
|
||||
}
|
||||
|
||||
void updateWorldBlock (int slot, ItemStack itemstack)
|
||||
{
|
||||
CoordTuple air = structure.getAirByIndex(slot);
|
||||
if (air != null)
|
||||
{
|
||||
TileEntity te = worldObj.getTileEntity(air.x, air.y, air.z);
|
||||
if (te != null && te instanceof TankAirLogic)
|
||||
{
|
||||
((TankAirLogic) te).setInventorySlotContents(0, itemstack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static final int pixelLayer = 162;
|
||||
|
||||
// Do the Monster Mash~
|
||||
public void distributeFluids ()
|
||||
{
|
||||
// Calculate liquids in each block
|
||||
int size = structure.getAirLayerSize();
|
||||
// HashMap<CoordTuple, LiquidDataInstance> blocks = new
|
||||
// HashMap<CoordTuple, LiquidDataInstance>();
|
||||
|
||||
for (FluidStack fluid : multitank.fluidlist)
|
||||
{
|
||||
// Base calculations per liquid
|
||||
LiquidData data = new LiquidData(fluid.amount, size);
|
||||
int baseY = structure.airCoords.get(0).y;
|
||||
int layerSize = structure.getAirLayerSize();
|
||||
|
||||
// Calculate where to distribute liquids
|
||||
for (int i = 0; i < structure.airCoords.size(); i++)
|
||||
{
|
||||
LiquidDataInstance instance;
|
||||
CoordTuple coord = structure.airCoords.get(i);
|
||||
int height = 16 * (coord.y - baseY);
|
||||
int position = i % layerSize;
|
||||
|
||||
if (!airUpdates.containsKey(coord))
|
||||
{
|
||||
instance = new LiquidDataInstance();
|
||||
airUpdates.put(coord, instance);
|
||||
}
|
||||
else
|
||||
{
|
||||
instance = airUpdates.get(coord);
|
||||
}
|
||||
|
||||
if (instance.openLayers() > 0) // This is capable of sending
|
||||
// negative liquid sizes to
|
||||
// blocks without the stopgap
|
||||
// check
|
||||
{
|
||||
if (position > data.blocksWithExtra)
|
||||
{
|
||||
// Calculate open layers
|
||||
int open = data.layers - height + 1;
|
||||
if (open < 1) // Temporary stopgap check
|
||||
continue;
|
||||
if (open > instance.openLayers())
|
||||
open = instance.openLayers();
|
||||
|
||||
// Copy fluid
|
||||
FluidStack newFluid = fluid.copy();
|
||||
newFluid.amount = pixelLayer * open;
|
||||
instance.addFluid(open, newFluid);
|
||||
|
||||
// Subtract from total
|
||||
data.totalAmount -= newFluid.amount;
|
||||
if (data.totalAmount <= 0)
|
||||
break;
|
||||
}
|
||||
else if (position == data.blocksWithExtra && data.leftovers > 0)
|
||||
{
|
||||
// Calculate open layers
|
||||
int open = data.layers - height + 1;
|
||||
if (open < 1) // Temporary stopgap check
|
||||
continue;
|
||||
boolean full = false;
|
||||
if (open > instance.openLayers())
|
||||
{
|
||||
open = instance.openLayers();
|
||||
full = true;
|
||||
}
|
||||
|
||||
// Copy fluid
|
||||
FluidStack newFluid = fluid.copy();
|
||||
newFluid.amount = pixelLayer * open;
|
||||
if (!full)
|
||||
newFluid.amount += data.leftovers;
|
||||
instance.addFluid(open, newFluid);
|
||||
|
||||
// Subtract from total
|
||||
data.totalAmount -= newFluid.amount;
|
||||
if (data.totalAmount <= 0)
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Calculate open layers
|
||||
int open = data.layers - height;
|
||||
if (open < 1) // Temporary stopgap check
|
||||
continue;
|
||||
if (open > instance.openLayers())
|
||||
open = instance.openLayers();
|
||||
|
||||
// Copy fluid
|
||||
FluidStack newFluid = fluid.copy();
|
||||
newFluid.amount = pixelLayer * open;
|
||||
instance.addFluid(open, newFluid);
|
||||
|
||||
// Subtract from total
|
||||
data.totalAmount -= newFluid.amount;
|
||||
if (data.totalAmount <= 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Distribute liquids to each block
|
||||
}
|
||||
|
||||
protected void updateFluidBlocks ()
|
||||
{
|
||||
Iterator iter = airUpdates.entrySet().iterator();
|
||||
byte count = 0;
|
||||
while (iter.hasNext() && count < 40)
|
||||
{
|
||||
Map.Entry pairs = (Map.Entry) iter.next();
|
||||
CoordTuple coord = (CoordTuple) pairs.getKey();
|
||||
TileEntity te = worldObj.getTileEntity(coord.x, coord.y, coord.z);
|
||||
if (te instanceof TankAirLogic)
|
||||
{
|
||||
((TankAirLogic) te).overrideFluids(((LiquidDataInstance) pairs.getValue()).fluids);
|
||||
}
|
||||
iter.remove();
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
public void updateAir ()
|
||||
{
|
||||
for (CoordTuple loc : structure.airCoords)
|
||||
worldObj.markBlockForUpdate(loc.x, loc.y, loc.z);
|
||||
}
|
||||
|
||||
class LiquidData
|
||||
{
|
||||
public int totalAmount;
|
||||
public int layers;
|
||||
public int leftovers;
|
||||
public int blocksWithExtra;
|
||||
|
||||
LiquidData(int amount, int blocks)
|
||||
{
|
||||
totalAmount = amount;
|
||||
int layerAmount = pixelLayer * blocks;
|
||||
layers = amount / layerAmount;
|
||||
leftovers = amount % pixelLayer;
|
||||
blocksWithExtra = (amount % layerAmount) / pixelLayer;
|
||||
}
|
||||
}
|
||||
|
||||
class LiquidDataInstance
|
||||
{
|
||||
public ArrayList<FluidStack> fluids = new ArrayList<FluidStack>();
|
||||
int layers = 0;
|
||||
|
||||
public int openLayers ()
|
||||
{
|
||||
return 16 - layers;
|
||||
}
|
||||
|
||||
public void addFluid (int l, FluidStack fluid)
|
||||
{
|
||||
layers += l;
|
||||
fluids.add(fluid);
|
||||
}
|
||||
}
|
||||
|
||||
/* Gui */
|
||||
|
||||
@Override
|
||||
public Container getGuiContainer (InventoryPlayer inventoryplayer, World world, int x, int y, int z)
|
||||
{
|
||||
return new AdaptiveSmelteryContainer(inventoryplayer, this);
|
||||
}
|
||||
|
||||
public int getTempForSlot (int slot)
|
||||
{
|
||||
return smeltery.activeTemps[slot];
|
||||
}
|
||||
|
||||
public int getMeltingPointForSlot (int slot)
|
||||
{
|
||||
return smeltery.meltingTemps[slot];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultName ()
|
||||
{
|
||||
return "crafters.Smeltery";
|
||||
}
|
||||
|
||||
/* Fluids */
|
||||
|
||||
@Override
|
||||
public int fill (ForgeDirection from, FluidStack resource, boolean doFill)
|
||||
{
|
||||
return multitank.fill(resource, doFill);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain (ForgeDirection from, FluidStack resource, boolean doDrain)
|
||||
{
|
||||
return multitank.drain(resource.amount, doDrain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain (ForgeDirection from, int maxDrain, boolean doDrain)
|
||||
{
|
||||
return multitank.drain(maxDrain, doDrain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFill (ForgeDirection from, Fluid fluid)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDrain (ForgeDirection from, Fluid fluid)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo[] getTankInfo (ForgeDirection from)
|
||||
{
|
||||
return multitank.getMultiTankInfo();
|
||||
}
|
||||
|
||||
public int getFillState ()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* NBT */
|
||||
|
||||
@Override
|
||||
public void readFromNBT (NBTTagCompound tags)
|
||||
{
|
||||
super.readFromNBT(tags);
|
||||
readNetworkNBT(tags);
|
||||
|
||||
structure.readFromNBT(tags);
|
||||
multitank.readFromNBT(tags);
|
||||
smeltery.readFromNBT(tags);
|
||||
}
|
||||
|
||||
public void readNetworkNBT (NBTTagCompound tags)
|
||||
{
|
||||
direction = tags.getByte("Direction");
|
||||
adjustInventory(tags.getInteger("InvSize"), false);
|
||||
super.readInventoryFromNBT(tags);
|
||||
|
||||
structure.readNetworkNBT(tags);
|
||||
multitank.readNetworkNBT(tags);
|
||||
smeltery.readNetworkNBT(tags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT (NBTTagCompound tags)
|
||||
{
|
||||
super.writeToNBT(tags);
|
||||
writeNetworkNBT(tags);
|
||||
|
||||
structure.writeToNBT(tags);
|
||||
multitank.writeToNBT(tags);
|
||||
smeltery.writeToNBT(tags);
|
||||
}
|
||||
|
||||
public void writeNetworkNBT (NBTTagCompound tags)
|
||||
{
|
||||
tags.setByte("Direction", direction);
|
||||
tags.setInteger("InvSize", inventory.length);
|
||||
super.writeInventoryToNBT(tags);
|
||||
|
||||
structure.writeNetworkNBT(tags);
|
||||
multitank.writeNetworkNBT(tags);
|
||||
smeltery.writeNetworkNBT(tags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket (NetworkManager net, S35PacketUpdateTileEntity packet)
|
||||
{
|
||||
readNetworkNBT(packet.func_148857_g());
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket ()
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
writeNetworkNBT(tag);
|
||||
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName ()
|
||||
{
|
||||
return getDefaultName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory ()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory ()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package tconstruct.blocks.logic;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public class AqueductLogic extends TileEntity // implements ITankContainer
|
||||
{
|
||||
|
||||
/*
|
||||
* @Override public int fill (ForgeDirection from, FluidStack resource,
|
||||
* boolean doFill) { return 0; }
|
||||
*
|
||||
* @Override public int fill (int tankIndex, FluidStack resource, boolean
|
||||
* doFill) { return 0; }
|
||||
*
|
||||
* @Override public FluidStack drain (ForgeDirection from, int maxDrain,
|
||||
* boolean doDrain) { return null; }
|
||||
*
|
||||
* @Override public FluidStack drain (int tankIndex, int maxDrain, boolean
|
||||
* doDrain) { return null; }
|
||||
*
|
||||
* @Override public ILiquidTank[] getTanks (ForgeDirection direction) {
|
||||
* return null; }
|
||||
*
|
||||
* @Override public ILiquidTank getTank (ForgeDirection direction,
|
||||
* FluidStack type) { return null; }
|
||||
*/
|
||||
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
package tconstruct.blocks.logic;
|
||||
|
||||
import tconstruct.inventory.FrypanContainer;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemFood;
|
||||
import net.minecraft.item.ItemHoe;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemSword;
|
||||
import net.minecraft.item.ItemTool;
|
||||
import net.minecraft.item.crafting.FurnaceRecipes;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
/* Slots
|
||||
* 0: Battlesign item
|
||||
*/
|
||||
|
||||
public class BattlesignLogic extends EquipLogic
|
||||
{
|
||||
|
||||
public BattlesignLogic()
|
||||
{
|
||||
super(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultName ()
|
||||
{
|
||||
return "decoration.battlesign";
|
||||
}
|
||||
|
||||
/* NBT */
|
||||
public void readFromNBT (NBTTagCompound tags)
|
||||
{
|
||||
super.readFromNBT(tags);
|
||||
}
|
||||
|
||||
public void writeToNBT (NBTTagCompound tags)
|
||||
{
|
||||
super.writeToNBT(tags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Container getGuiContainer (InventoryPlayer inventoryplayer, World world, int x, int y, int z)
|
||||
{
|
||||
return null; //Not a normal gui block
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName ()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory ()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory ()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,456 +0,0 @@
|
||||
package tconstruct.blocks.logic;
|
||||
|
||||
import mantle.blocks.abstracts.InventoryLogic;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidEvent;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
import net.minecraftforge.fluids.IFluidTank;
|
||||
import tconstruct.TConstruct;
|
||||
import tconstruct.library.crafting.CastingRecipe;
|
||||
import tconstruct.library.util.IPattern;
|
||||
|
||||
public class CastingBasinLogic extends InventoryLogic implements IFluidTank, IFluidHandler, ISidedInventory
|
||||
{
|
||||
public FluidStack liquid;
|
||||
int castingDelay = 0;
|
||||
int renderOffset = 0;
|
||||
int capacity = 0;
|
||||
boolean needsUpdate;
|
||||
boolean init = true;
|
||||
int tick;
|
||||
|
||||
public CastingBasinLogic()
|
||||
{
|
||||
super(2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit ()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInvName () // Not a gui block
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultName () // Still not a gui block
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Container getGuiContainer (InventoryPlayer inventoryplayer, World world, int x, int y, int z) // Definitely not a gui block
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/* Tank */
|
||||
|
||||
@Override
|
||||
public int getCapacity ()
|
||||
{
|
||||
return this.capacity;
|
||||
}
|
||||
|
||||
public int updateCapacity () // Only used to initialize
|
||||
{
|
||||
ItemStack inv = inventory[0];
|
||||
int ret = TConstruct.ingotLiquidValue;
|
||||
int rec = TConstruct.basinCasting.getCastingAmount(this.liquid, inv);
|
||||
|
||||
if (rec > 0)
|
||||
ret = rec;
|
||||
else {
|
||||
if (inv != null && inv.getItem() instanceof IPattern)
|
||||
{
|
||||
int cost = ((IPattern) inv.getItem()).getPatternCost(inv);
|
||||
if (cost > 0)
|
||||
ret *= ((IPattern) inv.getItem()).getPatternCost(inv) * 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
TConstruct.logger.info("Ret: " + ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int updateCapacity (int capacity)
|
||||
{
|
||||
int ret = TConstruct.ingotLiquidValue;
|
||||
|
||||
if (capacity > 0)
|
||||
ret = capacity;
|
||||
else {
|
||||
ItemStack inv = inventory[0];
|
||||
|
||||
if (inv != null && inv.getItem() instanceof IPattern)
|
||||
{
|
||||
int cost = ((IPattern) inv.getItem()).getPatternCost(inv);
|
||||
if (cost > 0)
|
||||
ret *= cost * 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill (FluidStack resource, boolean doFill)
|
||||
{
|
||||
if (resource == null)
|
||||
return 0;
|
||||
|
||||
if (this.liquid == null)
|
||||
{
|
||||
CastingRecipe recipe = TConstruct.basinCasting.getCastingRecipe(resource, inventory[0]);
|
||||
if (recipe == null)
|
||||
return 0;
|
||||
this.capacity = updateCapacity(recipe.castingMetal.amount);
|
||||
|
||||
if (inventory[1] == null)
|
||||
{
|
||||
FluidStack copyLiquid = resource.copy();
|
||||
|
||||
if (copyLiquid.amount > this.capacity)
|
||||
{
|
||||
copyLiquid.amount = this.capacity;
|
||||
}
|
||||
|
||||
if (doFill)
|
||||
{
|
||||
if (copyLiquid.amount == this.capacity)
|
||||
{
|
||||
castingDelay = recipe.coolTime;
|
||||
}
|
||||
renderOffset = copyLiquid.amount;
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
this.liquid = copyLiquid;
|
||||
needsUpdate = true;
|
||||
}
|
||||
return copyLiquid.amount;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
else if (resource.isFluidEqual(this.liquid))
|
||||
{
|
||||
if (resource.amount + this.liquid.amount >= this.capacity) // Start
|
||||
// timer
|
||||
// here
|
||||
{
|
||||
int roomInTank = this.capacity - liquid.amount;
|
||||
if (doFill && roomInTank > 0)
|
||||
{
|
||||
renderOffset = roomInTank;
|
||||
castingDelay = TConstruct.basinCasting.getCastingDelay(this.liquid, inventory[0]);
|
||||
this.liquid.amount = this.capacity;
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
needsUpdate = true;
|
||||
}
|
||||
return roomInTank;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (doFill)
|
||||
{
|
||||
this.liquid.amount += resource.amount;
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
needsUpdate = true;
|
||||
}
|
||||
return resource.amount;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty () // Isn't actually called?
|
||||
{
|
||||
super.markDirty();
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
needsUpdate = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize (int slot, int quantity)
|
||||
{
|
||||
ItemStack stack = super.decrStackSize(slot, quantity);
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain (int maxDrain, boolean doDrain)
|
||||
{
|
||||
if (liquid == null || liquid.fluidID <= 0 || castingDelay > 0)
|
||||
return null;
|
||||
if (liquid.amount <= 0)
|
||||
return null;
|
||||
|
||||
int used = maxDrain;
|
||||
if (liquid.amount < used)
|
||||
used = liquid.amount;
|
||||
|
||||
if (doDrain)
|
||||
{
|
||||
liquid.amount -= used;
|
||||
}
|
||||
|
||||
FluidStack drained = liquid.copy();// new FluidStack(liquid.itemID,
|
||||
// used, liquid.itemMeta);
|
||||
drained.amount = used;
|
||||
|
||||
// Reset liquid if emptied
|
||||
if (liquid.amount <= 0)
|
||||
liquid = null;
|
||||
|
||||
if (doDrain)
|
||||
FluidEvent.fireEvent(new FluidEvent.FluidDrainingEvent(drained, this.worldObj, this.xCoord, this.yCoord, this.zCoord, this));
|
||||
|
||||
return drained;
|
||||
}
|
||||
|
||||
/* Tank Container */
|
||||
|
||||
@Override
|
||||
public int fill (ForgeDirection from, FluidStack resource, boolean doFill)
|
||||
{
|
||||
// if (from == ForgeDirection.UP)
|
||||
return fill(resource, doFill);
|
||||
// return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain (ForgeDirection from, int maxDrain, boolean doDrain)
|
||||
{
|
||||
return drain(maxDrain, doDrain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain (ForgeDirection from, FluidStack resource, boolean doDrain)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFill (ForgeDirection from, Fluid fluid)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDrain (ForgeDirection from, Fluid fluid)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo[] getTankInfo (ForgeDirection from)
|
||||
{
|
||||
return new FluidTankInfo[] { getInfo() };
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack getFluid ()
|
||||
{
|
||||
return liquid == null ? null : liquid.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFluidAmount ()
|
||||
{
|
||||
return liquid != null ? liquid.amount : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo getInfo ()
|
||||
{
|
||||
FluidTankInfo info = new FluidTankInfo(this);
|
||||
return info;
|
||||
}
|
||||
|
||||
public int getLiquidAmount ()
|
||||
{
|
||||
return liquid.amount - renderOffset;
|
||||
}
|
||||
|
||||
/* Updating */
|
||||
@Override
|
||||
public void updateEntity ()
|
||||
{
|
||||
if (castingDelay > 0)
|
||||
{
|
||||
// TConstruct.logger.info("Casting");
|
||||
castingDelay--;
|
||||
if (castingDelay == 0)
|
||||
castLiquid();
|
||||
}
|
||||
if (renderOffset > 0)
|
||||
{
|
||||
renderOffset -= 6;
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
tick++;
|
||||
if (tick % 20 == 0)
|
||||
{
|
||||
tick = 0;
|
||||
if (needsUpdate)
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
}
|
||||
}
|
||||
|
||||
public void castLiquid ()
|
||||
{
|
||||
CastingRecipe recipe = TConstruct.basinCasting.getCastingRecipe(liquid, inventory[0]);
|
||||
if (recipe != null)
|
||||
{
|
||||
inventory[1] = recipe.getResult();
|
||||
if (recipe.consumeCast)
|
||||
inventory[0] = null;
|
||||
liquid = null;
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
}
|
||||
}
|
||||
|
||||
/* NBT */
|
||||
|
||||
@Override
|
||||
public void readFromNBT (NBTTagCompound tags)
|
||||
{
|
||||
super.readFromNBT(tags);
|
||||
readCustomNBT(tags);
|
||||
}
|
||||
|
||||
public void readCustomNBT (NBTTagCompound tags)
|
||||
{
|
||||
if (tags.getBoolean("hasLiquid"))
|
||||
{
|
||||
this.liquid = FluidStack.loadFluidStackFromNBT(tags.getCompoundTag("Fluid"));
|
||||
}
|
||||
// FluidStack fluid = FluidStack.loadFluidStackFromNBT(nbt);
|
||||
// this.liquid = new FluidStack(tags.getInteger("itemID"),
|
||||
// tags.getInteger("amount"), tags.getInteger("itemMeta"));
|
||||
else
|
||||
this.liquid = null;
|
||||
|
||||
if (tags.getBoolean("Initialized"))
|
||||
this.capacity = tags.getInteger("Capacity");
|
||||
else
|
||||
this.capacity = updateCapacity();
|
||||
this.castingDelay = tags.getInteger("castingDelay");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT (NBTTagCompound tags)
|
||||
{
|
||||
super.writeToNBT(tags);
|
||||
writeCustomNBT(tags);
|
||||
}
|
||||
|
||||
public void writeCustomNBT (NBTTagCompound tags)
|
||||
{
|
||||
tags.setBoolean("hasLiquid", liquid != null);
|
||||
if (liquid != null)
|
||||
{
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
liquid.writeToNBT(nbt);
|
||||
tags.setTag("Fluid", nbt);
|
||||
}
|
||||
tags.setBoolean("Initialized", init);
|
||||
tags.setInteger("Capacity", capacity);
|
||||
tags.setInteger("castingDelay", castingDelay);
|
||||
}
|
||||
|
||||
/* Packets */
|
||||
@Override
|
||||
public Packet getDescriptionPacket ()
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
writeToNBT(tag);
|
||||
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket (NetworkManager net, S35PacketUpdateTileEntity packet)
|
||||
{
|
||||
readFromNBT(packet.func_148857_g());
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide (int side)
|
||||
{
|
||||
return new int[] { 0, 1 };
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem (int slot, ItemStack itemstack, int side)
|
||||
{
|
||||
if (liquid != null)
|
||||
return false;
|
||||
|
||||
if (slot == 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem (int slot, ItemStack itemstack, int side)
|
||||
{
|
||||
if (slot == 1)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName ()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory ()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory ()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,584 +0,0 @@
|
||||
package tconstruct.blocks.logic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
import mantle.blocks.iface.IActiveLogic;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidEvent;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
import net.minecraftforge.fluids.IFluidTank;
|
||||
import tconstruct.TConstruct;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
/**
|
||||
* @author BluSunrize
|
||||
*/
|
||||
|
||||
public class CastingChannelLogic extends TileEntity implements IFluidHandler
|
||||
{
|
||||
public final static int fillMax = TConstruct.ingotLiquidValue;
|
||||
public final static int outputMax = TConstruct.ingotLiquidValue;
|
||||
FluidTank internalTank = new FluidTank(fillMax);
|
||||
HashMap<ForgeDirection, FluidTank> subTanks = new HashMap();
|
||||
public ForgeDirection lastProvider;
|
||||
public ArrayList<ForgeDirection> validOutputs = new ArrayList();
|
||||
public int ticks = 0;
|
||||
public int recentlyFilledDelay;
|
||||
|
||||
/* UNUSED
|
||||
public CastingChannelMode mode = CastingChannelMode.SINGLEDRAIN;
|
||||
*/
|
||||
|
||||
public CastingChannelLogic()
|
||||
{
|
||||
lastProvider = ForgeDirection.UNKNOWN;
|
||||
validOutputs.add(ForgeDirection.DOWN);
|
||||
validOutputs.add(ForgeDirection.NORTH);
|
||||
validOutputs.add(ForgeDirection.SOUTH);
|
||||
validOutputs.add(ForgeDirection.EAST);
|
||||
validOutputs.add(ForgeDirection.WEST);
|
||||
|
||||
subTanks.put(ForgeDirection.NORTH, new FluidTank(TConstruct.ingotLiquidValue / 4));
|
||||
subTanks.put(ForgeDirection.SOUTH, new FluidTank(TConstruct.ingotLiquidValue / 4));
|
||||
subTanks.put(ForgeDirection.WEST, new FluidTank(TConstruct.ingotLiquidValue / 4));
|
||||
subTanks.put(ForgeDirection.EAST, new FluidTank(TConstruct.ingotLiquidValue / 4));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity ()
|
||||
{
|
||||
ticks++;
|
||||
|
||||
boolean flagActiveFaucet = false;
|
||||
|
||||
TileEntity possibleFaucet = worldObj.getTileEntity(xCoord, yCoord + 1, zCoord);
|
||||
if (possibleFaucet != null && possibleFaucet instanceof FaucetLogic)
|
||||
flagActiveFaucet = ((FaucetLogic) possibleFaucet).active;
|
||||
|
||||
if (ticks == 6 && !flagActiveFaucet)
|
||||
this.distributeFluids();
|
||||
if (ticks >= 12 && !flagActiveFaucet)
|
||||
{
|
||||
if (recentlyFilledDelay != 0)
|
||||
recentlyFilledDelay--;
|
||||
if (recentlyFilledDelay == 0 || lastProvider == ForgeDirection.UP)
|
||||
this.outputFluids();
|
||||
|
||||
ticks = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void changeOutputs (EntityPlayer player, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
/*
|
||||
* UNUSED
|
||||
if(player.isSneaking())
|
||||
{
|
||||
|
||||
if(mode == null || mode == CastingChannelMode.SINGLEDRAIN)
|
||||
mode = CastingChannelMode.CONTINUEDRAIN;
|
||||
else
|
||||
mode = CastingChannelMode.SINGLEDRAIN;
|
||||
|
||||
String s = "Casting Channel Mode "+(worldObj.isRemote?"client side: ":"server side: ");
|
||||
player.addChatMessage(s+mode.toString());
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
ForgeDirection toggle = ForgeDirection.UNKNOWN;
|
||||
if (side == 0 || side == 1)
|
||||
{
|
||||
if (hitX > 0.3125 && hitX < 0.6875)
|
||||
if (hitZ > 0 && hitZ < 0.3125)
|
||||
toggle = ForgeDirection.NORTH;
|
||||
if (hitX > 0.3125 && hitX < 0.6875)
|
||||
if (hitZ > 0.6875 && hitZ < 1)
|
||||
toggle = ForgeDirection.SOUTH;
|
||||
if (hitZ > 0.3125 && hitZ < 0.6875)
|
||||
if (hitX > 0 && hitX < 0.3125)
|
||||
toggle = ForgeDirection.WEST;
|
||||
if (hitZ > 0.3125 && hitZ < 0.6875)
|
||||
if (hitX > 0.6875 && hitX < 1)
|
||||
toggle = ForgeDirection.EAST;
|
||||
|
||||
if (side == 0)
|
||||
if (hitX > 0.3125 && hitX < 0.6875)
|
||||
if (hitZ > 0.3125 && hitZ < 0.6875)
|
||||
toggle = ForgeDirection.DOWN;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (side == 2)
|
||||
{
|
||||
if (hitX > 0 && hitX < 0.3125)
|
||||
toggle = ForgeDirection.WEST;
|
||||
if (hitX > 0.6875 && hitX < 1)
|
||||
toggle = ForgeDirection.EAST;
|
||||
}
|
||||
if (side == 3)
|
||||
{
|
||||
if (hitX > 0 && hitX < 0.3125)
|
||||
toggle = ForgeDirection.WEST;
|
||||
if (hitX > 0.6875 && hitX < 1)
|
||||
toggle = ForgeDirection.EAST;
|
||||
}
|
||||
if (side == 4)
|
||||
{
|
||||
if (hitZ > 0 && hitZ < 0.3125)
|
||||
toggle = ForgeDirection.NORTH;
|
||||
if (hitZ > 0.6875 && hitZ < 1)
|
||||
toggle = ForgeDirection.SOUTH;
|
||||
}
|
||||
if (side == 5)
|
||||
{
|
||||
if (hitZ > 0 && hitZ < 0.3125)
|
||||
toggle = ForgeDirection.NORTH;
|
||||
if (hitZ > 0.6875 && hitZ < 1)
|
||||
toggle = ForgeDirection.SOUTH;
|
||||
}
|
||||
}
|
||||
|
||||
if (toggle != ForgeDirection.UNKNOWN && toggle != ForgeDirection.UP)
|
||||
{
|
||||
TileEntity tile = worldObj.getTileEntity(xCoord + toggle.offsetX, yCoord + toggle.offsetY, zCoord + toggle.offsetZ);
|
||||
if (tile instanceof IFluidHandler)
|
||||
if (validOutputs.contains(toggle))
|
||||
{
|
||||
validOutputs.remove(toggle);
|
||||
if (tile instanceof CastingChannelLogic && toggle != ForgeDirection.DOWN)
|
||||
((CastingChannelLogic) tile).validOutputs.remove(toggle.getOpposite());
|
||||
}
|
||||
else
|
||||
{
|
||||
validOutputs.add(toggle);
|
||||
if (tile instanceof CastingChannelLogic && toggle != ForgeDirection.DOWN)
|
||||
if (!((CastingChannelLogic) tile).validOutputs.contains(toggle.getOpposite()))
|
||||
((CastingChannelLogic) tile).validOutputs.add(toggle.getOpposite());
|
||||
}
|
||||
|
||||
}
|
||||
this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
private void distributeFluids ()
|
||||
{
|
||||
/* DEBUG
|
||||
boolean printDebugLog = false;
|
||||
ArrayList<String> debugLog = new ArrayList();
|
||||
*/
|
||||
//Move Fluid to Output Tanks
|
||||
Set<ForgeDirection> connected = this.getOutputs().keySet();
|
||||
|
||||
if (connected.contains(ForgeDirection.DOWN))
|
||||
connected.remove(ForgeDirection.DOWN);
|
||||
if (connected.contains(lastProvider))
|
||||
connected.remove(lastProvider);
|
||||
|
||||
int output = Math.min(internalTank.getFluidAmount(), 12);
|
||||
int connectedAmount = connected.size();
|
||||
if (connectedAmount < 1)
|
||||
connectedAmount = 1;
|
||||
int scaledAmount = output / connectedAmount;
|
||||
|
||||
for (ForgeDirection dirOut : connected)
|
||||
{
|
||||
if (this.internalTank.getFluid() == null)
|
||||
break;
|
||||
|
||||
/* DEBUG
|
||||
debugLog.add("Moving to "+dirOut+"ern SubTank");
|
||||
*/
|
||||
FluidStack tempFS = new FluidStack(internalTank.getFluid().getFluid(), scaledAmount);
|
||||
int fit = subTanks.get(dirOut).fill(tempFS, false);
|
||||
/* DEBUG
|
||||
debugLog.add("SubTank will accept "+fit+"mb");
|
||||
*/
|
||||
if (fit > 0)
|
||||
fit = internalTank.drain(fit, true).amount;
|
||||
/* DEBUG
|
||||
debugLog.add("Internal Tank was drained by "+fit+"mb");
|
||||
*/
|
||||
tempFS.amount = fit;
|
||||
fit = subTanks.get(dirOut).fill(tempFS, true);
|
||||
/* DEBUG
|
||||
debugLog.add("SubTank was filled by "+fit+"mb");
|
||||
if(fit > 0)
|
||||
printDebugLog = true;
|
||||
debugLog.add("Internal Tank now contains: "+internalTank.getFluidAmount()+"mb");
|
||||
debugLog.add("SubTank now contains: "+subTanks.get(dirOut).getFluidAmount()+"mb");
|
||||
*/
|
||||
this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
}
|
||||
/* DEBUG
|
||||
if(printDebugLog)
|
||||
{
|
||||
for(String s: debugLog)
|
||||
System.out.println(s);
|
||||
debugLog.clear();
|
||||
}
|
||||
printDebugLog = false;
|
||||
*/
|
||||
|
||||
//Get Fluid from most recent InputTank
|
||||
FluidTank inputTank = subTanks.get(lastProvider);
|
||||
if (inputTank != null && inputTank.getFluid() != null) //Tank can be null if input was received from top
|
||||
{
|
||||
/* DEBUG
|
||||
debugLog.add("Importing from "+lastProvider+"ern SubTank");
|
||||
*/
|
||||
FluidStack tempFS = new FluidStack(inputTank.getFluid().getFluid(), Math.min(inputTank.getFluidAmount(), 12));
|
||||
int fit = internalTank.fill(tempFS, false);
|
||||
/* DEBUG
|
||||
debugLog.add("Internal Tank will accept "+fit+"mb");
|
||||
*/
|
||||
if (fit > 0)
|
||||
fit = inputTank.drain(fit, true).amount;
|
||||
/* DEBUG
|
||||
debugLog.add("Import Tank was drained by "+fit+"mb");
|
||||
*/
|
||||
tempFS.amount = fit;
|
||||
fit = internalTank.fill(tempFS, true);
|
||||
/* DEBUG
|
||||
debugLog.add("Internal Tank was filled by "+fit+"mb");
|
||||
if(fit > 0)
|
||||
printDebugLog = true;
|
||||
debugLog.add("Internal Tank now contains: "+internalTank.getFluidAmount()+"mb");
|
||||
debugLog.add("SubTank now contains: "+inputTank.getFluidAmount()+"mb");
|
||||
*/
|
||||
|
||||
this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
}
|
||||
/* DEBUG
|
||||
if(printDebugLog)
|
||||
{
|
||||
for(String s: debugLog)
|
||||
System.out.println(s);
|
||||
debugLog.clear();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
private void outputFluids ()
|
||||
{
|
||||
/* DEBUG
|
||||
boolean printDebugLog = false;
|
||||
ArrayList<String> debugLog = new ArrayList();
|
||||
*/
|
||||
|
||||
HashMap<ForgeDirection, TileEntity> connected = this.getOutputs();
|
||||
if (connected.containsKey(lastProvider))
|
||||
connected.remove(lastProvider);
|
||||
if (connected.containsKey(ForgeDirection.DOWN) && this.internalTank.getFluid() != null) // Prioritizes FluidHandlers below
|
||||
{
|
||||
int output = Math.min(internalTank.getFluid().amount, 12);
|
||||
FluidStack tempFS = new FluidStack(internalTank.getFluid().getFluid(), output);
|
||||
int fittingBelow = ((IFluidHandler) connected.get(ForgeDirection.DOWN)).fill(ForgeDirection.UP, tempFS, false);
|
||||
if (fittingBelow > 0)
|
||||
fittingBelow = this.drain(ForgeDirection.DOWN, fittingBelow, true).amount;
|
||||
tempFS.amount = fittingBelow;
|
||||
fittingBelow = ((IFluidHandler) connected.get(ForgeDirection.DOWN)).fill(ForgeDirection.UP, tempFS, true);
|
||||
|
||||
connected.remove(ForgeDirection.DOWN);
|
||||
}
|
||||
if (connected.size() != 0)
|
||||
{
|
||||
for (ForgeDirection dir : connected.keySet()) //Iterates to connected FluidHandlers
|
||||
{
|
||||
if (subTanks.get(dir) != null && subTanks.get(dir).getFluid() != null)
|
||||
{
|
||||
/* DEBUG
|
||||
debugLog.add("Exporting from "+dir+"ern SubTank");
|
||||
*/
|
||||
FluidStack tempFS = new FluidStack(subTanks.get(dir).getFluid().getFluid(), Math.min(subTanks.get(dir).getFluidAmount(), 12));
|
||||
int fit = ((IFluidHandler) connected.get(dir)).fill(dir.getOpposite(), tempFS, false);
|
||||
/* DEBUG
|
||||
debugLog.add("New Channel will accept "+fit+"mb");
|
||||
*/
|
||||
if (fit > 0)
|
||||
fit = this.drain(dir, fit, true).amount;
|
||||
/* DEBUG
|
||||
debugLog.add("OldSubTank was drained by "+fit+"mb");
|
||||
*/
|
||||
tempFS.amount = fit;
|
||||
fit = ((IFluidHandler) connected.get(dir)).fill(dir.getOpposite(), tempFS, true);
|
||||
/* DEBUG
|
||||
debugLog.add("New Channel was filled by "+fit+"mb");
|
||||
|
||||
debugLog.add("OldSubTank now contains: "+drain(dir, 100000, false).amount+"mb");
|
||||
if(fit > 0)
|
||||
printDebugLog = true;
|
||||
*/
|
||||
}
|
||||
/* DEBUG
|
||||
for(String s: debugLog)
|
||||
System.out.println(s);
|
||||
debugLog.clear();
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float tankBelow ()
|
||||
{
|
||||
TileEntity te = this.worldObj.getTileEntity(this.xCoord, this.yCoord - 1, this.zCoord);
|
||||
if (te instanceof CastingChannelLogic)
|
||||
return -0.5f;
|
||||
if (te instanceof LavaTankLogic)
|
||||
return -1.0f;
|
||||
if (te instanceof CastingBasinLogic)
|
||||
return -0.75f;
|
||||
if (te instanceof CastingTableLogic)
|
||||
return -0.125f;
|
||||
if (te instanceof IFluidHandler)
|
||||
return 0f;
|
||||
|
||||
return 0.5f;
|
||||
}
|
||||
|
||||
public HashMap<ForgeDirection, TileEntity> getOutputs ()
|
||||
{
|
||||
HashMap<ForgeDirection, TileEntity> map = new HashMap();
|
||||
for (ForgeDirection fd : this.validOutputs)
|
||||
{
|
||||
int tX = this.xCoord + fd.offsetX;
|
||||
int tY = this.yCoord + fd.offsetY;
|
||||
int tZ = this.zCoord + fd.offsetZ;
|
||||
TileEntity tile = this.worldObj.getTileEntity(tX, tY, tZ);
|
||||
|
||||
if (tile != null && tile instanceof IFluidHandler)
|
||||
map.put(fd, tile);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill (ForgeDirection from, FluidStack resource, boolean doFill)
|
||||
{
|
||||
if (doFill)
|
||||
{
|
||||
this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
this.lastProvider = from;
|
||||
if (this.internalTank.getFluid() == null)
|
||||
this.recentlyFilledDelay = 2;
|
||||
}
|
||||
|
||||
if (from == ForgeDirection.UP)
|
||||
{
|
||||
return this.internalTank.fill(resource, doFill);
|
||||
}
|
||||
else if (from == ForgeDirection.NORTH || from == ForgeDirection.SOUTH || from == ForgeDirection.WEST || from == ForgeDirection.EAST)
|
||||
{
|
||||
return this.subTanks.get(from).fill(resource, doFill);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain (ForgeDirection from, FluidStack resource, boolean doDrain)
|
||||
{
|
||||
return drain(from, resource.amount, doDrain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain (ForgeDirection from, int maxDrain, boolean doDrain)
|
||||
{
|
||||
//if(doDrain)
|
||||
// this.worldObj.markBlockForRenderUpdate(xCoord, yCoord, zCoord);
|
||||
if (from == ForgeDirection.DOWN)
|
||||
return this.internalTank.drain(maxDrain, doDrain);
|
||||
else if (from == ForgeDirection.NORTH || from == ForgeDirection.SOUTH || from == ForgeDirection.WEST || from == ForgeDirection.EAST)
|
||||
{
|
||||
return this.subTanks.get(from).drain(maxDrain, doDrain);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFill (ForgeDirection from, Fluid fluid)
|
||||
{
|
||||
if (from == ForgeDirection.DOWN)
|
||||
return false;
|
||||
if (from == ForgeDirection.UP)
|
||||
return true;
|
||||
return validOutputs.contains(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDrain (ForgeDirection from, Fluid fluid)
|
||||
{
|
||||
if (from == ForgeDirection.UP)
|
||||
return false;
|
||||
return validOutputs.contains(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo[] getTankInfo (ForgeDirection from)
|
||||
{
|
||||
if (from == null || from == ForgeDirection.UP || from == ForgeDirection.DOWN || from == ForgeDirection.UNKNOWN)
|
||||
return new FluidTankInfo[] { new FluidTankInfo(internalTank) };
|
||||
else
|
||||
return new FluidTankInfo[] { new FluidTankInfo(subTanks.get(from)) };
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT (NBTTagCompound tags)
|
||||
{
|
||||
super.readFromNBT(tags);
|
||||
readCustomNBT(tags);
|
||||
}
|
||||
|
||||
public void readCustomNBT (NBTTagCompound tags)
|
||||
{
|
||||
|
||||
NBTTagCompound nbtTank = tags.getCompoundTag("internalTank");
|
||||
if (nbtTank != null)
|
||||
internalTank.readFromNBT(nbtTank);
|
||||
|
||||
for (ForgeDirection fdSub : subTanks.keySet())
|
||||
{
|
||||
NBTTagCompound nbtSubTank = tags.getCompoundTag("subTank_" + fdSub.name());
|
||||
if (nbtSubTank != null)
|
||||
subTanks.get(fdSub).readFromNBT(nbtSubTank);
|
||||
}
|
||||
|
||||
int[] validFDs = tags.getIntArray("validOutputs");
|
||||
if (validFDs != null)
|
||||
{
|
||||
validOutputs = new ArrayList();
|
||||
for (int i : validFDs)
|
||||
validOutputs.add(convertIntToFD(i));
|
||||
}
|
||||
/* UNUSED
|
||||
this.mode = CastingChannelMode.readFromNBT(tags);
|
||||
*/
|
||||
this.lastProvider = this.convertIntToFD(tags.getInteger("LastProvider"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT (NBTTagCompound tags)
|
||||
{
|
||||
super.writeToNBT(tags);
|
||||
writeCustomNBT(tags);
|
||||
}
|
||||
|
||||
public void writeCustomNBT (NBTTagCompound tags)
|
||||
{
|
||||
NBTTagCompound nbtTank = new NBTTagCompound();
|
||||
internalTank.writeToNBT(nbtTank);
|
||||
tags.setTag("internalTank", nbtTank);
|
||||
for (ForgeDirection fdSub : subTanks.keySet())
|
||||
{
|
||||
NBTTagCompound nbtSubTank = new NBTTagCompound();
|
||||
subTanks.get(fdSub).writeToNBT(nbtSubTank);
|
||||
tags.setTag("subTank_" + fdSub.name(), nbtSubTank);
|
||||
}
|
||||
|
||||
int[] validFDs = new int[validOutputs.size()];
|
||||
int it = 0;
|
||||
for (ForgeDirection fd : validOutputs)
|
||||
{
|
||||
if (fd != null)
|
||||
validFDs[it] = convertFDToInt(fd);
|
||||
it++;
|
||||
}
|
||||
tags.setIntArray("validOutputs", validFDs);
|
||||
/* UNUSED
|
||||
CastingChannelMode.writeToNBT(tags, this.mode);
|
||||
*/
|
||||
tags.setInteger("LastProvider", this.convertFDToInt(this.lastProvider));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket ()
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
writeCustomNBT(tag);
|
||||
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket (NetworkManager net, S35PacketUpdateTileEntity packet)
|
||||
{
|
||||
readCustomNBT(packet.func_148857_g());
|
||||
this.worldObj.func_147479_m(this.xCoord, this.yCoord, this.zCoord);
|
||||
}
|
||||
|
||||
public int convertFDToInt (ForgeDirection dir)
|
||||
{
|
||||
switch (dir)
|
||||
{
|
||||
case DOWN:
|
||||
return 0;
|
||||
case UP:
|
||||
return 1;
|
||||
case NORTH:
|
||||
return 2;
|
||||
case SOUTH:
|
||||
return 3;
|
||||
case WEST:
|
||||
return 4;
|
||||
case EAST:
|
||||
return 5;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public ForgeDirection convertIntToFD (int i)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
return ForgeDirection.DOWN;
|
||||
case 1:
|
||||
return ForgeDirection.UP;
|
||||
case 2:
|
||||
return ForgeDirection.NORTH;
|
||||
case 3:
|
||||
return ForgeDirection.SOUTH;
|
||||
case 4:
|
||||
return ForgeDirection.WEST;
|
||||
case 5:
|
||||
return ForgeDirection.EAST;
|
||||
default:
|
||||
return ForgeDirection.UNKNOWN;
|
||||
}
|
||||
}
|
||||
/* UNUSED
|
||||
public enum CastingChannelMode
|
||||
{
|
||||
//Will not output while being filled by Faucet, hence only taking one ingots worth from the Smeltery
|
||||
SINGLEDRAIN,
|
||||
//Will keep the Faucet above it open
|
||||
CONTINUEDRAIN;
|
||||
|
||||
public static void writeToNBT(NBTTagCompound tag, CastingChannelMode mode)
|
||||
{
|
||||
if(mode == SINGLEDRAIN)
|
||||
tag.setString("CastingChannelMode","single");
|
||||
else
|
||||
tag.setString("CastingChannelMode","continue");
|
||||
}
|
||||
public static CastingChannelMode readFromNBT(NBTTagCompound tag)
|
||||
{
|
||||
return (!tag.hasKey("CastingChannelMode") || tag.getString("CastingChannelMode")=="single") ? SINGLEDRAIN : CONTINUEDRAIN ;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -1,454 +0,0 @@
|
||||
package tconstruct.blocks.logic;
|
||||
|
||||
import mantle.blocks.abstracts.InventoryLogic;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidEvent;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
import net.minecraftforge.fluids.IFluidTank;
|
||||
import tconstruct.TConstruct;
|
||||
import tconstruct.library.crafting.CastingRecipe;
|
||||
import tconstruct.library.util.IPattern;
|
||||
|
||||
public class CastingTableLogic extends InventoryLogic implements IFluidTank, IFluidHandler, ISidedInventory
|
||||
{
|
||||
public FluidStack liquid;
|
||||
int castingDelay = 0;
|
||||
int renderOffset = 0;
|
||||
int capacity = 0;
|
||||
boolean needsUpdate;
|
||||
boolean init = true;
|
||||
int tick;
|
||||
|
||||
public CastingTableLogic()
|
||||
{
|
||||
super(2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit ()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInvName () // Not a gui block
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultName () // Still not a gui block
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Container getGuiContainer (InventoryPlayer inventoryplayer, World world, int x, int y, int z) // Definitely not a gui block
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/* Tank */
|
||||
|
||||
@Override
|
||||
public int getCapacity ()
|
||||
{
|
||||
return this.capacity;
|
||||
}
|
||||
|
||||
public int updateCapacity () // Only used to initialize
|
||||
{
|
||||
ItemStack inv = inventory[0];
|
||||
int ret = TConstruct.ingotLiquidValue;
|
||||
int rec = TConstruct.tableCasting.getCastingAmount(this.liquid, inv);
|
||||
|
||||
if (rec > 0)
|
||||
ret = rec;
|
||||
else {
|
||||
if (inv != null && inv.getItem() instanceof IPattern)
|
||||
{
|
||||
int cost = ((IPattern) inv.getItem()).getPatternCost(inv);
|
||||
if (cost > 0)
|
||||
ret *= ((IPattern) inv.getItem()).getPatternCost(inv) * 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
TConstruct.logger.info("Ret: " + ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int updateCapacity (int capacity)
|
||||
{
|
||||
int ret = TConstruct.ingotLiquidValue;
|
||||
|
||||
if (capacity > 0)
|
||||
ret = capacity;
|
||||
else {
|
||||
ItemStack inv = inventory[0];
|
||||
|
||||
if (inv != null && inv.getItem() instanceof IPattern)
|
||||
{
|
||||
int cost = ((IPattern) inv.getItem()).getPatternCost(inv);
|
||||
if (cost > 0)
|
||||
ret *= cost * 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill (FluidStack resource, boolean doFill)
|
||||
{
|
||||
if (resource == null)
|
||||
return 0;
|
||||
|
||||
if (this.liquid == null)
|
||||
{
|
||||
CastingRecipe recipe = TConstruct.tableCasting.getCastingRecipe(resource, inventory[0]);
|
||||
if (recipe == null)
|
||||
return 0;
|
||||
this.capacity = updateCapacity(recipe.castingMetal.amount);
|
||||
|
||||
if (inventory[1] == null)
|
||||
{
|
||||
FluidStack copyLiquid = resource.copy();
|
||||
|
||||
if (copyLiquid.amount > this.capacity)
|
||||
{
|
||||
copyLiquid.amount = this.capacity;
|
||||
}
|
||||
|
||||
if (doFill)
|
||||
{
|
||||
if (copyLiquid.amount == this.capacity)
|
||||
{
|
||||
castingDelay = recipe.coolTime;
|
||||
}
|
||||
renderOffset = copyLiquid.amount;
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
this.liquid = copyLiquid;
|
||||
needsUpdate = true;
|
||||
}
|
||||
return copyLiquid.amount;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
else if (resource.isFluidEqual(this.liquid))
|
||||
{
|
||||
if (resource.amount + this.liquid.amount >= this.capacity) // Start
|
||||
// timer
|
||||
// here
|
||||
{
|
||||
int roomInTank = this.capacity - liquid.amount;
|
||||
if (doFill && roomInTank > 0)
|
||||
{
|
||||
renderOffset = roomInTank;
|
||||
castingDelay = TConstruct.tableCasting.getCastingDelay(this.liquid, inventory[0]);
|
||||
this.liquid.amount = this.capacity;
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
needsUpdate = true;
|
||||
}
|
||||
return roomInTank;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (doFill)
|
||||
{
|
||||
this.liquid.amount += resource.amount;
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
needsUpdate = true;
|
||||
}
|
||||
return resource.amount;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty () // Isn't actually called?
|
||||
{
|
||||
super.markDirty();
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
needsUpdate = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize (int slot, int quantity)
|
||||
{
|
||||
ItemStack stack = super.decrStackSize(slot, quantity);
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain (int maxDrain, boolean doDrain)
|
||||
{
|
||||
if (liquid == null || liquid.fluidID <= 0 || castingDelay > 0)
|
||||
return null;
|
||||
if (liquid.amount <= 0)
|
||||
return null;
|
||||
|
||||
int used = maxDrain;
|
||||
if (liquid.amount < used)
|
||||
used = liquid.amount;
|
||||
|
||||
if (doDrain)
|
||||
{
|
||||
liquid.amount -= used;
|
||||
}
|
||||
|
||||
FluidStack drained = liquid.copy();// new FluidStack(liquid.itemID,
|
||||
// used, liquid.itemMeta);
|
||||
drained.amount = used;
|
||||
|
||||
// Reset liquid if emptied
|
||||
if (liquid.amount <= 0)
|
||||
liquid = null;
|
||||
|
||||
if (doDrain)
|
||||
FluidEvent.fireEvent(new FluidEvent.FluidDrainingEvent(drained, this.worldObj, this.xCoord, this.yCoord, this.zCoord, this));
|
||||
|
||||
return drained;
|
||||
}
|
||||
|
||||
/* Tank Container */
|
||||
|
||||
@Override
|
||||
public int fill (ForgeDirection from, FluidStack resource, boolean doFill)
|
||||
{
|
||||
// if (from == ForgeDirection.UP)
|
||||
return fill(resource, doFill);
|
||||
// return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain (ForgeDirection from, int maxDrain, boolean doDrain)
|
||||
{
|
||||
return drain(maxDrain, doDrain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain (ForgeDirection from, FluidStack resource, boolean doDrain)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFill (ForgeDirection from, Fluid fluid)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDrain (ForgeDirection from, Fluid fluid)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo[] getTankInfo (ForgeDirection from)
|
||||
{
|
||||
return new FluidTankInfo[] { getInfo() };
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack getFluid ()
|
||||
{
|
||||
return liquid == null ? null : liquid.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFluidAmount ()
|
||||
{
|
||||
return liquid != null ? liquid.amount : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo getInfo ()
|
||||
{
|
||||
FluidTankInfo info = new FluidTankInfo(this);
|
||||
return info;
|
||||
}
|
||||
|
||||
public int getLiquidAmount ()
|
||||
{
|
||||
return liquid.amount - renderOffset;
|
||||
}
|
||||
|
||||
/* Updating */
|
||||
@Override
|
||||
public void updateEntity ()
|
||||
{
|
||||
if (castingDelay > 0)
|
||||
{
|
||||
// TConstruct.logger.info("Casting");
|
||||
castingDelay--;
|
||||
if (castingDelay == 0)
|
||||
castLiquid();
|
||||
}
|
||||
if (renderOffset > 0)
|
||||
{
|
||||
renderOffset -= 6;
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
tick++;
|
||||
if (tick % 20 == 0)
|
||||
{
|
||||
tick = 0;
|
||||
if (needsUpdate)
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
}
|
||||
}
|
||||
|
||||
public void castLiquid ()
|
||||
{
|
||||
CastingRecipe recipe = TConstruct.tableCasting.getCastingRecipe(liquid, inventory[0]);
|
||||
if (recipe != null)
|
||||
{
|
||||
inventory[1] = recipe.getResult();
|
||||
if (recipe.consumeCast)
|
||||
inventory[0] = null;
|
||||
liquid = null;
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
}
|
||||
}
|
||||
|
||||
/* NBT */
|
||||
|
||||
@Override
|
||||
public void readFromNBT (NBTTagCompound tags)
|
||||
{
|
||||
super.readFromNBT(tags);
|
||||
readCustomNBT(tags);
|
||||
}
|
||||
|
||||
public void readCustomNBT (NBTTagCompound tags)
|
||||
{
|
||||
if (tags.getBoolean("hasLiquid"))
|
||||
{
|
||||
this.liquid = FluidStack.loadFluidStackFromNBT(tags.getCompoundTag("Fluid"));
|
||||
}
|
||||
else
|
||||
this.liquid = null;
|
||||
|
||||
if (tags.getBoolean("Initialized"))
|
||||
this.capacity = tags.getInteger("Capacity");
|
||||
else
|
||||
this.capacity = updateCapacity();
|
||||
this.castingDelay = tags.getInteger("castingDelay");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT (NBTTagCompound tags)
|
||||
{
|
||||
super.writeToNBT(tags);
|
||||
writeCustomNBT(tags);
|
||||
}
|
||||
|
||||
public void writeCustomNBT (NBTTagCompound tags)
|
||||
{
|
||||
tags.setBoolean("hasLiquid", liquid != null);
|
||||
if (liquid != null)
|
||||
{
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
liquid.writeToNBT(nbt);
|
||||
tags.setTag("Fluid", nbt);
|
||||
}
|
||||
tags.setBoolean("Initialized", init);
|
||||
tags.setInteger("Capacity", capacity);
|
||||
tags.setInteger("castingDelay", castingDelay);
|
||||
}
|
||||
|
||||
/* Packets */
|
||||
@Override
|
||||
public Packet getDescriptionPacket ()
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
writeToNBT(tag);
|
||||
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket (NetworkManager net, S35PacketUpdateTileEntity packet)
|
||||
{
|
||||
readFromNBT(packet.func_148857_g());
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide (int side)
|
||||
{
|
||||
return new int[] { 0, 1 };
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem (int slot, ItemStack itemstack, int side)
|
||||
{
|
||||
if (liquid != null)
|
||||
return false;
|
||||
|
||||
if (slot == 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem (int slot, ItemStack itemstack, int side)
|
||||
{
|
||||
if (slot == 1)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName ()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory ()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory ()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,155 +0,0 @@
|
||||
package tconstruct.blocks.logic;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import mantle.blocks.abstracts.InventoryLogic;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityChest;
|
||||
import net.minecraft.tileentity.TileEntityFurnace;
|
||||
import net.minecraft.world.World;
|
||||
import tconstruct.inventory.CraftingStationContainer;
|
||||
|
||||
public class CraftingStationLogic extends InventoryLogic implements ISidedInventory
|
||||
{
|
||||
public WeakReference<IInventory> chest; // TODO: These are prototypes
|
||||
public WeakReference<IInventory> doubleChest;
|
||||
public WeakReference<IInventory> patternChest;
|
||||
public WeakReference<IInventory> furnace;
|
||||
public boolean tinkerTable;
|
||||
public boolean stencilTable;
|
||||
public boolean doubleFirst;
|
||||
|
||||
public CraftingStationLogic()
|
||||
{
|
||||
super(17); // 9 for crafting, 1 for output, 6 for extensions, 1 for
|
||||
// plans
|
||||
}
|
||||
|
||||
@Override
|
||||
public Container getGuiContainer (InventoryPlayer inventoryplayer, World world, int x, int y, int z)
|
||||
{
|
||||
chest = null;
|
||||
doubleChest = null;
|
||||
patternChest = null;
|
||||
furnace = null;
|
||||
tinkerTable = false;
|
||||
int[] ys = {y, y - 1, y + 1};
|
||||
for (byte iy = 0; iy < 3; iy++)
|
||||
{
|
||||
int yPos = ys[iy];
|
||||
for (int xPos = x - 1; xPos <= x + 1; xPos++)
|
||||
{
|
||||
for (int zPos = z - 1; zPos <= z + 1; zPos++)
|
||||
{
|
||||
TileEntity tile = world.getTileEntity(xPos, yPos, zPos);
|
||||
if (chest == null && tile instanceof TileEntityChest)
|
||||
{
|
||||
chest = new WeakReference(tile);
|
||||
checkForChest(world, xPos, yPos, zPos, 1, 0);
|
||||
checkForChest(world, xPos, yPos, zPos, -1, 0);
|
||||
checkForChest(world, xPos, yPos, zPos, 0, 1);
|
||||
checkForChest(world, xPos, yPos, zPos, 0, -1);
|
||||
}
|
||||
else if (patternChest == null && tile instanceof PatternChestLogic)
|
||||
patternChest = new WeakReference(tile);
|
||||
else if (furnace == null && (tile instanceof TileEntityFurnace || tile instanceof FurnaceLogic))
|
||||
furnace = new WeakReference(tile);
|
||||
else if (tinkerTable == false && tile instanceof ToolStationLogic)
|
||||
tinkerTable = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new CraftingStationContainer(inventoryplayer, this, x, y, z);
|
||||
}
|
||||
|
||||
void checkForChest (World world, int x, int y, int z, int dx, int dz)
|
||||
{
|
||||
TileEntity tile = world.getTileEntity(x + dx, y, z + dz);
|
||||
if (tile instanceof TileEntityChest)
|
||||
{
|
||||
doubleChest = new WeakReference(tile);
|
||||
doubleFirst = dx + dz < 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultName ()
|
||||
{
|
||||
return "crafters.CraftingStation";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDropInventorySlot (int slot)
|
||||
{
|
||||
if (slot == 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide (int var1)
|
||||
{
|
||||
return new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem (int i, ItemStack itemstack, int j)
|
||||
{
|
||||
return i != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize (int slot, int quantity)
|
||||
{
|
||||
if (slot == 0)
|
||||
{
|
||||
for (int i = 1; i < getSizeInventory(); i++)
|
||||
decrStackSize(i, 1);
|
||||
}
|
||||
return super.decrStackSize(slot, quantity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem (int i, ItemStack itemstack, int j)
|
||||
{
|
||||
return i == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName ()
|
||||
{
|
||||
return getDefaultName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory ()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory ()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUpdate ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
package tconstruct.blocks.logic;
|
||||
|
||||
import mantle.blocks.abstracts.InventoryLogic;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/* Slots
|
||||
* 0: Frying pan item
|
||||
* 1: Fuel
|
||||
* 2-9: Food
|
||||
*/
|
||||
|
||||
public abstract class EquipLogic extends InventoryLogic
|
||||
{
|
||||
|
||||
public EquipLogic(int invSize)
|
||||
{
|
||||
super(invSize);
|
||||
}
|
||||
|
||||
public void setEquipmentItem (ItemStack stack)
|
||||
{
|
||||
inventory[0] = stack.copy();
|
||||
}
|
||||
|
||||
public boolean hasEquipmentItem ()
|
||||
{
|
||||
return inventory[0] != null;
|
||||
}
|
||||
|
||||
public ItemStack getEquipmentItem ()
|
||||
{
|
||||
return inventory[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents (int slot, ItemStack stack)
|
||||
{
|
||||
if (slot == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
super.setInventorySlotContents(slot, stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot (int slot)
|
||||
{
|
||||
return slot != 0 ? inventory[slot] : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStackInSlot (int slot)
|
||||
{
|
||||
return slot != 0 ? inventory[slot] != null : false;
|
||||
}
|
||||
}
|
||||
@@ -1,254 +0,0 @@
|
||||
package tconstruct.blocks.logic;
|
||||
|
||||
import tconstruct.TConstruct;
|
||||
import mantle.blocks.iface.IActiveLogic;
|
||||
import mantle.blocks.iface.IFacingLogic;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
|
||||
public class FaucetLogic extends TileEntity implements IFacingLogic, IActiveLogic, IFluidHandler
|
||||
{
|
||||
byte direction;
|
||||
boolean active;
|
||||
public FluidStack liquid;
|
||||
|
||||
public boolean activateFaucet ()
|
||||
{
|
||||
if (liquid == null && active)
|
||||
{
|
||||
int x = xCoord, z = zCoord;
|
||||
switch (getRenderDirection())
|
||||
{
|
||||
case 2:
|
||||
z++;
|
||||
break;
|
||||
case 3:
|
||||
z--;
|
||||
break;
|
||||
case 4:
|
||||
x++;
|
||||
break;
|
||||
case 5:
|
||||
x--;
|
||||
break;
|
||||
}
|
||||
|
||||
TileEntity drainte = worldObj.getTileEntity(x, yCoord, z);
|
||||
TileEntity tankte = worldObj.getTileEntity(xCoord, yCoord - 1, zCoord);
|
||||
|
||||
if (drainte != null && drainte instanceof IFluidHandler && tankte != null && tankte instanceof IFluidHandler)
|
||||
{
|
||||
FluidStack templiquid = ((IFluidHandler) drainte).drain(getForgeDirection(), TConstruct.ingotLiquidValue, false);
|
||||
if (templiquid != null)
|
||||
{
|
||||
int drained = ((IFluidHandler) tankte).fill(ForgeDirection.UP, templiquid, false);
|
||||
if (drained > 0)
|
||||
{
|
||||
liquid = ((IFluidHandler) drainte).drain(getForgeDirection(), drained, true);
|
||||
((IFluidHandler) tankte).fill(ForgeDirection.UP, liquid, true);
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity ()
|
||||
{
|
||||
if (liquid != null)
|
||||
{
|
||||
liquid.amount -= TConstruct.liquidUpdateAmount;
|
||||
if (liquid.amount <= 0)
|
||||
{
|
||||
liquid = null;
|
||||
if (!activateFaucet())
|
||||
{
|
||||
active = false;
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getRenderDirection ()
|
||||
{
|
||||
return direction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForgeDirection getForgeDirection ()
|
||||
{
|
||||
return ForgeDirection.VALID_DIRECTIONS[direction];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDirection (int side)
|
||||
{
|
||||
if (side != 0 && side != 1)
|
||||
{
|
||||
direction = (byte) side;
|
||||
}
|
||||
else
|
||||
{
|
||||
direction = 2;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDirection (float yaw, float pitch, EntityLivingBase player)
|
||||
{
|
||||
/*int facing = MathHelper.floor_double((double) (yaw / 360) + 0.5D) & 3;
|
||||
switch (facing)
|
||||
{
|
||||
case 0:
|
||||
direction = 2;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
direction = 5;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
direction = 3;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
direction = 4;
|
||||
break;
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT (NBTTagCompound tags)
|
||||
{
|
||||
super.readFromNBT(tags);
|
||||
readCustomNBT(tags);
|
||||
}
|
||||
|
||||
public void readCustomNBT (NBTTagCompound tags)
|
||||
{
|
||||
direction = tags.getByte("Direction");
|
||||
if (tags.getBoolean("hasLiquid"))
|
||||
{
|
||||
this.liquid = FluidStack.loadFluidStackFromNBT(tags.getCompoundTag("Fluid"));
|
||||
}
|
||||
else
|
||||
this.liquid = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT (NBTTagCompound tags)
|
||||
{
|
||||
super.writeToNBT(tags);
|
||||
writeCustomNBT(tags);
|
||||
}
|
||||
|
||||
public void writeCustomNBT (NBTTagCompound tags)
|
||||
{
|
||||
tags.setByte("Direction", direction);
|
||||
tags.setBoolean("hasLiquid", liquid != null);
|
||||
if (liquid != null)
|
||||
{
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
liquid.writeToNBT(nbt);
|
||||
tags.setTag("Fluid", nbt);
|
||||
}
|
||||
}
|
||||
|
||||
/* Packets */
|
||||
@Override
|
||||
public Packet getDescriptionPacket ()
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
writeCustomNBT(tag);
|
||||
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket (NetworkManager net, S35PacketUpdateTileEntity packet)
|
||||
{
|
||||
readCustomNBT(packet.func_148857_g());
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getActive ()
|
||||
{
|
||||
return active;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActive (boolean flag)
|
||||
{
|
||||
if (!active)
|
||||
{
|
||||
active = true;
|
||||
activateFaucet();
|
||||
}
|
||||
else
|
||||
{
|
||||
active = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill (ForgeDirection from, FluidStack resource, boolean doFill)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain (ForgeDirection from, FluidStack resource, boolean doDrain)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain (ForgeDirection from, int maxDrain, boolean doDrain)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFill (ForgeDirection from, Fluid fluid)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDrain (ForgeDirection from, Fluid fluid)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo[] getTankInfo (ForgeDirection from)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,324 +0,0 @@
|
||||
package tconstruct.blocks.logic;
|
||||
|
||||
import tconstruct.inventory.FrypanContainer;
|
||||
import mantle.blocks.BlockUtils;
|
||||
import mantle.blocks.iface.IActiveLogic;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemFood;
|
||||
import net.minecraft.item.ItemHoe;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemSword;
|
||||
import net.minecraft.item.ItemTool;
|
||||
import net.minecraft.item.crafting.FurnaceRecipes;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
/* Slots
|
||||
* 0: Frying pan item
|
||||
* 1: Fuel
|
||||
* 2-9: Food
|
||||
*/
|
||||
|
||||
public class FrypanLogic extends EquipLogic implements IActiveLogic
|
||||
{
|
||||
boolean active;
|
||||
public int fuel;
|
||||
public int fuelGague;
|
||||
public int progress;
|
||||
|
||||
public FrypanLogic()
|
||||
{
|
||||
super(10);
|
||||
active = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultName ()
|
||||
{
|
||||
return "crafters.frypan";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getActive ()
|
||||
{
|
||||
return active;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActive (boolean flag)
|
||||
{
|
||||
active = flag;
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
/* Fuel gauge */
|
||||
public int gaugeProgressScaled (int scale)
|
||||
{
|
||||
return (progress * scale) / 1000;
|
||||
}
|
||||
|
||||
public int gaugeFuelScaled (int scale)
|
||||
{
|
||||
if (fuelGague == 0)
|
||||
{
|
||||
fuelGague = fuel;
|
||||
if (fuelGague == 0)
|
||||
{
|
||||
fuelGague = 1000;
|
||||
}
|
||||
}
|
||||
return (fuel * scale) / fuelGague;
|
||||
}
|
||||
|
||||
/* Item cooking */
|
||||
@Override
|
||||
public void updateEntity ()
|
||||
{
|
||||
boolean burning = isBurning();
|
||||
boolean updateInventory = false;
|
||||
if (fuel <= 0 && canCook())
|
||||
{
|
||||
fuel = fuelGague = (int) (getItemBurnTime(inventory[1]) * 2.5);
|
||||
if (fuel > 0)
|
||||
{
|
||||
if (inventory[1].getItem().hasContainerItem()) //Fuel slot
|
||||
{
|
||||
inventory[1] = new ItemStack(inventory[1].getItem().getContainerItem());
|
||||
}
|
||||
else
|
||||
{
|
||||
inventory[1].stackSize--;
|
||||
}
|
||||
if (inventory[1].stackSize <= 0)
|
||||
{
|
||||
inventory[1] = null;
|
||||
}
|
||||
updateInventory = true;
|
||||
}
|
||||
}
|
||||
if (isBurning() && canCook())
|
||||
{
|
||||
progress++;
|
||||
if (progress >= 1000)
|
||||
{
|
||||
progress = 0;
|
||||
cookItems();
|
||||
updateInventory = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
progress = 0;
|
||||
}
|
||||
if (fuel > 0)
|
||||
{
|
||||
fuel--;
|
||||
}
|
||||
if (burning != isBurning())
|
||||
{
|
||||
setActive(isBurning());
|
||||
updateInventory = true;
|
||||
}
|
||||
if (updateInventory)
|
||||
{
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
public void cookItems ()
|
||||
{
|
||||
if (!canCook())
|
||||
return;
|
||||
|
||||
for (int id = 2; id < 10; id++) //Check every slot
|
||||
{
|
||||
if (canCook())
|
||||
{
|
||||
ItemStack result = getResultFor(inventory[id]);
|
||||
if (result != null)
|
||||
{
|
||||
int ids = 2;
|
||||
boolean placed = false;
|
||||
while (ids < 10 && !placed) //Try to merge stacks first
|
||||
{
|
||||
if (inventory[ids] != null && inventory[ids].isItemEqual(result) && inventory[ids].stackSize < inventory[ids].getMaxStackSize())
|
||||
{
|
||||
if (inventory[ids].stackSize + result.stackSize <= inventory[ids].getMaxStackSize())
|
||||
{
|
||||
inventory[ids].stackSize += result.stackSize;
|
||||
placed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
int decrement = inventory[ids].getMaxStackSize() - inventory[ids].stackSize;
|
||||
inventory[ids].stackSize = inventory[ids].getMaxStackSize();
|
||||
result.stackSize -= decrement;
|
||||
}
|
||||
}
|
||||
ids++;
|
||||
}
|
||||
|
||||
ids = 2;
|
||||
while (!placed && ids < 10) //Place remaining in slot
|
||||
{
|
||||
if (inventory[ids] == null)
|
||||
{
|
||||
inventory[ids] = result;
|
||||
placed = true;
|
||||
}
|
||||
ids++;
|
||||
}
|
||||
|
||||
if (placed)
|
||||
decrStackSize(id, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canCook ()
|
||||
{
|
||||
for (int id = 2; id < 10; id++)
|
||||
{
|
||||
if (inventory[id] == null) //Nothing here!
|
||||
continue;
|
||||
|
||||
ItemStack result = getResultFor(inventory[id]);
|
||||
if (result == null) //Doesn't cook into anything
|
||||
continue;
|
||||
|
||||
for (int slotid = 2; slotid < 10; slotid++)
|
||||
{
|
||||
if (inventory[slotid] == null)
|
||||
return true;
|
||||
|
||||
else if (inventory[slotid].isItemEqual(result) && inventory[slotid].stackSize + result.stackSize <= inventory[slotid].getMaxStackSize())
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isBurning ()
|
||||
{
|
||||
return fuel > 0;
|
||||
}
|
||||
|
||||
public ItemStack getResultFor (ItemStack stack)
|
||||
{
|
||||
if (stack == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemStack result = FurnaceRecipes.smelting().getSmeltingResult(stack);
|
||||
if (result != null && result.getItem() instanceof ItemFood) //Only valid for food
|
||||
return result.copy();
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static int getItemBurnTime (ItemStack stack)
|
||||
{
|
||||
if (stack == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
Item item = stack.getItem();
|
||||
|
||||
if (stack.getItem() instanceof ItemBlock && BlockUtils.getBlockFromItem(item) != null)
|
||||
{
|
||||
Block block = BlockUtils.getBlockFromItem(item);
|
||||
|
||||
if (block == Blocks.wooden_slab)
|
||||
{
|
||||
return 150;
|
||||
}
|
||||
|
||||
if (block == Blocks.log)
|
||||
{
|
||||
return 2400;
|
||||
}
|
||||
|
||||
if (block.getMaterial() == Material.wood)
|
||||
{
|
||||
return 300;
|
||||
}
|
||||
}
|
||||
if (item instanceof ItemTool && ((ItemTool) item).getToolMaterialName().equals("WOOD"))
|
||||
return 200;
|
||||
if (item instanceof ItemSword && ((ItemSword) item).getToolMaterialName().equals("WOOD"))
|
||||
return 200;
|
||||
if (item instanceof ItemHoe && ((ItemHoe) item).getToolMaterialName().equals("WOOD"))
|
||||
return 200;
|
||||
if (item == Items.stick)
|
||||
return 100;
|
||||
if (item == Items.coal)
|
||||
return 800;
|
||||
if (item == Items.lava_bucket)
|
||||
return 20000;
|
||||
if (new ItemStack(item).equals(new ItemStack(Blocks.sapling)))
|
||||
return 100;
|
||||
if (item == Items.blaze_rod)
|
||||
return 2400;
|
||||
return GameRegistry.getFuelValue(stack);
|
||||
}
|
||||
}
|
||||
|
||||
/* NBT */
|
||||
public void readFromNBT (NBTTagCompound tags)
|
||||
{
|
||||
super.readFromNBT(tags);
|
||||
active = tags.getBoolean("Active");
|
||||
fuel = tags.getInteger("Fuel");
|
||||
fuelGague = tags.getInteger("FuelGague");
|
||||
}
|
||||
|
||||
public void writeToNBT (NBTTagCompound tags)
|
||||
{
|
||||
super.writeToNBT(tags);
|
||||
tags.setBoolean("Active", active);
|
||||
tags.setInteger("Fuel", fuel);
|
||||
tags.setInteger("FuelGague", fuelGague);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Container getGuiContainer (InventoryPlayer inventoryplayer, World world, int x, int y, int z)
|
||||
{
|
||||
return new FrypanContainer(inventoryplayer.player, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName ()
|
||||
{
|
||||
return getDefaultName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory ()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory ()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,376 +0,0 @@
|
||||
package tconstruct.blocks.logic;
|
||||
|
||||
import mantle.blocks.BlockUtils;
|
||||
import mantle.blocks.abstracts.InventoryLogic;
|
||||
import mantle.blocks.iface.IActiveLogic;
|
||||
import mantle.blocks.iface.IFacingLogic;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemHoe;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemSword;
|
||||
import net.minecraft.item.ItemTool;
|
||||
import net.minecraft.item.crafting.FurnaceRecipes;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import tconstruct.inventory.FurnaceContainer;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
/* Slots
|
||||
* 0: Input
|
||||
* 1: Fuel
|
||||
* 2: Output
|
||||
* 3-16: Chest
|
||||
*/
|
||||
|
||||
public class FurnaceLogic extends InventoryLogic implements IActiveLogic, IFacingLogic
|
||||
{
|
||||
boolean active;
|
||||
public int fuel;
|
||||
public int fuelGague;
|
||||
public int progress;
|
||||
public int fuelScale = 200;
|
||||
byte direction;
|
||||
|
||||
public FurnaceLogic()
|
||||
{
|
||||
super(3);
|
||||
active = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultName ()
|
||||
{
|
||||
return "container.furnace";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getActive ()
|
||||
{
|
||||
return active;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActive (boolean flag)
|
||||
{
|
||||
active = flag;
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
/* Fuel gauge */
|
||||
public int gaugeProgressScaled (int scale)
|
||||
{
|
||||
return (progress * scale) / fuelScale;
|
||||
}
|
||||
|
||||
public int gaugeFuelScaled (int scale)
|
||||
{
|
||||
if (fuelGague == 0)
|
||||
{
|
||||
fuelGague = fuel;
|
||||
if (fuelGague == 0)
|
||||
{
|
||||
fuelGague = fuelScale;
|
||||
}
|
||||
}
|
||||
return (fuel * scale) / fuelGague;
|
||||
}
|
||||
|
||||
/* Item cooking */
|
||||
@Override
|
||||
public void updateEntity ()
|
||||
{
|
||||
boolean burning = isBurning();
|
||||
boolean updateInventory = false;
|
||||
if (fuel <= 0 && canSmelt())
|
||||
{
|
||||
fuel = fuelGague = (int) (getItemBurnTime(inventory[1]));
|
||||
if (fuel > 0)
|
||||
{
|
||||
if (inventory[1].getItem().hasContainerItem()) // Fuel slot
|
||||
{
|
||||
inventory[1] = new ItemStack(inventory[1].getItem().getContainerItem());
|
||||
}
|
||||
else
|
||||
{
|
||||
inventory[1].stackSize--;
|
||||
}
|
||||
if (inventory[1].stackSize <= 0)
|
||||
{
|
||||
inventory[1] = null;
|
||||
}
|
||||
updateInventory = true;
|
||||
}
|
||||
}
|
||||
if (isBurning() && canSmelt())
|
||||
{
|
||||
progress++;
|
||||
if (progress >= fuelScale)
|
||||
{
|
||||
progress = 0;
|
||||
cookItems();
|
||||
updateInventory = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
progress = 0;
|
||||
}
|
||||
if (fuel > 0)
|
||||
{
|
||||
fuel--;
|
||||
}
|
||||
if (burning != isBurning())
|
||||
{
|
||||
setActive(isBurning());
|
||||
updateInventory = true;
|
||||
}
|
||||
if (updateInventory)
|
||||
{
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
public void cookItems ()
|
||||
{
|
||||
if (this.canSmelt())
|
||||
{
|
||||
ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.inventory[0]);
|
||||
|
||||
if (this.inventory[2] == null)
|
||||
{
|
||||
this.inventory[2] = itemstack.copy();
|
||||
}
|
||||
else if (this.inventory[2].isItemEqual(itemstack))
|
||||
{
|
||||
inventory[2].stackSize += itemstack.stackSize;
|
||||
}
|
||||
|
||||
--this.inventory[0].stackSize;
|
||||
|
||||
if (this.inventory[0].stackSize <= 0)
|
||||
{
|
||||
this.inventory[0] = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean canSmelt ()
|
||||
{
|
||||
if (inventory[0] == null) // Nothing here!
|
||||
return false;
|
||||
else
|
||||
{
|
||||
ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.inventory[0]);
|
||||
if (itemstack == null)
|
||||
return false;
|
||||
if (this.inventory[2] == null)
|
||||
return true;
|
||||
if (!this.inventory[2].isItemEqual(itemstack))
|
||||
return false;
|
||||
int result = inventory[2].stackSize + itemstack.stackSize;
|
||||
return (result <= getInventoryStackLimit() && result <= itemstack.getMaxStackSize());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isBurning ()
|
||||
{
|
||||
return fuel > 0;
|
||||
}
|
||||
|
||||
public ItemStack getResultFor (ItemStack stack)
|
||||
{
|
||||
ItemStack result = FurnaceRecipes.smelting().getSmeltingResult(stack);
|
||||
if (result != null) // Only valid for food
|
||||
return result.copy();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int getItemBurnTime (ItemStack stack)
|
||||
{
|
||||
if (stack == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
Item item = stack.getItem();
|
||||
|
||||
if (stack.getItem() instanceof ItemBlock && BlockUtils.getBlockFromItem(item) != null)
|
||||
{
|
||||
Block block = BlockUtils.getBlockFromItem(item);
|
||||
|
||||
if (block == Blocks.wooden_slab)
|
||||
{
|
||||
return 150;
|
||||
}
|
||||
|
||||
if (block == Blocks.log)
|
||||
{
|
||||
return 1200;
|
||||
}
|
||||
|
||||
if (block.getMaterial() == Material.wood)
|
||||
{
|
||||
return 300;
|
||||
}
|
||||
|
||||
if (block == Blocks.coal_block)
|
||||
{
|
||||
return 16000;
|
||||
}
|
||||
}
|
||||
|
||||
if (item instanceof ItemTool && ((ItemTool) item).getToolMaterialName().equals("WOOD"))
|
||||
return 200;
|
||||
if (item instanceof ItemSword && ((ItemSword) item).getToolMaterialName().equals("WOOD"))
|
||||
return 200;
|
||||
if (item instanceof ItemHoe && ((ItemHoe) item).getToolMaterialName().equals("WOOD"))
|
||||
return 200;
|
||||
if (item == Items.stick)
|
||||
return 100;
|
||||
if (item == Items.coal)
|
||||
return 1600;
|
||||
if (item == Items.lava_bucket)
|
||||
return 20000;
|
||||
if (item == new ItemStack(Blocks.sapling).getItem())
|
||||
return 100;
|
||||
if (item == Items.blaze_rod)
|
||||
return 2400;
|
||||
return GameRegistry.getFuelValue(stack);
|
||||
}
|
||||
}
|
||||
|
||||
/* NBT */
|
||||
@Override
|
||||
public void readFromNBT (NBTTagCompound tags)
|
||||
{
|
||||
super.readFromNBT(tags);
|
||||
active = tags.getBoolean("Active");
|
||||
fuel = tags.getInteger("Fuel");
|
||||
fuelGague = tags.getInteger("FuelGague");
|
||||
readNetworkNBT(tags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT (NBTTagCompound tags)
|
||||
{
|
||||
super.writeToNBT(tags);
|
||||
tags.setBoolean("Active", active);
|
||||
tags.setInteger("Fuel", fuel);
|
||||
tags.setInteger("FuelGague", fuelGague);
|
||||
writeNetworkNBT(tags);
|
||||
}
|
||||
|
||||
public void readNetworkNBT (NBTTagCompound tags)
|
||||
{
|
||||
direction = tags.getByte("Direction");
|
||||
}
|
||||
|
||||
public void writeNetworkNBT (NBTTagCompound tags)
|
||||
{
|
||||
tags.setByte("Direction", direction);
|
||||
}
|
||||
|
||||
/* Packets */
|
||||
@Override
|
||||
public Packet getDescriptionPacket ()
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
writeNetworkNBT(tag);
|
||||
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket (NetworkManager net, S35PacketUpdateTileEntity packet)
|
||||
{
|
||||
readNetworkNBT(packet.func_148857_g());
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Container getGuiContainer (InventoryPlayer inventoryplayer, World world, int x, int y, int z)
|
||||
{
|
||||
return new FurnaceContainer(inventoryplayer, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getRenderDirection ()
|
||||
{
|
||||
return direction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForgeDirection getForgeDirection ()
|
||||
{
|
||||
return ForgeDirection.VALID_DIRECTIONS[direction];
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void setDirection (int side)
|
||||
{
|
||||
// Nope!
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void setDirection (float yaw, float pitch, EntityLivingBase player)
|
||||
{
|
||||
int facing = MathHelper.floor_double((double) (yaw / 360) + 0.5D) & 3;
|
||||
switch (facing)
|
||||
{
|
||||
case 0:
|
||||
direction = 2;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
direction = 5;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
direction = 3;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
direction = 4;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName ()
|
||||
{
|
||||
return getDefaultName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory ()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory ()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,156 +0,0 @@
|
||||
package tconstruct.blocks.logic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import mantle.world.WorldHelper;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import tconstruct.util.landmine.behavior.Behavior;
|
||||
|
||||
/**
|
||||
* This logic is designed only for blocks having TileEntityLandmine as their
|
||||
* tileEntity(otherwise ClassCastException will be awarded)
|
||||
*
|
||||
* @author fuj1n
|
||||
*
|
||||
*/
|
||||
public class LandmineExplodeLogic
|
||||
{
|
||||
|
||||
private final World worldObj;
|
||||
private final Entity triggerer;
|
||||
private final TileEntityLandmine tileEntity;
|
||||
private final int x, y, z;
|
||||
|
||||
public LandmineExplodeLogic(World par1World, int par2, int par3, int par4, Entity entity)
|
||||
{
|
||||
worldObj = par1World;
|
||||
this.tileEntity = (TileEntityLandmine) par1World.getTileEntity(par2, par3, par4);
|
||||
this.x = par2;
|
||||
this.y = par3;
|
||||
this.z = par4;
|
||||
this.triggerer = entity;
|
||||
}
|
||||
|
||||
public void explode ()
|
||||
{
|
||||
if (triggerer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
boolean preventExplode = false;
|
||||
boolean isOffensive = true;
|
||||
boolean cancelDefault = false;
|
||||
|
||||
ArrayList<ItemStack> stacks = new ArrayList<ItemStack>();
|
||||
boolean hasExploded = false;
|
||||
|
||||
if (tileEntity == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
tileEntity.isExploding = true;
|
||||
|
||||
for (int i = 0; i < tileEntity.getSizeTriggerInventory(); i++)
|
||||
{
|
||||
ItemStack currentStack = tileEntity.getStackInSlot(i);
|
||||
Behavior b = Behavior.getBehaviorFromStack(currentStack);
|
||||
if (b != null)
|
||||
{
|
||||
|
||||
if (b.doesBehaviorPreventRemovalOfBlock(currentStack))
|
||||
{
|
||||
preventExplode = true;
|
||||
}
|
||||
|
||||
if (!b.isBehaviorExchangableWithOffensive(currentStack))
|
||||
{
|
||||
isOffensive = false;
|
||||
}
|
||||
|
||||
if (b.overridesDefault())
|
||||
{
|
||||
cancelDefault = true;
|
||||
}
|
||||
|
||||
if (!stacks.isEmpty() && Behavior.arrayContainsEqualStack(stacks, currentStack) && b.effectStacks())
|
||||
{
|
||||
stacks.get(Behavior.arrayIndexOfStack(stacks, currentStack)).stackSize += currentStack.stackSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
stacks.add(currentStack.copy());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LandmineSpecialStackLogic specialStacks = new LandmineSpecialStackLogic(worldObj, x, y, z, triggerer, isOffensive, stacks);
|
||||
specialStacks.handleSpecialStacks();
|
||||
|
||||
Iterator<ItemStack> i1 = stacks.iterator();
|
||||
while (i1.hasNext())
|
||||
{
|
||||
ItemStack currentStack = i1.next();
|
||||
Behavior b = Behavior.getBehaviorFromStack(currentStack);
|
||||
if (b != null)
|
||||
{
|
||||
if (isOffensive || !b.isOffensive(currentStack))
|
||||
{
|
||||
b.executeLogic(worldObj, x, y, z, currentStack, triggerer, !preventExplode);
|
||||
if (b.shouldItemBeRemoved(currentStack, !preventExplode))
|
||||
{
|
||||
if (b.effectStacks())
|
||||
{
|
||||
for (int i = 0; i < tileEntity.getSizeTriggerInventory(); i++)
|
||||
{
|
||||
if (tileEntity.getStackInSlot(i) != null)
|
||||
{
|
||||
if (tileEntity.getStackInSlot(i).isItemEqual(currentStack))
|
||||
{
|
||||
tileEntity.setInventorySlotContents(i, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
boolean hasRemoved = false;
|
||||
|
||||
for (int i = 0; i < tileEntity.getSizeTriggerInventory() && !hasRemoved; i++)
|
||||
{
|
||||
if (tileEntity.getStackInSlot(i) != null)
|
||||
{
|
||||
if (tileEntity.getStackInSlot(i).isItemEqual(currentStack))
|
||||
{
|
||||
tileEntity.setInventorySlotContents(i, null);
|
||||
hasRemoved = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Behavior defBeh = Behavior.getDefaulBehavior();
|
||||
if (defBeh != null && isOffensive && !cancelDefault)
|
||||
{
|
||||
defBeh.executeLogic(worldObj, x, y, z, null, triggerer, !preventExplode);
|
||||
}
|
||||
|
||||
if (hasExploded || defBeh != null && !preventExplode)
|
||||
{
|
||||
worldObj.removeTileEntity(x, y, z);
|
||||
WorldHelper.setBlockToAir(worldObj, x, y, z);
|
||||
}
|
||||
else
|
||||
{
|
||||
tileEntity.isExploding = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package tconstruct.blocks.logic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import tconstruct.util.landmine.behavior.stackCombo.SpecialStackHandler;
|
||||
|
||||
public class LandmineSpecialStackLogic
|
||||
{
|
||||
|
||||
private final World worldObj;
|
||||
private final Entity triggerer;
|
||||
private final TileEntityLandmine tileEntity;
|
||||
private final int x, y, z;
|
||||
private final boolean isOffensive;
|
||||
private final ArrayList<ItemStack> stackEffects;
|
||||
|
||||
public LandmineSpecialStackLogic(World par1World, int par2, int par3, int par4, Entity entity, boolean mayHurtPlayer, ArrayList<ItemStack> items)
|
||||
{
|
||||
worldObj = par1World;
|
||||
this.tileEntity = (TileEntityLandmine) par1World.getTileEntity(par2, par3, par4);
|
||||
this.x = par2;
|
||||
this.y = par3;
|
||||
this.z = par4;
|
||||
this.triggerer = entity;
|
||||
this.isOffensive = mayHurtPlayer;
|
||||
this.stackEffects = items;
|
||||
}
|
||||
|
||||
public void handleSpecialStacks ()
|
||||
{
|
||||
Iterator<SpecialStackHandler> i1 = SpecialStackHandler.handlers.iterator();
|
||||
|
||||
while (i1.hasNext())
|
||||
{
|
||||
SpecialStackHandler h = i1.next();
|
||||
if (isOffensive || !h.isOffensive(stackEffects))
|
||||
{
|
||||
h.checkStack(worldObj, x, y, z, triggerer, stackEffects);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,180 +0,0 @@
|
||||
package tconstruct.blocks.logic;
|
||||
|
||||
import mantle.blocks.abstracts.MultiServantLogic;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
|
||||
public class LavaTankLogic extends MultiServantLogic implements IFluidHandler
|
||||
{
|
||||
public FluidTank tank;
|
||||
public int renderOffset;
|
||||
|
||||
public LavaTankLogic()
|
||||
{
|
||||
tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME * 4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill (ForgeDirection from, FluidStack resource, boolean doFill)
|
||||
{
|
||||
int amount = tank.fill(resource, doFill);
|
||||
if (amount > 0 && doFill)
|
||||
{
|
||||
renderOffset = resource.amount;
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
return amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain (ForgeDirection from, int maxDrain, boolean doDrain)
|
||||
{
|
||||
FluidStack amount = tank.drain(maxDrain, doDrain);
|
||||
if (amount != null && doDrain)
|
||||
{
|
||||
renderOffset = -maxDrain;
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
}
|
||||
return amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain (ForgeDirection from, FluidStack resource, boolean doDrain)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFill (ForgeDirection from, Fluid fluid)
|
||||
{
|
||||
// return tank.fill(fluid, false) > 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDrain (ForgeDirection from, Fluid fluid)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo[] getTankInfo (ForgeDirection from)
|
||||
{
|
||||
FluidStack fluid = null;
|
||||
if (tank.getFluid() != null)
|
||||
fluid = tank.getFluid().copy();
|
||||
return new FluidTankInfo[] { new FluidTankInfo(fluid, tank.getCapacity()) };
|
||||
}
|
||||
|
||||
/*
|
||||
* @Override public IFluidTank[] getTanks (ForgeDirection direction) {
|
||||
* return new IFluidTank[] { tank }; }
|
||||
*
|
||||
* @Override public IFluidTank getTank (ForgeDirection direction, FluidStack
|
||||
* type) { return tank; }
|
||||
*/
|
||||
|
||||
public float getFluidAmountScaled ()
|
||||
{
|
||||
return (float) (tank.getFluid().amount - renderOffset) / (float) (tank.getCapacity() * 1.01F);
|
||||
}
|
||||
|
||||
public boolean containsFluid ()
|
||||
{
|
||||
return tank.getFluid() != null;
|
||||
}
|
||||
|
||||
public int getBrightness ()
|
||||
{
|
||||
if (containsFluid())
|
||||
{
|
||||
int id = tank.getFluid().fluidID;
|
||||
if (id < 4096)
|
||||
{
|
||||
Block block = Block.getBlockById(id);
|
||||
return block.getLightValue();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT (NBTTagCompound tags)
|
||||
{
|
||||
super.readFromNBT(tags);
|
||||
readCustomNBT(tags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT (NBTTagCompound tags)
|
||||
{
|
||||
super.writeToNBT(tags);
|
||||
writeCustomNBT(tags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readCustomNBT (NBTTagCompound tags)
|
||||
{
|
||||
if (tags.getBoolean("hasFluid"))
|
||||
tank.setFluid(new FluidStack(tags.getInteger("itemID"), tags.getInteger("amount")));
|
||||
else
|
||||
tank.setFluid(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeCustomNBT (NBTTagCompound tags)
|
||||
{
|
||||
FluidStack liquid = tank.getFluid();
|
||||
tags.setBoolean("hasFluid", liquid != null);
|
||||
if (liquid != null)
|
||||
{
|
||||
tags.setInteger("itemID", liquid.fluidID);
|
||||
tags.setInteger("amount", liquid.amount);
|
||||
}
|
||||
}
|
||||
|
||||
/* Packets */
|
||||
@Override
|
||||
public Packet getDescriptionPacket ()
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
writeCustomNBT(tag);
|
||||
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket (NetworkManager net, S35PacketUpdateTileEntity packet)
|
||||
{
|
||||
readCustomNBT(packet.func_148857_g());
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
/* Updating */
|
||||
@Override
|
||||
public boolean canUpdate ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity ()
|
||||
{
|
||||
if (renderOffset > 0)
|
||||
{
|
||||
renderOffset -= 6;
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
package tconstruct.blocks.logic;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public class LiquidTextureLogic extends TileEntity
|
||||
{
|
||||
int texturePos;
|
||||
|
||||
@Override
|
||||
public boolean canUpdate ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setLiquidType (int tex)
|
||||
{
|
||||
texturePos = tex;
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
public int getLiquidType ()
|
||||
{
|
||||
return texturePos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT (NBTTagCompound tags)
|
||||
{
|
||||
super.readFromNBT(tags);
|
||||
readCustomNBT(tags);
|
||||
}
|
||||
|
||||
public void readCustomNBT (NBTTagCompound tags)
|
||||
{
|
||||
texturePos = tags.getInteger("Texture");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT (NBTTagCompound tags)
|
||||
{
|
||||
super.writeToNBT(tags);
|
||||
writeCustomNBT(tags);
|
||||
}
|
||||
|
||||
public void writeCustomNBT (NBTTagCompound tags)
|
||||
{
|
||||
tags.setInteger("Texture", texturePos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket ()
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
writeCustomNBT(tag);
|
||||
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket (NetworkManager net, S35PacketUpdateTileEntity packet)
|
||||
{
|
||||
readCustomNBT(packet.func_148857_g());
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
}
|
||||
}
|
||||
@@ -1,215 +0,0 @@
|
||||
package tconstruct.blocks.logic;
|
||||
|
||||
import mantle.blocks.abstracts.InventoryLogic;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import tconstruct.inventory.PartCrafterChestContainer;
|
||||
import tconstruct.inventory.PartCrafterContainer;
|
||||
import tconstruct.library.crafting.PatternBuilder;
|
||||
import tconstruct.library.util.IPattern;
|
||||
|
||||
public class PartBuilderLogic extends InventoryLogic implements ISidedInventory
|
||||
{
|
||||
boolean craftedTop;
|
||||
boolean craftedBottom;
|
||||
|
||||
public PartBuilderLogic()
|
||||
{
|
||||
super(10);
|
||||
craftedTop = false;
|
||||
craftedBottom = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultName ()
|
||||
{
|
||||
return "toolstation.parts";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Container getGuiContainer (InventoryPlayer inventoryplayer, World world, int x, int y, int z)
|
||||
{
|
||||
for (int xPos = x - 1; xPos <= x + 1; xPos++)
|
||||
{
|
||||
for (int zPos = z - 1; zPos <= z + 1; zPos++)
|
||||
{
|
||||
for (int yPos = y - 1; yPos <= y + 1; yPos++)
|
||||
{
|
||||
TileEntity tile = world.getTileEntity(xPos, yPos, zPos);
|
||||
if (tile != null && tile instanceof PatternChestLogic && (x == xPos || z == zPos))
|
||||
return new PartCrafterChestContainer(inventoryplayer, this, (PatternChestLogic) tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new PartCrafterContainer(inventoryplayer, this);
|
||||
}
|
||||
|
||||
//Called when emptying a slot, not when another item is placed in it
|
||||
@Override
|
||||
public ItemStack decrStackSize (int slotID, int quantity)
|
||||
{
|
||||
ItemStack returnStack = super.decrStackSize(slotID, quantity);
|
||||
tryBuildPart(slotID);
|
||||
return returnStack;
|
||||
}
|
||||
|
||||
public void tryBuildPart (int slotID)
|
||||
{
|
||||
if (slotID == 4 || slotID == 5)
|
||||
{
|
||||
if (!craftedTop && inventory[0] != null)
|
||||
{
|
||||
int value = PatternBuilder.instance.getPartValue(inventory[2]);
|
||||
IPattern item = (IPattern) inventory[0].getItem();
|
||||
int cost = item != null ? item.getPatternCost(inventory[0]) : 0;
|
||||
if (value > 0 && cost > 0)
|
||||
{
|
||||
int decrease = cost / value;
|
||||
if (cost % value != 0)
|
||||
decrease++;
|
||||
super.decrStackSize(2, decrease); //Call super to avoid crafting again
|
||||
}
|
||||
}
|
||||
|
||||
if (inventory[4] != null || inventory[5] != null)
|
||||
craftedTop = true;
|
||||
else
|
||||
craftedTop = false;
|
||||
}
|
||||
|
||||
if (!craftedTop)
|
||||
buildTopPart();
|
||||
|
||||
if (slotID == 6 || slotID == 7)
|
||||
{
|
||||
if (!craftedBottom && inventory[1] != null)
|
||||
{
|
||||
int value = PatternBuilder.instance.getPartValue(inventory[3]);
|
||||
IPattern item = (IPattern) inventory[1].getItem();
|
||||
int cost = item != null ? item.getPatternCost(inventory[1]) : 0;
|
||||
if (value > 0 && cost > 0)
|
||||
{
|
||||
int decrease = cost / value;
|
||||
if (cost % value != 0)
|
||||
decrease++;
|
||||
super.decrStackSize(3, decrease); //Call super to avoid crafting again
|
||||
}
|
||||
}
|
||||
|
||||
if (inventory[6] != null || inventory[7] != null)
|
||||
craftedBottom = true;
|
||||
else
|
||||
craftedBottom = false;
|
||||
}
|
||||
|
||||
if (!craftedBottom)
|
||||
buildBottomPart();
|
||||
}
|
||||
|
||||
//Called when a slot has something placed into it.
|
||||
@Override
|
||||
public void setInventorySlotContents (int slot, ItemStack itemstack)
|
||||
{
|
||||
super.setInventorySlotContents(slot, itemstack);
|
||||
if ((slot == 0 || slot == 2) && !craftedTop)
|
||||
buildTopPart();
|
||||
if ((slot == 1 || slot == 3) && !craftedBottom)
|
||||
buildBottomPart();
|
||||
}
|
||||
|
||||
void buildTopPart ()
|
||||
{
|
||||
ItemStack[] parts = PatternBuilder.instance.getToolPart(inventory[2], inventory[0], inventory[1]);
|
||||
if (parts != null)
|
||||
{
|
||||
inventory[4] = parts[0];
|
||||
inventory[5] = parts[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
inventory[4] = inventory[5] = null;
|
||||
}
|
||||
}
|
||||
|
||||
void buildBottomPart ()
|
||||
{
|
||||
ItemStack[] parts = PatternBuilder.instance.getToolPart(inventory[3], inventory[1], inventory[0]);
|
||||
if (parts != null)
|
||||
{
|
||||
inventory[6] = parts[0];
|
||||
inventory[7] = parts[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
inventory[6] = inventory[7] = null;
|
||||
}
|
||||
}
|
||||
|
||||
/* NBT */
|
||||
@Override
|
||||
public void readFromNBT (NBTTagCompound tags)
|
||||
{
|
||||
super.readFromNBT(tags);
|
||||
craftedTop = tags.getBoolean("CraftedTop");
|
||||
craftedBottom = tags.getBoolean("CraftedBottom");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT (NBTTagCompound tags)
|
||||
{
|
||||
super.writeToNBT(tags);
|
||||
tags.setBoolean("CraftedTop", craftedTop);
|
||||
tags.setBoolean("CraftedBottom", craftedBottom);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide (int side)
|
||||
{
|
||||
return new int[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem (int i, ItemStack itemstack, int j)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem (int i, ItemStack itemstack, int j)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName ()
|
||||
{
|
||||
return getDefaultName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory ()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory ()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUpdate ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package tconstruct.blocks.logic;
|
||||
|
||||
import mantle.blocks.abstracts.InventoryLogic;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.world.World;
|
||||
import tconstruct.inventory.PatternChestContainer;
|
||||
|
||||
public class PatternChestLogic extends InventoryLogic
|
||||
{
|
||||
public PatternChestLogic()
|
||||
{
|
||||
super(30);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUpdate ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultName ()
|
||||
{
|
||||
return "toolstation.patternholder";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Container getGuiContainer (InventoryPlayer inventoryplayer, World world, int x, int y, int z)
|
||||
{
|
||||
return new PatternChestContainer(inventoryplayer, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName ()
|
||||
{
|
||||
return getDefaultName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory ()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory ()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
package tconstruct.blocks.logic;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public class RedwireLogic extends TileEntity
|
||||
{
|
||||
byte facesUsed;
|
||||
byte type;
|
||||
byte distanceTravelled;
|
||||
byte maxDistance;
|
||||
|
||||
public void readCustomNBT (NBTTagCompound tags)
|
||||
{
|
||||
/*
|
||||
* hasMaster = tags.getBoolean("HasMaster"); if (hasMaster) { int
|
||||
* xCenter = tags.getInteger("xCenter"); int yCenter =
|
||||
* tags.getInteger("yCenter"); int zCenter = tags.getInteger("zCenter");
|
||||
* master = new CoordTuple(xCenter, yCenter, zCenter); masterID =
|
||||
* tags.getShort("MasterID"); masterMeat = tags.getByte("masterMeat"); }
|
||||
*/
|
||||
}
|
||||
|
||||
public void writeCustomNBT (NBTTagCompound tags)
|
||||
{
|
||||
/*
|
||||
* tags.setBoolean("HasMaster", hasMaster); if (hasMaster) {
|
||||
* tags.setInteger("xCenter", master.x); tags.setInteger("yCenter",
|
||||
* master.y); tags.setInteger("zCenter", master.z);
|
||||
* tags.setShort("MasterID", masterID); tags.setByte("masterMeat",
|
||||
* masterMeat); }
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT (NBTTagCompound tags)
|
||||
{
|
||||
super.readFromNBT(tags);
|
||||
readCustomNBT(tags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT (NBTTagCompound tags)
|
||||
{
|
||||
super.writeToNBT(tags);
|
||||
writeCustomNBT(tags);
|
||||
}
|
||||
|
||||
/* Packets */
|
||||
@Override
|
||||
public Packet getDescriptionPacket ()
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
writeCustomNBT(tag);
|
||||
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket (NetworkManager net, S35PacketUpdateTileEntity packet)
|
||||
{
|
||||
readCustomNBT(packet.func_148857_g());
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
}
|
||||
}
|
||||
@@ -1,188 +0,0 @@
|
||||
package tconstruct.blocks.logic;
|
||||
|
||||
import mantle.blocks.abstracts.MultiServantLogic;
|
||||
import mantle.blocks.iface.IFacingLogic;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
|
||||
public class SmelteryDrainLogic extends MultiServantLogic implements IFluidHandler, IFacingLogic
|
||||
{
|
||||
byte direction;
|
||||
|
||||
@Override
|
||||
public boolean canUpdate ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill (ForgeDirection from, FluidStack resource, boolean doFill)
|
||||
{
|
||||
if (hasValidMaster() && resource != null && canFill(from, resource.getFluid()))
|
||||
{
|
||||
if (doFill)
|
||||
{
|
||||
SmelteryLogic smeltery = (SmelteryLogic) worldObj.getTileEntity(getMasterPosition().x, getMasterPosition().y, getMasterPosition().z);
|
||||
return smeltery.fill(resource, doFill);
|
||||
}
|
||||
else
|
||||
{
|
||||
return resource.amount;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain (ForgeDirection from, int maxDrain, boolean doDrain)
|
||||
{
|
||||
if (hasValidMaster() && canDrain(from, null))
|
||||
{
|
||||
SmelteryLogic smeltery = (SmelteryLogic) worldObj.getTileEntity(getMasterPosition().x, getMasterPosition().y, getMasterPosition().z);
|
||||
return smeltery.drain(maxDrain, doDrain);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain (ForgeDirection from, FluidStack resource, boolean doDrain)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFill (ForgeDirection from, Fluid fluid)
|
||||
{
|
||||
return true;
|
||||
// return from == getForgeDirection();//.getOpposite();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDrain (ForgeDirection from, Fluid fluid)
|
||||
{
|
||||
// Check that the drain is coming from the from the front of the block
|
||||
// and that the fluid to be drained is in the smeltery.
|
||||
boolean containsFluid = fluid == null;
|
||||
if (fluid != null)
|
||||
{
|
||||
SmelteryLogic smeltery = (SmelteryLogic) worldObj.getTileEntity(getMasterPosition().x, getMasterPosition().y, getMasterPosition().z);
|
||||
for (FluidStack fstack : smeltery.moltenMetal)
|
||||
{
|
||||
if (fstack.fluidID == fluid.getID())
|
||||
{
|
||||
containsFluid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// return from == getForgeDirection().getOpposite() && containsFluid;
|
||||
return containsFluid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo[] getTankInfo (ForgeDirection from)
|
||||
{
|
||||
if (hasValidMaster() && (from == getForgeDirection() || from == getForgeDirection().getOpposite() || from == ForgeDirection.UNKNOWN))
|
||||
{
|
||||
SmelteryLogic smeltery = (SmelteryLogic) worldObj.getTileEntity(getMasterPosition().x, getMasterPosition().y, getMasterPosition().z);
|
||||
return smeltery.getMultiTankInfo();
|
||||
// return new FluidTankInfo[] { smeltery.getInfo() };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getRenderDirection ()
|
||||
{
|
||||
return direction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForgeDirection getForgeDirection ()
|
||||
{
|
||||
return ForgeDirection.VALID_DIRECTIONS[direction];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDirection (int side)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDirection (float yaw, float pitch, EntityLivingBase player)
|
||||
{
|
||||
if (pitch > 45)
|
||||
direction = 1;
|
||||
else if (pitch < -45)
|
||||
direction = 0;
|
||||
else
|
||||
{
|
||||
int facing = MathHelper.floor_double((double) (yaw / 360) + 0.5D) & 3;
|
||||
switch (facing)
|
||||
{
|
||||
case 0:
|
||||
direction = 2;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
direction = 5;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
direction = 3;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
direction = 4;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT (NBTTagCompound tags)
|
||||
{
|
||||
super.readFromNBT(tags);
|
||||
direction = tags.getByte("Direction");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT (NBTTagCompound tags)
|
||||
{
|
||||
super.writeToNBT(tags);
|
||||
tags.setByte("Direction", direction);
|
||||
}
|
||||
|
||||
/* Packets */
|
||||
@Override
|
||||
public Packet getDescriptionPacket ()
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
writeToNBT(tag);
|
||||
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket (NetworkManager net, S35PacketUpdateTileEntity packet)
|
||||
{
|
||||
readFromNBT(packet.func_148857_g());
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,146 +0,0 @@
|
||||
package tconstruct.blocks.logic;
|
||||
|
||||
import mantle.blocks.abstracts.InventoryLogic;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.world.World;
|
||||
import tconstruct.common.TRepo;
|
||||
import tconstruct.inventory.PatternShaperContainer;
|
||||
|
||||
public class StencilTableLogic extends InventoryLogic implements ISidedInventory
|
||||
{
|
||||
public StencilTableLogic()
|
||||
{
|
||||
super(2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUpdate ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultName ()
|
||||
{
|
||||
return "toolstation.PatternShaper";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Container getGuiContainer (InventoryPlayer inventoryplayer, World world, int x, int y, int z)
|
||||
{
|
||||
return new PatternShaperContainer(inventoryplayer, this);
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public void onInventoryChanged()
|
||||
{
|
||||
if (inventory[0] == null)
|
||||
inventory[1] = null;
|
||||
super.onInventoryChanged();
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents (int slot, ItemStack itemstack)
|
||||
{
|
||||
super.setInventorySlotContents(slot, itemstack);
|
||||
if (slot == 0 && itemstack != null && itemstack.getItem() == TRepo.blankPattern)//instanceof tconstruct.items.Pattern)
|
||||
{
|
||||
if (itemstack.getItemDamage() == 0)
|
||||
setInventorySlotContents(1, new ItemStack(TRepo.woodPattern, 1, 1));
|
||||
/*else if (itemstack.getItemDamage() == 1)
|
||||
setInventorySlotContents(1, new ItemStack(TContent.metalPattern, 1, 0));*/
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize (int slot, int quantity)
|
||||
{
|
||||
if (slot == 1)
|
||||
{
|
||||
super.decrStackSize(0, 1);
|
||||
if (inventory[0] == null)
|
||||
return super.decrStackSize(slot, quantity);
|
||||
else
|
||||
return inventory[1].copy();
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemStack ret = super.decrStackSize(slot, quantity);
|
||||
if (inventory[0] == null)
|
||||
super.decrStackSize(1, 1);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
public void altDecrStackSize (int slot, int quantity)
|
||||
{
|
||||
if (inventory[slot] != null)
|
||||
{
|
||||
if (inventory[slot].stackSize <= quantity)
|
||||
{
|
||||
ItemStack stack = inventory[slot];
|
||||
inventory[slot] = null;
|
||||
return;
|
||||
}
|
||||
ItemStack split = inventory[slot].splitStack(quantity);
|
||||
if (inventory[slot].stackSize == 0)
|
||||
{
|
||||
inventory[slot] = null;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDropInventorySlot (int slot)
|
||||
{
|
||||
if (slot == 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide (int side)
|
||||
{
|
||||
return new int[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem (int i, ItemStack itemstack, int j)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem (int i, ItemStack itemstack, int j)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName ()
|
||||
{
|
||||
return StatCollector.translateToLocal("toolstation.PatternShaper");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory ()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory ()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,219 +0,0 @@
|
||||
package tconstruct.blocks.logic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import mantle.blocks.abstracts.InventoryLogic;
|
||||
import mantle.blocks.iface.IMasterLogic;
|
||||
import mantle.blocks.iface.IServantLogic;
|
||||
import mantle.world.CoordTuple;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import tconstruct.TConstruct;
|
||||
import tconstruct.blocks.component.TankAirComponent;
|
||||
|
||||
public class TankAirLogic extends InventoryLogic implements IServantLogic, ISidedInventory
|
||||
{
|
||||
TankAirComponent multitank = new TankAirComponent(TConstruct.ingotLiquidValue * 18);
|
||||
CoordTuple master;
|
||||
|
||||
public TankAirLogic()
|
||||
{
|
||||
super(1);
|
||||
}
|
||||
|
||||
public void overrideFluids (ArrayList<FluidStack> fluids)
|
||||
{
|
||||
/*
|
||||
* multitank.overrideFluids(fluids); worldObj.markBlockForUpdate(xCoord,
|
||||
* yCoord, zCoord);
|
||||
*/
|
||||
}
|
||||
|
||||
public boolean hasItem ()
|
||||
{
|
||||
return inventory[0] != null;
|
||||
}
|
||||
|
||||
public boolean hasFluids ()
|
||||
{
|
||||
return multitank.fluidlist.size() > 0;
|
||||
}
|
||||
|
||||
public List<FluidStack> getFluids ()
|
||||
{
|
||||
return multitank.fluidlist;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents (int slot, ItemStack itemstack)
|
||||
{
|
||||
/*
|
||||
* inventory[slot] = itemstack; if (itemstack != null &&
|
||||
* itemstack.stackSize > getInventoryStackLimit()) { itemstack.stackSize
|
||||
* = getInventoryStackLimit();
|
||||
* worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord,
|
||||
* itemstack.getItemDamage(), 3); worldObj.markBlockForUpdate(xCoord,
|
||||
* yCoord, zCoord); }
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public Container getGuiContainer (InventoryPlayer inventoryplayer, World world, int x, int y, int z)
|
||||
{
|
||||
return null; // Not a gui block
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultName ()
|
||||
{
|
||||
return null; // Not a gui block
|
||||
}
|
||||
|
||||
@Override
|
||||
public CoordTuple getMasterPosition ()
|
||||
{
|
||||
return master;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyMasterOfChange ()
|
||||
{
|
||||
// Probably not useful here
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setPotentialMaster (IMasterLogic master, World world, int xMaster, int yMaster, int zMaster)
|
||||
{
|
||||
return false; // Master should be verified right after placement
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean verifyMaster (IMasterLogic logic, World world, int xMaster, int yMaster, int zMaster)
|
||||
{
|
||||
/*
|
||||
* if (master != null) //Is this even needed? return false;
|
||||
*/
|
||||
|
||||
master = new CoordTuple(xMaster, yMaster, zMaster);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateMaster (IMasterLogic master, World world, int xMaster, int yMaster, int zMaster)
|
||||
{
|
||||
world.setBlockToAir(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide (int var1)
|
||||
{
|
||||
return new int[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem (int i, ItemStack itemstack, int j)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem (int i, ItemStack itemstack, int j)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* @Override public boolean canUpdate() { return false; }
|
||||
*/
|
||||
|
||||
// DELETE
|
||||
@Override
|
||||
public void updateEntity ()
|
||||
{
|
||||
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
// Keep TE regardless of metadata
|
||||
public boolean shouldRefresh (int oldID, int newID, int oldMeta, int newMeta, World world, int x, int y, int z)
|
||||
{
|
||||
return oldID != newID;
|
||||
}
|
||||
|
||||
/* NBT */
|
||||
|
||||
@Override
|
||||
public void readFromNBT (NBTTagCompound tags)
|
||||
{
|
||||
super.readFromNBT(tags);
|
||||
readNetworkNBT(tags);
|
||||
multitank.readFromNBT(tags);
|
||||
}
|
||||
|
||||
public void readNetworkNBT (NBTTagCompound tags)
|
||||
{
|
||||
multitank.readNetworkNBT(tags);
|
||||
super.readInventoryFromNBT(tags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT (NBTTagCompound tags)
|
||||
{
|
||||
super.writeToNBT(tags);
|
||||
writeNetworkNBT(tags);
|
||||
multitank.writeToNBT(tags);
|
||||
}
|
||||
|
||||
public void writeNetworkNBT (NBTTagCompound tags)
|
||||
{
|
||||
multitank.writeNetworkNBT(tags);
|
||||
super.writeInventoryToNBT(tags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket (NetworkManager net, S35PacketUpdateTileEntity packet)
|
||||
{
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
readNetworkNBT(packet.func_148857_g());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket ()
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
writeNetworkNBT(tag);
|
||||
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName ()
|
||||
{
|
||||
return this.getInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory ()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory ()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,269 +0,0 @@
|
||||
package tconstruct.blocks.logic;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author fuj1n
|
||||
*
|
||||
*/
|
||||
public class TileEntityLandmine extends TileEntity implements IInventory
|
||||
{
|
||||
|
||||
private ItemStack[] inventory = new ItemStack[getSizeInventory()];
|
||||
private String containerName;
|
||||
|
||||
public int soundcountythingmax = 10;
|
||||
public int soundcountything = 0;
|
||||
|
||||
private boolean shouldUpdateLogic = true;
|
||||
|
||||
public int triggerType;
|
||||
public boolean isExploding = false;
|
||||
|
||||
public int getSizeTriggerInventory ()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory ()
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT (NBTTagCompound par1NBTTagCompound)
|
||||
{
|
||||
super.writeToNBT(par1NBTTagCompound);
|
||||
NBTTagList nbttaglist = new NBTTagList();
|
||||
|
||||
for (int i = 0; i < this.inventory.length; ++i)
|
||||
{
|
||||
if (this.inventory[i] != null)
|
||||
{
|
||||
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
|
||||
nbttagcompound1.setByte("Slot", (byte) i);
|
||||
this.inventory[i].writeToNBT(nbttagcompound1);
|
||||
nbttaglist.appendTag(nbttagcompound1);
|
||||
}
|
||||
}
|
||||
|
||||
par1NBTTagCompound.setTag("Items", nbttaglist);
|
||||
|
||||
par1NBTTagCompound.setInteger("triggerType", triggerType);
|
||||
|
||||
if (this.hasCustomInventoryName())
|
||||
{
|
||||
par1NBTTagCompound.setString("CustomName", this.containerName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT (NBTTagCompound par1NBTTagCompound)
|
||||
{
|
||||
super.readFromNBT(par1NBTTagCompound);
|
||||
NBTTagList nbttaglist = par1NBTTagCompound.getTagList("Items", 10);
|
||||
this.inventory = new ItemStack[this.getSizeInventory()];
|
||||
|
||||
for (int i = 0; i < nbttaglist.tagCount(); ++i)
|
||||
{
|
||||
NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.getCompoundTagAt(i);
|
||||
byte b0 = nbttagcompound1.getByte("Slot");
|
||||
|
||||
if (b0 >= 0 && b0 < this.inventory.length)
|
||||
{
|
||||
this.inventory[b0] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
|
||||
}
|
||||
}
|
||||
|
||||
triggerType = par1NBTTagCompound.getInteger("triggerType");
|
||||
|
||||
if (par1NBTTagCompound.hasKey("CustomName"))
|
||||
{
|
||||
this.containerName = par1NBTTagCompound.getString("CustomName");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket ()
|
||||
{
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
writeToNBT(nbt);
|
||||
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 0, nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket (NetworkManager net, S35PacketUpdateTileEntity packet)
|
||||
{
|
||||
readFromNBT(packet.func_148857_g());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot (int i)
|
||||
{
|
||||
if (i < inventory.length)
|
||||
{
|
||||
return inventory[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize (int par1, int par2)
|
||||
{
|
||||
if (par1 < inventory.length)
|
||||
{
|
||||
if (inventory[par1] != null)
|
||||
{
|
||||
ItemStack itemstack;
|
||||
|
||||
if (inventory[par1].stackSize <= par2)
|
||||
{
|
||||
itemstack = inventory[par1];
|
||||
inventory[par1] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else
|
||||
{
|
||||
itemstack = inventory[par1].splitStack(par2);
|
||||
|
||||
if (inventory[par1].stackSize == 0)
|
||||
{
|
||||
inventory[par1] = null;
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing (int i)
|
||||
{
|
||||
if (i < inventory.length && this.inventory[i] != null)
|
||||
{
|
||||
ItemStack itemstack = this.inventory[i];
|
||||
this.inventory[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents (int i, ItemStack itemstack)
|
||||
{
|
||||
if (i < inventory.length)
|
||||
{
|
||||
inventory[i] = itemstack;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName ()
|
||||
{
|
||||
return this.hasCustomInventoryName() ? this.containerName : "Landmine";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName ()
|
||||
{
|
||||
return containerName != null && containerName.length() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit ()
|
||||
{
|
||||
return 64;
|
||||
}
|
||||
|
||||
public void setGuiDisplayName (String par1Str)
|
||||
{
|
||||
this.containerName = par1Str;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer (EntityPlayer par1EntityPlayer)
|
||||
{
|
||||
return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : par1EntityPlayer.getDistanceSq((double) this.xCoord + 0.5D, (double) this.yCoord + 0.5D,
|
||||
(double) this.zCoord + 0.5D) <= 64.0D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory ()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory ()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty ()
|
||||
{
|
||||
super.markDirty();
|
||||
this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot (int i, ItemStack itemstack)
|
||||
{
|
||||
// Should automatic camo insertion be allowed.
|
||||
if (i == 3)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Here for mDiyo to decide if he wants automation for
|
||||
// insertion/extraction of the items to be an option.
|
||||
// Would be useful for building automated mine laying machines.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void setSoundPlayed ()
|
||||
{
|
||||
soundcountythingmax = 35;
|
||||
soundcountything = soundcountythingmax;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity ()
|
||||
{
|
||||
if (shouldUpdateLogic)
|
||||
{
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
shouldUpdateLogic = false;
|
||||
}
|
||||
if (soundcountything > 0)
|
||||
{
|
||||
soundcountything--;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package tconstruct.blocks.logic;
|
||||
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import tconstruct.inventory.ToolForgeContainer;
|
||||
import tconstruct.library.crafting.ToolBuilder;
|
||||
|
||||
/* Simple class for storing items in the block
|
||||
*/
|
||||
|
||||
public class ToolForgeLogic extends ToolStationLogic implements ISidedInventory
|
||||
{
|
||||
ItemStack previousTool;
|
||||
String toolName;
|
||||
|
||||
public ToolForgeLogic()
|
||||
{
|
||||
super(6);
|
||||
toolName = "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultName ()
|
||||
{
|
||||
return "crafters.ToolForge";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Container getGuiContainer (InventoryPlayer inventoryplayer, World world, int x, int y, int z)
|
||||
{
|
||||
return new ToolForgeContainer(inventoryplayer, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildTool (String name)
|
||||
{
|
||||
toolName = name;
|
||||
ItemStack tool = ToolBuilder.instance.buildTool(inventory[1], inventory[2], inventory[3], inventory[4], name);
|
||||
if (inventory[0] == null)
|
||||
inventory[0] = tool;
|
||||
else
|
||||
{
|
||||
NBTTagCompound tags = inventory[0].getTagCompound();
|
||||
if (!tags.getCompoundTag("InfiTool").hasKey("Built"))
|
||||
{
|
||||
inventory[0] = tool;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
package tconstruct.blocks.logic;
|
||||
|
||||
import mantle.blocks.abstracts.InventoryLogic;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import tconstruct.inventory.ToolStationContainer;
|
||||
import tconstruct.library.crafting.ToolBuilder;
|
||||
|
||||
/* Simple class for storing items in the block
|
||||
*/
|
||||
|
||||
public class ToolStationLogic extends InventoryLogic implements ISidedInventory
|
||||
{
|
||||
public ItemStack previousTool;
|
||||
public String toolName;
|
||||
|
||||
public ToolStationLogic()
|
||||
{
|
||||
super(4);
|
||||
toolName = "";
|
||||
}
|
||||
|
||||
public ToolStationLogic(int slots)
|
||||
{
|
||||
super(slots);
|
||||
toolName = "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDropInventorySlot (int slot)
|
||||
{
|
||||
if (slot == 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing (int var1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultName ()
|
||||
{
|
||||
return "crafters.ToolStation";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Container getGuiContainer (InventoryPlayer inventoryplayer, World world, int x, int y, int z)
|
||||
{
|
||||
return new ToolStationContainer(inventoryplayer, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty ()
|
||||
{
|
||||
buildTool(toolName);
|
||||
if (this.worldObj != null)
|
||||
{
|
||||
this.blockMetadata = this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord);
|
||||
this.worldObj.markTileEntityChunkModified(this.xCoord, this.yCoord, this.zCoord, this);
|
||||
}
|
||||
}
|
||||
|
||||
public void buildTool (String name)
|
||||
{
|
||||
toolName = name;
|
||||
ItemStack tool = ToolBuilder.instance.buildTool(inventory[1], inventory[2], inventory[3], name);
|
||||
if (inventory[0] == null)
|
||||
inventory[0] = tool;
|
||||
else
|
||||
{
|
||||
NBTTagCompound tags = inventory[0].getTagCompound();
|
||||
if (!tags.getCompoundTag("InfiTool").hasKey("Built"))
|
||||
{
|
||||
inventory[0] = tool;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setToolname (String name)
|
||||
{
|
||||
toolName = name;
|
||||
buildTool(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUpdate ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide (int side)
|
||||
{
|
||||
return new int[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem (int i, ItemStack itemstack, int j)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem (int i, ItemStack itemstack, int j)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName ()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory ()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory ()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package tconstruct.blocks.logic;
|
||||
|
||||
import mantle.blocks.abstracts.AdaptiveInventoryLogic;
|
||||
import mantle.blocks.iface.IActiveLogic;
|
||||
import mantle.blocks.iface.IFacingLogic;
|
||||
import mantle.blocks.iface.IMasterLogic;
|
||||
|
||||
//Not actually abstract
|
||||
public abstract class TowerFurnaceLogic extends AdaptiveInventoryLogic implements IActiveLogic, IFacingLogic, IMasterLogic
|
||||
{
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user