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
@@ -0,0 +1,284 @@
|
||||
package tconstruct.smeltery.component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import mantle.world.CoordTuple;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
import tconstruct.library.component.LogicComponent;
|
||||
import tconstruct.library.component.MultiFluidTank;
|
||||
import tconstruct.library.crafting.Smeltery;
|
||||
import tconstruct.smeltery.logic.AdaptiveSmelteryLogic;
|
||||
|
||||
public class SmelteryComponent extends LogicComponent
|
||||
{
|
||||
final AdaptiveSmelteryLogic master;
|
||||
final SmelteryScan structure;
|
||||
final MultiFluidTank multitank;
|
||||
int maxTemp;
|
||||
|
||||
public int fuelTicks;
|
||||
public int fuelGague;
|
||||
public int fuelAmount;
|
||||
boolean inUse;
|
||||
|
||||
public int[] activeTemps = new int[0];
|
||||
public int[] meltingTemps = new int[0];
|
||||
|
||||
CoordTuple activeLavaTank;
|
||||
|
||||
public SmelteryComponent(AdaptiveSmelteryLogic inventory, SmelteryScan structure, MultiFluidTank multitank, int maxTemp)
|
||||
{
|
||||
master = inventory;
|
||||
this.structure = structure;
|
||||
this.multitank = multitank;
|
||||
this.maxTemp = maxTemp;
|
||||
}
|
||||
|
||||
public void update ()
|
||||
{
|
||||
/*
|
||||
* if (useTime > 0 && inUse) useTime -= 3;
|
||||
*/
|
||||
if (activeTemps.length == 0)
|
||||
inUse = false;
|
||||
|
||||
updateFuelGague();
|
||||
}
|
||||
|
||||
public void adjustSize (int size, boolean forceAdjust)
|
||||
{
|
||||
if (size != activeTemps.length || forceAdjust)
|
||||
{
|
||||
int[] tempActive = activeTemps;
|
||||
activeTemps = new int[size];
|
||||
int activeLength = tempActive.length > activeTemps.length ? activeTemps.length : tempActive.length;
|
||||
System.arraycopy(tempActive, 0, activeTemps, 0, activeLength);
|
||||
|
||||
int[] tempMelting = meltingTemps;
|
||||
meltingTemps = new int[size];
|
||||
int meltingLength = tempMelting.length > meltingTemps.length ? meltingTemps.length : tempMelting.length;
|
||||
System.arraycopy(tempMelting, 0, meltingTemps, 0, meltingLength);
|
||||
|
||||
if (activeTemps.length > 0 && activeTemps.length > tempActive.length)
|
||||
{
|
||||
for (int i = tempActive.length; i < activeTemps.length; i++)
|
||||
{
|
||||
activeTemps[i] = 20;
|
||||
meltingTemps[i] = 20;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateTemperatures ()
|
||||
{
|
||||
inUse = true;
|
||||
for (int i = 0; i < meltingTemps.length; i++)
|
||||
{
|
||||
meltingTemps[i] = Smeltery.instance.getLiquifyTemperature(master.getStackInSlot(i));
|
||||
}
|
||||
}
|
||||
|
||||
public void heatItems ()
|
||||
{
|
||||
if (fuelTicks > 0)
|
||||
{
|
||||
boolean hasUse = false;
|
||||
for (int i = 0; i < meltingTemps.length; i++)
|
||||
{
|
||||
fuelTicks--;
|
||||
if (fuelTicks <= 0)
|
||||
break;
|
||||
|
||||
ItemStack slot = master.getStackInSlot(i);
|
||||
if (meltingTemps[i] > 20 && slot != null)
|
||||
{
|
||||
hasUse = true;
|
||||
if (activeTemps[i] < maxTemp && activeTemps[i] < meltingTemps[i])
|
||||
{
|
||||
activeTemps[i] += 1;
|
||||
}
|
||||
else if (activeTemps[i] >= meltingTemps[i] && !world.isRemote)
|
||||
{
|
||||
FluidStack result = getResultFor(slot);
|
||||
if (result != null)
|
||||
{
|
||||
if (multitank.addFluidToTank(result, false))
|
||||
{
|
||||
master.setInventorySlotContents(i, null);
|
||||
activeTemps[i] = 20;
|
||||
ArrayList alloys = Smeltery.mixMetals(multitank.fluidlist);
|
||||
for (int al = 0; al < alloys.size(); al++)
|
||||
{
|
||||
FluidStack liquid = (FluidStack) alloys.get(al);
|
||||
multitank.addFluidToTank(liquid, true);
|
||||
}
|
||||
master.markDirty();
|
||||
master.setUpdateFluids();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
activeTemps[i] = 20;
|
||||
}
|
||||
inUse = hasUse;
|
||||
}
|
||||
}
|
||||
|
||||
void updateFuelGague ()
|
||||
{
|
||||
if (activeLavaTank == null || fuelTicks > 0 || structure.lavaTanks.size() < 1)
|
||||
return;
|
||||
|
||||
if (!world.blockExists(activeLavaTank.x, activeLavaTank.y, activeLavaTank.z))
|
||||
{
|
||||
fuelAmount = 0;
|
||||
fuelGague = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
TileEntity tankContainer = world.getTileEntity(activeLavaTank.x, activeLavaTank.y, activeLavaTank.z);
|
||||
if (tankContainer == null)
|
||||
{
|
||||
fuelAmount = 0;
|
||||
fuelGague = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (tankContainer instanceof IFluidHandler && inUse)
|
||||
{
|
||||
FluidStack liquid = ((IFluidHandler) tankContainer).drain(ForgeDirection.DOWN, drainFuelAmount(), false);
|
||||
if (liquid != null && liquid.getFluid().getBlock() == Blocks.lava)
|
||||
{
|
||||
liquid = ((IFluidHandler) tankContainer).drain(ForgeDirection.DOWN, drainFuelAmount(), true);
|
||||
fuelTicks += liquid.amount * 15;
|
||||
|
||||
FluidTankInfo[] info = ((IFluidHandler) tankContainer).getTankInfo(ForgeDirection.DOWN);
|
||||
liquid = info[0].fluid;
|
||||
int capacity = info[0].capacity;
|
||||
if (liquid != null)
|
||||
{
|
||||
fuelAmount = liquid.amount;
|
||||
fuelGague = liquid.amount * 52 / capacity;
|
||||
}
|
||||
else
|
||||
{
|
||||
fuelAmount = 0;
|
||||
fuelGague = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
boolean foundTank = false;
|
||||
int iter = 0;
|
||||
while (!foundTank)
|
||||
{
|
||||
CoordTuple possibleTank = structure.lavaTanks.get(iter);
|
||||
TileEntity newTankContainer = world.getTileEntity(possibleTank.x, possibleTank.y, possibleTank.z);
|
||||
if (newTankContainer instanceof IFluidHandler)
|
||||
{
|
||||
FluidStack newliquid = ((IFluidHandler) newTankContainer).drain(ForgeDirection.UNKNOWN, drainFuelAmount(), false);
|
||||
if (newliquid != null && newliquid.getFluid().getBlock() == Blocks.lava && newliquid.amount > 0)
|
||||
{
|
||||
foundTank = true;
|
||||
setActiveLavaTank(possibleTank);
|
||||
iter = structure.lavaTanks.size();
|
||||
|
||||
FluidTankInfo[] info = ((IFluidHandler) tankContainer).getTankInfo(ForgeDirection.DOWN);
|
||||
liquid = info[0].fluid;
|
||||
int capacity = info[0].capacity;
|
||||
if (liquid != null)
|
||||
{
|
||||
fuelAmount = liquid.amount;
|
||||
fuelGague = liquid.amount * 52 / capacity;
|
||||
}
|
||||
else
|
||||
{
|
||||
fuelAmount = 0;
|
||||
fuelGague = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
iter++;
|
||||
if (iter >= structure.lavaTanks.size())
|
||||
foundTank = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setActiveLavaTank (CoordTuple coord)
|
||||
{
|
||||
activeLavaTank = coord;
|
||||
}
|
||||
|
||||
private int drainFuelAmount ()
|
||||
{
|
||||
if (activeTemps.length == 0)
|
||||
return 0;
|
||||
|
||||
int amount = activeTemps.length / 3;
|
||||
if (amount < 150)
|
||||
amount = 150;
|
||||
return amount;
|
||||
}
|
||||
|
||||
public FluidStack getResultFor (ItemStack stack)
|
||||
{
|
||||
return Smeltery.instance.getSmelteryResult(stack);
|
||||
}
|
||||
|
||||
public int getInternalTemperature ()
|
||||
{
|
||||
return maxTemp;
|
||||
}
|
||||
|
||||
public int getTempForSlot (int slot)
|
||||
{
|
||||
return activeTemps[slot];
|
||||
}
|
||||
|
||||
public int getMeltingPointForSlot (int slot)
|
||||
{
|
||||
return meltingTemps[slot];
|
||||
}
|
||||
|
||||
public int getScaledFuelGague (int scale)
|
||||
{
|
||||
int ret = (fuelGague * scale) / 52;
|
||||
if (ret < 1)
|
||||
ret = 1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* NBT */
|
||||
@Override
|
||||
public void readNetworkNBT (NBTTagCompound tags)
|
||||
{
|
||||
activeTemps = tags.getIntArray("Temperature");
|
||||
meltingTemps = tags.getIntArray("Melting");
|
||||
fuelAmount = tags.getInteger("Fuel");
|
||||
int[] tank = tags.getIntArray("LavaTank");
|
||||
if (tank.length > 0)
|
||||
activeLavaTank = new CoordTuple(tank[0], tank[1], tank[2]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeNetworkNBT (NBTTagCompound tags)
|
||||
{
|
||||
tags.setIntArray("Temperature", activeTemps);
|
||||
tags.setIntArray("Melting", meltingTemps);
|
||||
tags.setInteger("Fuel", fuelAmount);
|
||||
if (activeLavaTank != null)
|
||||
tags.setIntArray("LavaTank", new int[] { activeLavaTank.x, activeLavaTank.y, activeLavaTank.z });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
package tconstruct.smeltery.component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import mantle.blocks.iface.IServantLogic;
|
||||
import mantle.world.CoordTuple;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagIntArray;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import tconstruct.library.component.TankLayerScan;
|
||||
import tconstruct.smeltery.TinkerSmeltery;
|
||||
|
||||
public class SmelteryScan extends TankLayerScan
|
||||
{
|
||||
public ArrayList<CoordTuple> lavaTanks = new ArrayList<CoordTuple>();
|
||||
|
||||
public SmelteryScan(TileEntity te, Block... id)
|
||||
{
|
||||
super(te, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkValidStructure ()
|
||||
{
|
||||
lavaTanks.clear();
|
||||
super.checkValidStructure();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkAir (int x, int y, int z)
|
||||
{
|
||||
Block block = world.getBlock(x, y, z);
|
||||
if (block == null || world.isAirBlock(x, y, z) || block == TinkerSmeltery.tankAir)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkServant (int x, int y, int z)
|
||||
{
|
||||
Block block = world.getBlock(x, y, z);
|
||||
if (block == null || world.isAirBlock(x, y, z) || !isValidBlock(x, y, z))
|
||||
return false;
|
||||
|
||||
if (!block.hasTileEntity(world.getBlockMetadata(x, y, z)))
|
||||
return false;
|
||||
|
||||
TileEntity be = world.getTileEntity(x, y, z);
|
||||
if (be instanceof IServantLogic)
|
||||
{
|
||||
boolean ret = ((IServantLogic) be).setPotentialMaster(this.imaster, this.world, x, y, z);
|
||||
if (ret && block == TinkerSmeltery.lavaTank)
|
||||
lavaTanks.add(new CoordTuple(x, y, z));
|
||||
return ret;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finalizeStructure ()
|
||||
{
|
||||
super.finalizeStructure();
|
||||
if (lavaTanks.size() < 1)
|
||||
completeStructure = false;
|
||||
else
|
||||
{
|
||||
for (CoordTuple coord : airCoords)
|
||||
{
|
||||
if (world.getBlock(coord.x, coord.y, coord.z) != TinkerSmeltery.tankAir)
|
||||
{
|
||||
world.setBlock(coord.x, coord.y, coord.z, TinkerSmeltery.tankAir);
|
||||
IServantLogic servant = (IServantLogic) world.getTileEntity(coord.x, coord.y, coord.z);
|
||||
servant.verifyMaster(imaster, world, master.xCoord, master.yCoord, master.zCoord);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void invalidateStructure ()
|
||||
{
|
||||
super.invalidateStructure();
|
||||
for (CoordTuple coord : airCoords)
|
||||
{
|
||||
TileEntity servant = world.getTileEntity(coord.x, coord.y, coord.z);
|
||||
if (servant instanceof IServantLogic)
|
||||
((IServantLogic) servant).invalidateMaster(imaster, world, master.xCoord, master.yCoord, master.zCoord);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void invalidateBlocksAbove (int height)
|
||||
{
|
||||
for (CoordTuple coord : airCoords)
|
||||
{
|
||||
if (coord.y < height)
|
||||
continue;
|
||||
|
||||
TileEntity servant = world.getTileEntity(coord.x, coord.y, coord.z);
|
||||
if (servant instanceof IServantLogic)
|
||||
((IServantLogic) servant).invalidateMaster(imaster, world, master.xCoord, master.yCoord, master.zCoord);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup ()
|
||||
{
|
||||
super.cleanup();
|
||||
Iterator i = airCoords.iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
CoordTuple coord = (CoordTuple) i.next();
|
||||
TileEntity te = world.getTileEntity(coord.x, coord.y, coord.z);
|
||||
if (te != null && te instanceof IServantLogic)
|
||||
{
|
||||
((IServantLogic) te).invalidateMaster(imaster, world, master.xCoord, master.yCoord, master.zCoord);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sync lava tanks for fuel values
|
||||
@Override
|
||||
public void readNetworkNBT (NBTTagCompound tags)
|
||||
{
|
||||
super.readNetworkNBT(tags);
|
||||
|
||||
NBTTagList tanks = tags.getTagList("Tanks", 10);
|
||||
if (tanks != null)
|
||||
{
|
||||
lavaTanks.clear();
|
||||
|
||||
for (int i = 0; i < tanks.tagCount(); ++i)
|
||||
{
|
||||
int[] coord = tanks.func_150306_c(i);
|
||||
layerAirCoords.add(new CoordTuple(coord[0], coord[1], coord[2]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeNetworkNBT (NBTTagCompound tags)
|
||||
{
|
||||
super.writeNetworkNBT(tags);
|
||||
|
||||
NBTTagList tanks = new NBTTagList();
|
||||
for (CoordTuple coord : lavaTanks)
|
||||
{
|
||||
tanks.appendTag(new NBTTagIntArray(new int[] { coord.x, coord.y, coord.z }));
|
||||
}
|
||||
tags.setTag("Tanks", tanks);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package tconstruct.smeltery.component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import tconstruct.library.component.MultiFluidTank;
|
||||
|
||||
public class TankAirComponent extends MultiFluidTank
|
||||
{
|
||||
public TankAirComponent()
|
||||
{
|
||||
}
|
||||
|
||||
public TankAirComponent(int i)
|
||||
{
|
||||
super(i);
|
||||
}
|
||||
|
||||
public void overrideFluids (ArrayList<FluidStack> fluids)
|
||||
{
|
||||
fluidlist = fluids;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user