mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
291 lines
7.3 KiB
Java
291 lines
7.3 KiB
Java
package com.hbm.tileentity.machine.oil;
|
|
|
|
import java.util.List;
|
|
|
|
import com.hbm.blocks.ModBlocks;
|
|
import com.hbm.inventory.UpgradeManager;
|
|
import com.hbm.inventory.container.ContainerSolidifier;
|
|
import com.hbm.inventory.fluid.Fluids;
|
|
import com.hbm.inventory.fluid.tank.FluidTank;
|
|
import com.hbm.inventory.gui.GUISolidifier;
|
|
import com.hbm.inventory.recipes.SolidificationRecipes;
|
|
import com.hbm.items.machine.ItemMachineUpgrade.UpgradeType;
|
|
import com.hbm.lib.Library;
|
|
import com.hbm.tileentity.IGUIProvider;
|
|
import com.hbm.tileentity.IUpgradeInfoProvider;
|
|
import com.hbm.tileentity.TileEntityMachineBase;
|
|
import com.hbm.util.CompatEnergyControl;
|
|
import com.hbm.util.I18nUtil;
|
|
import com.hbm.util.Tuple.Pair;
|
|
import com.hbm.util.fauxpointtwelve.DirPos;
|
|
|
|
import api.hbm.energymk2.IEnergyReceiverMK2;
|
|
import api.hbm.fluid.IFluidStandardReceiver;
|
|
import api.hbm.tile.IInfoProviderEC;
|
|
import cpw.mods.fml.relauncher.Side;
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
import io.netty.buffer.ByteBuf;
|
|
import net.minecraft.client.gui.GuiScreen;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.inventory.Container;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
import net.minecraft.util.AxisAlignedBB;
|
|
import net.minecraft.util.EnumChatFormatting;
|
|
import net.minecraft.world.World;
|
|
|
|
public class TileEntityMachineSolidifier extends TileEntityMachineBase implements IEnergyReceiverMK2, IFluidStandardReceiver, IGUIProvider, IUpgradeInfoProvider, IInfoProviderEC {
|
|
|
|
public long power;
|
|
public static final long maxPower = 100000;
|
|
public static final int usageBase = 500;
|
|
public int usage;
|
|
public int progress;
|
|
public static final int processTimeBase = 100;
|
|
public int processTime;
|
|
|
|
public FluidTank tank;
|
|
|
|
public TileEntityMachineSolidifier() {
|
|
super(5);
|
|
tank = new FluidTank(Fluids.NONE, 24_000);
|
|
}
|
|
|
|
@Override
|
|
public String getName() {
|
|
return "container.machineSolidifier";
|
|
}
|
|
|
|
@Override
|
|
public void updateEntity() {
|
|
|
|
if(!worldObj.isRemote) {
|
|
this.power = Library.chargeTEFromItems(slots, 1, power, maxPower);
|
|
tank.setType(4, slots);
|
|
|
|
this.updateConnections();
|
|
|
|
UpgradeManager.eval(slots, 2, 3);
|
|
int speed = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3);
|
|
int power = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3);
|
|
|
|
this.processTime = processTimeBase - (processTimeBase / 4) * speed;
|
|
this.usage = (usageBase + (usageBase * speed)) / (power + 1);
|
|
|
|
if(this.canProcess())
|
|
this.process();
|
|
else
|
|
this.progress = 0;
|
|
|
|
this.networkPackNT(50);
|
|
}
|
|
}
|
|
|
|
private void updateConnections() {
|
|
for(DirPos pos : getConPos()) {
|
|
this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
|
|
this.trySubscribe(tank.getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
|
|
}
|
|
}
|
|
|
|
private DirPos[] getConPos() {
|
|
return new DirPos[] {
|
|
new DirPos(xCoord, yCoord + 4, zCoord, Library.POS_Y),
|
|
new DirPos(xCoord, yCoord - 1, zCoord, Library.NEG_Y),
|
|
new DirPos(xCoord + 2, yCoord + 1, zCoord, Library.POS_X),
|
|
new DirPos(xCoord - 2, yCoord + 1, zCoord, Library.NEG_X),
|
|
new DirPos(xCoord, yCoord + 1, zCoord + 2, Library.POS_Z),
|
|
new DirPos(xCoord, yCoord + 1, zCoord - 2, Library.NEG_Z)
|
|
};
|
|
}
|
|
|
|
@Override
|
|
public boolean canExtractItem(int slot, ItemStack stack, int side) {
|
|
return slot == 0;
|
|
}
|
|
|
|
@Override
|
|
public int[] getAccessibleSlotsFromSide(int side) {
|
|
return new int[] { 0 };
|
|
}
|
|
|
|
public boolean canProcess() {
|
|
|
|
if(this.power < usage)
|
|
return false;
|
|
|
|
Pair<Integer, ItemStack> out = SolidificationRecipes.getOutput(tank.getTankType());
|
|
|
|
if(out == null)
|
|
return false;
|
|
|
|
int req = out.getKey();
|
|
ItemStack stack = out.getValue();
|
|
|
|
if(req > tank.getFill())
|
|
return false;
|
|
|
|
if(slots[0] != null) {
|
|
|
|
if(slots[0].getItem() != stack.getItem())
|
|
return false;
|
|
|
|
if(slots[0].getItemDamage() != stack.getItemDamage())
|
|
return false;
|
|
|
|
if(slots[0].stackSize + stack.stackSize > slots[0].getMaxStackSize())
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public void process() {
|
|
|
|
this.power -= usage;
|
|
|
|
progress++;
|
|
|
|
if(progress >= processTime) {
|
|
|
|
Pair<Integer, ItemStack> out = SolidificationRecipes.getOutput(tank.getTankType());
|
|
int req = out.getKey();
|
|
ItemStack stack = out.getValue();
|
|
tank.setFill(tank.getFill() - req);
|
|
|
|
if(slots[0] == null) {
|
|
slots[0] = stack.copy();
|
|
} else {
|
|
slots[0].stackSize += stack.stackSize;
|
|
}
|
|
|
|
progress = 0;
|
|
|
|
this.markDirty();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void serialize(ByteBuf buf) {
|
|
super.serialize(buf);
|
|
buf.writeLong(this.power);
|
|
buf.writeInt(this.progress);
|
|
buf.writeInt(this.usage);
|
|
buf.writeInt(this.processTime);
|
|
tank.serialize(buf);
|
|
}
|
|
|
|
@Override
|
|
public void deserialize(ByteBuf buf) {
|
|
super.deserialize(buf);
|
|
this.power = buf.readLong();
|
|
this.progress = buf.readInt();
|
|
this.usage = buf.readInt();
|
|
this.processTime = buf.readInt();
|
|
tank.deserialize(buf);
|
|
}
|
|
|
|
@Override
|
|
public void readFromNBT(NBTTagCompound nbt) {
|
|
super.readFromNBT(nbt);
|
|
tank.readFromNBT(nbt, "tank");
|
|
}
|
|
|
|
@Override
|
|
public void writeToNBT(NBTTagCompound nbt) {
|
|
super.writeToNBT(nbt);
|
|
tank.writeToNBT(nbt, "tank");
|
|
}
|
|
|
|
@Override
|
|
public void setPower(long power) {
|
|
this.power = power;
|
|
}
|
|
|
|
@Override
|
|
public long getPower() {
|
|
return power;
|
|
}
|
|
|
|
@Override
|
|
public long getMaxPower() {
|
|
return maxPower;
|
|
}
|
|
|
|
AxisAlignedBB bb = null;
|
|
|
|
@Override
|
|
public AxisAlignedBB getRenderBoundingBox() {
|
|
|
|
if(bb == null) {
|
|
bb = AxisAlignedBB.getBoundingBox(
|
|
xCoord - 1,
|
|
yCoord,
|
|
zCoord - 1,
|
|
xCoord + 2,
|
|
yCoord + 4,
|
|
zCoord + 2
|
|
);
|
|
}
|
|
|
|
return bb;
|
|
}
|
|
|
|
@Override
|
|
@SideOnly(Side.CLIENT)
|
|
public double getMaxRenderDistanceSquared() {
|
|
return 65536.0D;
|
|
}
|
|
|
|
@Override
|
|
public FluidTank[] getReceivingTanks() {
|
|
return new FluidTank[] { tank };
|
|
}
|
|
|
|
@Override
|
|
public FluidTank[] getAllTanks() {
|
|
return new FluidTank[] { tank };
|
|
}
|
|
|
|
@Override
|
|
public Container provideContainer(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
|
return new ContainerSolidifier(player.inventory, this);
|
|
}
|
|
|
|
@Override
|
|
@SideOnly(Side.CLIENT)
|
|
public GuiScreen provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
|
return new GUISolidifier(player.inventory, this);
|
|
}
|
|
|
|
@Override
|
|
public boolean canProvideInfo(UpgradeType type, int level, boolean extendedInfo) {
|
|
return type == UpgradeType.SPEED || type == UpgradeType.POWER;
|
|
}
|
|
|
|
@Override
|
|
public void provideInfo(UpgradeType type, int level, List<String> info, boolean extendedInfo) {
|
|
info.add(IUpgradeInfoProvider.getStandardLabel(ModBlocks.machine_solidifier));
|
|
if(type == UpgradeType.SPEED) {
|
|
info.add(EnumChatFormatting.GREEN + I18nUtil.resolveKey(this.KEY_DELAY, "-" + (level * 25) + "%"));
|
|
info.add(EnumChatFormatting.RED + I18nUtil.resolveKey(this.KEY_CONSUMPTION, "+" + (level * 100) + "%"));
|
|
}
|
|
if(type == UpgradeType.POWER) {
|
|
info.add(EnumChatFormatting.GREEN + I18nUtil.resolveKey(this.KEY_CONSUMPTION, "-" + (100 - 100 / (level + 1)) + "%"));
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public int getMaxLevel(UpgradeType type) {
|
|
if(type == UpgradeType.SPEED) return 3;
|
|
if(type == UpgradeType.POWER) return 3;
|
|
return 0;
|
|
}
|
|
|
|
@Override
|
|
public void provideExtraInfo(NBTTagCompound data) {
|
|
data.setBoolean(CompatEnergyControl.B_ACTIVE, this.progress > 0);
|
|
data.setDouble(CompatEnergyControl.D_CONSUMPTION_HE, this.usage);
|
|
}
|
|
}
|