2015-08-29 14:33:25 +02:00
|
|
|
/*
|
2016-05-16 22:52:27 +02:00
|
|
|
* This file ("TileEntityCanolaPress.java") is part of the Actually Additions mod for Minecraft.
|
2015-08-29 14:33:25 +02:00
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-05-16 22:52:27 +02:00
|
|
|
* http://ellpeck.de/actaddlicense
|
2015-08-29 14:33:25 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2017-01-01 16:23:26 +01:00
|
|
|
* © 2015-2017 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.tile;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2016-01-29 17:38:31 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.fluids.InitFluids;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.items.InitItems;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems;
|
2018-08-10 05:04:07 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
|
2016-11-16 16:59:00 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
2016-05-06 23:23:29 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.Util;
|
2015-05-20 22:39:43 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2021-02-26 22:15:48 +01:00
|
|
|
import net.minecraft.nbt.CompoundNBT;
|
2016-01-07 19:47:53 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-11-26 08:58:42 +01:00
|
|
|
import net.minecraftforge.energy.IEnergyStorage;
|
2016-11-26 21:32:27 +01:00
|
|
|
import net.minecraftforge.fluids.FluidStack;
|
|
|
|
import net.minecraftforge.fluids.FluidTank;
|
2021-02-26 22:15:48 +01:00
|
|
|
import net.minecraftforge.fml.relauncher.OnlyIn;
|
2016-05-19 20:05:12 +02:00
|
|
|
|
2018-08-10 05:04:07 +02:00
|
|
|
public class TileEntityCanolaPress extends TileEntityInventoryBase implements ISharingFluidHandler {
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2016-01-23 22:58:40 +01:00
|
|
|
public static final int PRODUCE = 80;
|
2015-12-01 19:48:09 +01:00
|
|
|
public static final int ENERGY_USE = 35;
|
|
|
|
private static final int TIME = 30;
|
2016-11-26 20:43:50 +01:00
|
|
|
public final CustomEnergyStorage storage = new CustomEnergyStorage(40000, 100, 0);
|
2018-08-10 05:04:07 +02:00
|
|
|
public final FluidTank tank = new FluidTank(2 * Util.BUCKET) {
|
2016-06-05 02:16:52 +02:00
|
|
|
@Override
|
2018-08-10 05:04:07 +02:00
|
|
|
public boolean canFill() {
|
2016-06-05 02:16:52 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
2015-05-20 22:39:43 +02:00
|
|
|
public int currentProcessTime;
|
2015-10-03 10:16:18 +02:00
|
|
|
private int lastEnergyStored;
|
|
|
|
private int lastTankAmount;
|
2015-07-02 04:21:21 +02:00
|
|
|
private int lastProcessTime;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2018-08-10 05:04:07 +02:00
|
|
|
public TileEntityCanolaPress() {
|
2016-05-06 23:23:29 +02:00
|
|
|
super(1, "canolaPress");
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2018-08-10 05:04:07 +02:00
|
|
|
public int getTankScaled(int i) {
|
|
|
|
return this.tank.getFluidAmount() * i / this.tank.getCapacity();
|
2015-12-01 19:48:09 +01:00
|
|
|
}
|
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2018-08-10 05:04:07 +02:00
|
|
|
public int getProcessScaled(int i) {
|
|
|
|
return this.currentProcessTime * i / TIME;
|
2015-12-01 19:48:09 +01:00
|
|
|
}
|
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2018-08-10 05:04:07 +02:00
|
|
|
public int getEnergyScaled(int i) {
|
|
|
|
return this.storage.getEnergyStored() * i / this.storage.getMaxEnergyStored();
|
2015-12-01 19:48:09 +01:00
|
|
|
}
|
|
|
|
|
2016-02-01 20:32:49 +01:00
|
|
|
@Override
|
2021-02-26 22:15:48 +01:00
|
|
|
public void writeSyncableNBT(CompoundNBT compound, NBTType type) {
|
2018-08-10 05:04:07 +02:00
|
|
|
if (type != NBTType.SAVE_BLOCK) {
|
2016-07-02 15:01:46 +02:00
|
|
|
compound.setInteger("ProcessTime", this.currentProcessTime);
|
|
|
|
}
|
2016-02-01 20:32:49 +01:00
|
|
|
this.storage.writeToNBT(compound);
|
|
|
|
this.tank.writeToNBT(compound);
|
2016-07-02 15:01:46 +02:00
|
|
|
super.writeSyncableNBT(compound, type);
|
2016-02-01 20:32:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-02-26 22:15:48 +01:00
|
|
|
public void readSyncableNBT(CompoundNBT compound, NBTType type) {
|
2018-08-10 05:04:07 +02:00
|
|
|
if (type != NBTType.SAVE_BLOCK) {
|
2016-07-02 15:01:46 +02:00
|
|
|
this.currentProcessTime = compound.getInteger("ProcessTime");
|
|
|
|
}
|
2016-02-01 20:32:49 +01:00
|
|
|
this.storage.readFromNBT(compound);
|
|
|
|
this.tank.readFromNBT(compound);
|
2016-07-02 15:01:46 +02:00
|
|
|
super.readSyncableNBT(compound, type);
|
2016-02-01 20:32:49 +01:00
|
|
|
}
|
|
|
|
|
2015-05-20 22:39:43 +02:00
|
|
|
@Override
|
2018-08-10 05:04:07 +02:00
|
|
|
public void updateEntity() {
|
2015-11-18 23:11:24 +01:00
|
|
|
super.updateEntity();
|
2018-08-10 05:04:07 +02:00
|
|
|
if (!this.world.isRemote) {
|
2019-02-27 19:53:05 +01:00
|
|
|
if (isCanola(this.inv.getStackInSlot(0)) && PRODUCE <= this.tank.getCapacity() - this.tank.getFluidAmount()) {
|
2018-08-10 05:04:07 +02:00
|
|
|
if (this.storage.getEnergyStored() >= ENERGY_USE) {
|
2015-06-13 12:52:22 +02:00
|
|
|
this.currentProcessTime++;
|
2016-11-23 18:10:55 +01:00
|
|
|
this.storage.extractEnergyInternal(ENERGY_USE, false);
|
2018-08-10 05:04:07 +02:00
|
|
|
if (this.currentProcessTime >= TIME) {
|
2015-06-13 12:52:22 +02:00
|
|
|
this.currentProcessTime = 0;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2018-06-23 01:39:30 +02:00
|
|
|
this.inv.setStackInSlot(0, StackUtil.shrink(this.inv.getStackInSlot(0), 1));
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2016-06-05 02:16:52 +02:00
|
|
|
this.tank.fillInternal(new FluidStack(InitFluids.fluidCanolaOil, PRODUCE), true);
|
2015-06-13 12:52:22 +02:00
|
|
|
this.markDirty();
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
2018-08-10 05:04:07 +02:00
|
|
|
} else {
|
2015-10-02 16:48:01 +02:00
|
|
|
this.currentProcessTime = 0;
|
|
|
|
}
|
2015-07-02 04:21:21 +02:00
|
|
|
|
2018-08-10 05:04:07 +02:00
|
|
|
if ((this.storage.getEnergyStored() != this.lastEnergyStored || this.tank.getFluidAmount() != this.lastTankAmount | this.currentProcessTime != this.lastProcessTime) && this.sendUpdateWithInterval()) {
|
2015-07-02 04:21:21 +02:00
|
|
|
this.lastEnergyStored = this.storage.getEnergyStored();
|
|
|
|
this.lastProcessTime = this.currentProcessTime;
|
|
|
|
this.lastTankAmount = this.tank.getFluidAmount();
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-01 17:49:55 +01:00
|
|
|
@Override
|
2018-08-10 05:04:07 +02:00
|
|
|
public IAcceptor getAcceptor() {
|
|
|
|
return (slot, stack, automation) -> slot == 0 && isCanola(stack);
|
2016-02-01 17:49:55 +01:00
|
|
|
}
|
|
|
|
|
2018-08-10 05:04:07 +02:00
|
|
|
public static boolean isCanola(ItemStack stack) {
|
2018-06-23 01:39:30 +02:00
|
|
|
return stack.getItem() == InitItems.itemMisc && stack.getMetadata() == TheMiscItems.CANOLA.ordinal();
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-08-10 05:04:07 +02:00
|
|
|
public IRemover getRemover() {
|
|
|
|
return (slot, automation) -> !automation;
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
2016-06-05 02:16:52 +02:00
|
|
|
@Override
|
2018-08-10 05:04:07 +02:00
|
|
|
public FluidTank getFluidHandler(EnumFacing facing) {
|
2016-12-05 14:16:53 +01:00
|
|
|
return this.tank;
|
2016-06-05 02:16:52 +02:00
|
|
|
}
|
2016-06-10 21:52:37 +02:00
|
|
|
|
|
|
|
@Override
|
2018-08-10 05:04:07 +02:00
|
|
|
public int getMaxFluidAmountToSplitShare() {
|
2016-08-31 20:16:36 +02:00
|
|
|
return this.tank.getFluidAmount();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-08-10 05:04:07 +02:00
|
|
|
public boolean doesShareFluid() {
|
2016-08-31 20:16:36 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-08-10 05:04:07 +02:00
|
|
|
public EnumFacing[] getFluidShareSides() {
|
2016-08-31 20:16:36 +02:00
|
|
|
return EnumFacing.values();
|
|
|
|
}
|
2016-11-26 08:58:42 +01:00
|
|
|
|
|
|
|
@Override
|
2018-08-10 05:04:07 +02:00
|
|
|
public IEnergyStorage getEnergyStorage(EnumFacing facing) {
|
2016-11-26 08:58:42 +01:00
|
|
|
return this.storage;
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|