2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.tile;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2016-09-01 22:11:51 +02:00
|
|
|
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
2016-11-21 13:30:38 +01:00
|
|
|
import de.ellpeck.actuallyadditions.api.recipe.OilGenRecipe;
|
2018-04-14 19:54:08 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntListValues;
|
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.nbt.NBTTagCompound;
|
2016-12-18 17:28:29 +01:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2016-01-07 19:04:29 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-11-26 08:58:42 +01:00
|
|
|
import net.minecraftforge.energy.IEnergyStorage;
|
2016-11-21 13:30:38 +01:00
|
|
|
import net.minecraftforge.fluids.Fluid;
|
|
|
|
import net.minecraftforge.fluids.FluidStack;
|
|
|
|
import net.minecraftforge.fluids.FluidTank;
|
2016-06-05 02:16:52 +02:00
|
|
|
import net.minecraftforge.fluids.capability.IFluidHandler;
|
2016-01-07 18:20:59 +01:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public class TileEntityOilGenerator extends TileEntityBase implements ISharingEnergyProvider, ISharingFluidHandler {
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2018-04-14 19:54:08 +02:00
|
|
|
int[] i = ConfigIntListValues.OIL_POWER.getValue();
|
|
|
|
|
2019-02-27 19:53:05 +01:00
|
|
|
public final CustomEnergyStorage storage = new CustomEnergyStorage(50000, 0, Math.max(Math.max(this.i[0], this.i[1]), Math.max(this.i[2], this.i[3])) + 20);
|
2019-05-02 09:10:29 +02:00
|
|
|
public final FluidTank tank = new FluidTank(2 * Util.BUCKET) {
|
2016-06-05 02:16:52 +02:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public boolean canDrain() {
|
2016-06-05 02:16:52 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public boolean canFillFluidType(FluidStack stack) {
|
2018-01-17 19:22:55 +01:00
|
|
|
Fluid fluid = stack == null ? null : stack.getFluid();
|
2016-11-21 13:30:38 +01:00
|
|
|
return fluid != null && getRecipeForFluid(fluid.getName()) != null;
|
2016-06-05 02:16:52 +02:00
|
|
|
}
|
|
|
|
};
|
2016-09-01 22:11:51 +02:00
|
|
|
public int currentEnergyProduce;
|
2015-05-20 22:39:43 +02:00
|
|
|
public int currentBurnTime;
|
2016-11-21 13:30:38 +01:00
|
|
|
public int maxBurnTime;
|
2015-10-03 10:16:18 +02:00
|
|
|
private int lastEnergy;
|
|
|
|
private int lastTank;
|
2015-07-02 04:21:21 +02:00
|
|
|
private int lastBurnTime;
|
2016-11-21 13:30:38 +01:00
|
|
|
private int lastMaxBurnTime;
|
2016-09-01 22:11:51 +02:00
|
|
|
private int lastEnergyProduce;
|
2016-11-28 13:02:42 +01:00
|
|
|
private int lastCompare;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public TileEntityOilGenerator() {
|
2016-05-06 23:23:29 +02:00
|
|
|
super("oilGenerator");
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
private static OilGenRecipe getRecipeForFluid(String fluidName) {
|
|
|
|
if (fluidName != null) {
|
|
|
|
for (OilGenRecipe recipe : ActuallyAdditionsAPI.OIL_GENERATOR_RECIPES) {
|
|
|
|
if (recipe != null && fluidName.equals(recipe.fluidName)) { return recipe; }
|
2016-11-26 21:32:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-12-01 19:48:09 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
public int getBurningScaled(int i) {
|
|
|
|
return this.currentBurnTime * i / this.maxBurnTime;
|
2016-11-21 13:30:38 +01:00
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
private OilGenRecipe getRecipeForCurrentFluid() {
|
2016-11-21 13:30:38 +01:00
|
|
|
FluidStack stack = this.tank.getFluid();
|
2019-05-02 09:10:29 +02:00
|
|
|
if (stack != null) {
|
2016-11-21 13:30:38 +01:00
|
|
|
Fluid fluid = stack.getFluid();
|
2019-05-02 09:10:29 +02:00
|
|
|
if (fluid != null) { return getRecipeForFluid(fluid.getName()); }
|
2016-11-21 13:30:38 +01:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-02-01 20:32:49 +01:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public void writeSyncableNBT(NBTTagCompound compound, NBTType type) {
|
|
|
|
if (type != NBTType.SAVE_BLOCK) {
|
2016-07-02 15:01:46 +02:00
|
|
|
compound.setInteger("BurnTime", this.currentBurnTime);
|
2016-09-01 22:11:51 +02:00
|
|
|
compound.setInteger("CurrentEnergy", this.currentEnergyProduce);
|
2016-11-21 13:30:38 +01:00
|
|
|
compound.setInteger("MaxBurnTime", this.maxBurnTime);
|
2016-07-02 15:01:46 +02:00
|
|
|
}
|
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
|
2019-05-02 09:10:29 +02:00
|
|
|
public void readSyncableNBT(NBTTagCompound compound, NBTType type) {
|
|
|
|
if (type != NBTType.SAVE_BLOCK) {
|
2016-07-02 15:01:46 +02:00
|
|
|
this.currentBurnTime = compound.getInteger("BurnTime");
|
2016-09-01 22:11:51 +02:00
|
|
|
this.currentEnergyProduce = compound.getInteger("CurrentEnergy");
|
2016-11-21 13:30:38 +01:00
|
|
|
this.maxBurnTime = compound.getInteger("MaxBurnTime");
|
2016-07-02 15:01:46 +02:00
|
|
|
}
|
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
|
2019-05-02 09:10:29 +02:00
|
|
|
public void updateEntity() {
|
2015-11-18 23:11:24 +01:00
|
|
|
super.updateEntity();
|
2019-05-02 09:10:29 +02:00
|
|
|
if (!this.world.isRemote) {
|
2015-06-21 02:28:49 +02:00
|
|
|
boolean flag = this.currentBurnTime > 0;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (this.currentBurnTime > 0 && this.currentEnergyProduce > 0) {
|
2015-05-20 22:39:43 +02:00
|
|
|
this.currentBurnTime--;
|
2016-11-28 12:51:45 +01:00
|
|
|
|
2016-11-23 18:10:55 +01:00
|
|
|
this.storage.receiveEnergyInternal(this.currentEnergyProduce, false);
|
2019-05-02 09:10:29 +02:00
|
|
|
} else if (!this.isRedstonePowered) {
|
2016-09-01 22:11:51 +02:00
|
|
|
int fuelUsed = 50;
|
2016-11-21 13:30:38 +01:00
|
|
|
|
|
|
|
OilGenRecipe recipe = this.getRecipeForCurrentFluid();
|
2019-05-02 09:10:29 +02:00
|
|
|
if (recipe != null && this.storage.getEnergyStored() < this.storage.getMaxEnergyStored() && this.tank.getFluidAmount() >= fuelUsed) {
|
2016-11-21 13:30:38 +01:00
|
|
|
this.currentEnergyProduce = recipe.genAmount;
|
|
|
|
this.maxBurnTime = recipe.genTime;
|
|
|
|
this.currentBurnTime = this.maxBurnTime;
|
|
|
|
|
2016-06-05 02:16:52 +02:00
|
|
|
this.tank.drainInternal(fuelUsed, true);
|
2019-05-02 09:10:29 +02:00
|
|
|
} else {
|
2016-11-21 13:30:38 +01:00
|
|
|
this.currentEnergyProduce = 0;
|
2016-09-01 22:11:51 +02:00
|
|
|
this.currentBurnTime = 0;
|
2016-11-21 13:30:38 +01:00
|
|
|
this.maxBurnTime = 0;
|
2016-09-01 22:11:51 +02:00
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (flag != this.currentBurnTime > 0 || this.lastCompare != this.getComparatorStrength()) {
|
2016-11-28 13:02:42 +01:00
|
|
|
this.lastCompare = this.getComparatorStrength();
|
|
|
|
|
2015-07-02 00:35:38 +02:00
|
|
|
this.markDirty();
|
2015-06-21 02:28:49 +02:00
|
|
|
}
|
2015-07-02 04:21:21 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if ((this.storage.getEnergyStored() != this.lastEnergy || this.tank.getFluidAmount() != this.lastTank || this.lastBurnTime != this.currentBurnTime || this.lastEnergyProduce != this.currentEnergyProduce || this.lastMaxBurnTime != this.maxBurnTime) && this.sendUpdateWithInterval()) {
|
2015-07-02 04:21:21 +02:00
|
|
|
this.lastEnergy = this.storage.getEnergyStored();
|
|
|
|
this.lastTank = this.tank.getFluidAmount();
|
|
|
|
this.lastBurnTime = this.currentBurnTime;
|
2016-09-01 22:11:51 +02:00
|
|
|
this.lastEnergyProduce = this.currentEnergyProduce;
|
2016-11-21 13:30:38 +01:00
|
|
|
this.lastMaxBurnTime = this.maxBurnTime;
|
2016-09-01 22:11:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-28 12:51:45 +01:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public int getComparatorStrength() {
|
|
|
|
float calc = (float) this.storage.getEnergyStored() / (float) this.storage.getMaxEnergyStored() * 15F;
|
|
|
|
return (int) calc;
|
2016-11-28 12:51:45 +01:00
|
|
|
}
|
|
|
|
|
2015-05-20 22:39:43 +02:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public IFluidHandler getFluidHandler(EnumFacing facing) {
|
2016-12-05 14:16:53 +01:00
|
|
|
return this.tank;
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
2015-12-13 00:54:25 +01:00
|
|
|
|
2016-06-10 21:52:37 +02:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public int getMaxFluidAmountToSplitShare() {
|
2016-08-31 20:16:36 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public boolean doesShareFluid() {
|
2016-08-31 20:16:36 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public EnumFacing[] getFluidShareSides() {
|
2016-08-31 20:16:36 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public int getEnergyToSplitShare() {
|
2016-08-31 20:16:36 +02:00
|
|
|
return this.storage.getEnergyStored();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public boolean doesShareEnergy() {
|
2016-08-31 20:16:36 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public EnumFacing[] getEnergyShareSides() {
|
2016-08-31 20:16:36 +02:00
|
|
|
return EnumFacing.values();
|
|
|
|
}
|
2016-11-26 08:58:42 +01:00
|
|
|
|
2016-12-18 17:28:29 +01:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public boolean canShareTo(TileEntity tile) {
|
2016-12-18 17:28:29 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-26 08:58:42 +01:00
|
|
|
@Override
|
2019-05-02 09:10:29 +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
|
|
|
}
|