mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
the commit
This commit is contained in:
parent
3323356c73
commit
32d3b6722f
@ -2,6 +2,7 @@ package com.hbm.tileentity.machine.oil;
|
|||||||
|
|
||||||
import com.hbm.handler.pollution.PollutionHandler;
|
import com.hbm.handler.pollution.PollutionHandler;
|
||||||
import com.hbm.handler.pollution.PollutionHandler.PollutionType;
|
import com.hbm.handler.pollution.PollutionHandler.PollutionType;
|
||||||
|
import com.hbm.handler.CompatHandler.OCComponent;
|
||||||
import com.hbm.inventory.FluidStack;
|
import com.hbm.inventory.FluidStack;
|
||||||
import com.hbm.inventory.container.ContainerMachineCoker;
|
import com.hbm.inventory.container.ContainerMachineCoker;
|
||||||
import com.hbm.inventory.fluid.Fluids;
|
import com.hbm.inventory.fluid.Fluids;
|
||||||
@ -18,9 +19,14 @@ import com.hbm.util.fauxpointtwelve.DirPos;
|
|||||||
|
|
||||||
import api.hbm.fluid.IFluidStandardTransceiver;
|
import api.hbm.fluid.IFluidStandardTransceiver;
|
||||||
import api.hbm.tile.IHeatSource;
|
import api.hbm.tile.IHeatSource;
|
||||||
|
import cpw.mods.fml.common.Optional;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import li.cil.oc.api.machine.Arguments;
|
||||||
|
import li.cil.oc.api.machine.Callback;
|
||||||
|
import li.cil.oc.api.machine.Context;
|
||||||
|
import li.cil.oc.api.network.SimpleComponent;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.inventory.Container;
|
import net.minecraft.inventory.Container;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
@ -29,16 +35,17 @@ import net.minecraft.tileentity.TileEntity;
|
|||||||
import net.minecraft.util.AxisAlignedBB;
|
import net.minecraft.util.AxisAlignedBB;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class TileEntityMachineCoker extends TileEntityMachineBase implements IFluidStandardTransceiver, IGUIProvider, IFluidCopiable {
|
@Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "opencomputers")})
|
||||||
|
public class TileEntityMachineCoker extends TileEntityMachineBase implements SimpleComponent, OCComponent, IFluidStandardTransceiver, IGUIProvider, IFluidCopiable {
|
||||||
|
|
||||||
public boolean wasOn;
|
public boolean wasOn;
|
||||||
public int progress;
|
public int progress;
|
||||||
public static int processTime = 20_000;
|
public static int processTime = 20_000;
|
||||||
|
|
||||||
public int heat;
|
public int heat;
|
||||||
public static int maxHeat = 100_000;
|
public static int maxHeat = 100_000;
|
||||||
public static double diffusion = 0.25D;
|
public static double diffusion = 0.25D;
|
||||||
|
|
||||||
public FluidTank[] tanks;
|
public FluidTank[] tanks;
|
||||||
|
|
||||||
public TileEntityMachineCoker() {
|
public TileEntityMachineCoker() {
|
||||||
@ -55,7 +62,7 @@ public class TileEntityMachineCoker extends TileEntityMachineBase implements IFl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity() {
|
public void updateEntity() {
|
||||||
|
|
||||||
if(!worldObj.isRemote) {
|
if(!worldObj.isRemote) {
|
||||||
|
|
||||||
this.tryPullHeat();
|
this.tryPullHeat();
|
||||||
@ -66,26 +73,26 @@ public class TileEntityMachineCoker extends TileEntityMachineBase implements IFl
|
|||||||
this.trySubscribe(tanks[0].getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
|
this.trySubscribe(tanks[0].getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.wasOn = false;
|
this.wasOn = false;
|
||||||
|
|
||||||
if(canProcess()) {
|
if(canProcess()) {
|
||||||
int burn = heat / 100;
|
int burn = heat / 100;
|
||||||
|
|
||||||
if(burn > 0) {
|
if(burn > 0) {
|
||||||
this.wasOn = true;
|
this.wasOn = true;
|
||||||
this.progress += burn;
|
this.progress += burn;
|
||||||
this.heat -= burn;
|
this.heat -= burn;
|
||||||
|
|
||||||
if(progress >= processTime) {
|
if(progress >= processTime) {
|
||||||
this.markChanged();
|
this.markChanged();
|
||||||
progress -= this.processTime;
|
progress -= this.processTime;
|
||||||
|
|
||||||
Triplet<Integer, ItemStack, FluidStack> recipe = CokerRecipes.getOutput(tanks[0].getTankType());
|
Triplet<Integer, ItemStack, FluidStack> recipe = CokerRecipes.getOutput(tanks[0].getTankType());
|
||||||
int fillReq = recipe.getX();
|
int fillReq = recipe.getX();
|
||||||
ItemStack output = recipe.getY();
|
ItemStack output = recipe.getY();
|
||||||
FluidStack byproduct = recipe.getZ();
|
FluidStack byproduct = recipe.getZ();
|
||||||
|
|
||||||
if(output != null) {
|
if(output != null) {
|
||||||
if(slots[1] == null) {
|
if(slots[1] == null) {
|
||||||
slots[1] = output.copy();
|
slots[1] = output.copy();
|
||||||
@ -93,25 +100,25 @@ public class TileEntityMachineCoker extends TileEntityMachineBase implements IFl
|
|||||||
slots[1].stackSize += output.stackSize;
|
slots[1].stackSize += output.stackSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(byproduct != null) {
|
if(byproduct != null) {
|
||||||
tanks[1].setFill(tanks[1].getFill() + byproduct.fill);
|
tanks[1].setFill(tanks[1].getFill() + byproduct.fill);
|
||||||
}
|
}
|
||||||
|
|
||||||
tanks[0].setFill(tanks[0].getFill() - fillReq);
|
tanks[0].setFill(tanks[0].getFill() - fillReq);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(wasOn && worldObj.getTotalWorldTime() % 5 == 0) PollutionHandler.incrementPollution(worldObj, xCoord, yCoord, zCoord, PollutionType.SOOT, PollutionHandler.SOOT_PER_SECOND * 5);
|
if(wasOn && worldObj.getTotalWorldTime() % 5 == 0) PollutionHandler.incrementPollution(worldObj, xCoord, yCoord, zCoord, PollutionType.SOOT, PollutionHandler.SOOT_PER_SECOND * 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(DirPos pos : getConPos()) {
|
for(DirPos pos : getConPos()) {
|
||||||
if(this.tanks[1].getFill() > 0) this.sendFluid(tanks[1], worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
|
if(this.tanks[1].getFill() > 0) this.sendFluid(tanks[1], worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.networkPackNT(25);
|
this.networkPackNT(25);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if(this.wasOn) {
|
if(this.wasOn) {
|
||||||
|
|
||||||
if(worldObj.getTotalWorldTime() % 2 == 0) {
|
if(worldObj.getTotalWorldTime() % 2 == 0) {
|
||||||
@ -134,7 +141,7 @@ public class TileEntityMachineCoker extends TileEntityMachineBase implements IFl
|
|||||||
|
|
||||||
|
|
||||||
public DirPos[] getConPos() {
|
public DirPos[] getConPos() {
|
||||||
|
|
||||||
return new DirPos[] {
|
return new DirPos[] {
|
||||||
new DirPos(xCoord + 2, yCoord, zCoord + 1, Library.POS_X),
|
new DirPos(xCoord + 2, yCoord, zCoord + 1, Library.POS_X),
|
||||||
new DirPos(xCoord + 2, yCoord, zCoord - 1, Library.POS_X),
|
new DirPos(xCoord + 2, yCoord, zCoord - 1, Library.POS_X),
|
||||||
@ -146,27 +153,27 @@ public class TileEntityMachineCoker extends TileEntityMachineBase implements IFl
|
|||||||
new DirPos(xCoord - 1, yCoord, zCoord - 2, Library.NEG_Z)
|
new DirPos(xCoord - 1, yCoord, zCoord - 2, Library.NEG_Z)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canProcess() {
|
public boolean canProcess() {
|
||||||
Triplet<Integer, ItemStack, FluidStack> recipe = CokerRecipes.getOutput(tanks[0].getTankType());
|
Triplet<Integer, ItemStack, FluidStack> recipe = CokerRecipes.getOutput(tanks[0].getTankType());
|
||||||
|
|
||||||
if(recipe == null) return false;
|
if(recipe == null) return false;
|
||||||
|
|
||||||
int fillReq = recipe.getX();
|
int fillReq = recipe.getX();
|
||||||
ItemStack output = recipe.getY();
|
ItemStack output = recipe.getY();
|
||||||
FluidStack byproduct = recipe.getZ();
|
FluidStack byproduct = recipe.getZ();
|
||||||
|
|
||||||
if(byproduct != null) tanks[1].setTankType(byproduct.type);
|
if(byproduct != null) tanks[1].setTankType(byproduct.type);
|
||||||
|
|
||||||
if(tanks[0].getFill() < fillReq) return false;
|
if(tanks[0].getFill() < fillReq) return false;
|
||||||
if(byproduct != null && byproduct.fill + tanks[1].getFill() > tanks[1].getMaxFill()) return false;
|
if(byproduct != null && byproduct.fill + tanks[1].getFill() > tanks[1].getMaxFill()) return false;
|
||||||
|
|
||||||
if(output != null && slots[1] != null) {
|
if(output != null && slots[1] != null) {
|
||||||
if(output.getItem() != slots[1].getItem()) return false;
|
if(output.getItem() != slots[1].getItem()) return false;
|
||||||
if(output.getItemDamage() != slots[1].getItemDamage()) return false;
|
if(output.getItemDamage() != slots[1].getItemDamage()) return false;
|
||||||
if(output.stackSize + slots[1].stackSize > output.getMaxStackSize()) return false;
|
if(output.stackSize + slots[1].stackSize > output.getMaxStackSize()) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,21 +196,21 @@ public class TileEntityMachineCoker extends TileEntityMachineBase implements IFl
|
|||||||
tanks[0].deserialize(buf);
|
tanks[0].deserialize(buf);
|
||||||
tanks[1].deserialize(buf);
|
tanks[1].deserialize(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void tryPullHeat() {
|
protected void tryPullHeat() {
|
||||||
|
|
||||||
if(this.heat >= this.maxHeat) return;
|
if(this.heat >= this.maxHeat) return;
|
||||||
|
|
||||||
TileEntity con = worldObj.getTileEntity(xCoord, yCoord - 1, zCoord);
|
TileEntity con = worldObj.getTileEntity(xCoord, yCoord - 1, zCoord);
|
||||||
|
|
||||||
if(con instanceof IHeatSource) {
|
if(con instanceof IHeatSource) {
|
||||||
IHeatSource source = (IHeatSource) con;
|
IHeatSource source = (IHeatSource) con;
|
||||||
int diff = source.getHeatStored() - this.heat;
|
int diff = source.getHeatStored() - this.heat;
|
||||||
|
|
||||||
if(diff == 0) {
|
if(diff == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(diff > 0) {
|
if(diff > 0) {
|
||||||
diff = (int) Math.ceil(diff * diffusion);
|
diff = (int) Math.ceil(diff * diffusion);
|
||||||
source.useUpHeat(diff);
|
source.useUpHeat(diff);
|
||||||
@ -213,7 +220,7 @@ public class TileEntityMachineCoker extends TileEntityMachineBase implements IFl
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.heat = Math.max(this.heat - Math.max(this.heat / 1000, 1), 0);
|
this.heat = Math.max(this.heat - Math.max(this.heat / 1000, 1), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,7 +233,7 @@ public class TileEntityMachineCoker extends TileEntityMachineBase implements IFl
|
|||||||
public int[] getAccessibleSlotsFromSide(int side) {
|
public int[] getAccessibleSlotsFromSide(int side) {
|
||||||
return new int[] { 1 };
|
return new int[] { 1 };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT(NBTTagCompound nbt) {
|
public void readFromNBT(NBTTagCompound nbt) {
|
||||||
super.readFromNBT(nbt);
|
super.readFromNBT(nbt);
|
||||||
@ -235,7 +242,7 @@ public class TileEntityMachineCoker extends TileEntityMachineBase implements IFl
|
|||||||
this.progress = nbt.getInteger("prog");
|
this.progress = nbt.getInteger("prog");
|
||||||
this.heat = nbt.getInteger("heat");
|
this.heat = nbt.getInteger("heat");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToNBT(NBTTagCompound nbt) {
|
public void writeToNBT(NBTTagCompound nbt) {
|
||||||
super.writeToNBT(nbt);
|
super.writeToNBT(nbt);
|
||||||
@ -259,12 +266,12 @@ public class TileEntityMachineCoker extends TileEntityMachineBase implements IFl
|
|||||||
public FluidTank[] getReceivingTanks() {
|
public FluidTank[] getReceivingTanks() {
|
||||||
return new FluidTank[] { tanks[0] };
|
return new FluidTank[] { tanks[0] };
|
||||||
}
|
}
|
||||||
|
|
||||||
AxisAlignedBB bb = null;
|
AxisAlignedBB bb = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AxisAlignedBB getRenderBoundingBox() {
|
public AxisAlignedBB getRenderBoundingBox() {
|
||||||
|
|
||||||
if(bb == null) {
|
if(bb == null) {
|
||||||
bb = AxisAlignedBB.getBoundingBox(
|
bb = AxisAlignedBB.getBoundingBox(
|
||||||
xCoord - 2,
|
xCoord - 2,
|
||||||
@ -275,10 +282,10 @@ public class TileEntityMachineCoker extends TileEntityMachineBase implements IFl
|
|||||||
zCoord + 3
|
zCoord + 3
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bb;
|
return bb;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public double getMaxRenderDistanceSquared() {
|
public double getMaxRenderDistanceSquared() {
|
||||||
@ -295,4 +302,60 @@ public class TileEntityMachineCoker extends TileEntityMachineBase implements IFl
|
|||||||
public Object provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
public Object provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||||
return new GUIMachineCoker(player.inventory, this);
|
return new GUIMachineCoker(player.inventory, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Optional.Method(modid = "OpenComputers")
|
||||||
|
public String getComponentName() {
|
||||||
|
return "ntm_coker";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Callback(direct = true)
|
||||||
|
@Optional.Method(modid = "OpenComputers")
|
||||||
|
public Object[] getTypeStored(Context context, Arguments args) {
|
||||||
|
return new Object[] {tanks[0].getTankType().getName(), tanks[1].getTankType().getName()};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Callback(direct = true)
|
||||||
|
@Optional.Method(modid = "OpenComputers")
|
||||||
|
public Object[] getFluidStored(Context context, Arguments args) {
|
||||||
|
return new Object[] {tanks[0].getFill(), tanks[1].getFill()};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Callback(direct = true)
|
||||||
|
@Optional.Method(modid = "OpenComputers")
|
||||||
|
public Object[] getHeat(Context context, Arguments args) {
|
||||||
|
return new Object[] {this.heat};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Callback(direct = true)
|
||||||
|
@Optional.Method(modid = "OpenComputers")
|
||||||
|
public Object[] getInfo(Context context, Arguments args) {
|
||||||
|
return new Object[] {tanks[0].getTankType().getName(), tanks[1].getTankType().getName(), tanks[0].getFill(), tanks[1].getFill(), this.heat};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Optional.Method(modid = "OpenComputers")
|
||||||
|
public String[] methods() {
|
||||||
|
return new String[] {
|
||||||
|
"getFluidStored",
|
||||||
|
"getTypeStored",
|
||||||
|
"getHeat",
|
||||||
|
"getInfo"};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Optional.Method(modid = "OpenComputers")
|
||||||
|
public Object[] invoke(String method, Context context, Arguments args) throws Exception {
|
||||||
|
switch (method) {
|
||||||
|
case "getFluidStored":
|
||||||
|
return getFluidStored(context, args);
|
||||||
|
case "getTypeStored":
|
||||||
|
return getTypeStored(context, args);
|
||||||
|
case "getHeat":
|
||||||
|
return getHeat(context, args);
|
||||||
|
case "getInfo":
|
||||||
|
return getInfo(context, args);
|
||||||
|
}
|
||||||
|
throw new NoSuchMethodException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user