aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core/tileentities/general
diff options
context:
space:
mode:
authorAlkalus <3060479+draknyte1@users.noreply.github.com>2018-09-14 13:47:51 +1000
committerAlkalus <3060479+draknyte1@users.noreply.github.com>2018-09-14 13:47:51 +1000
commit678a32be304bcffe457cf869ba6c5d57bdc1b2e1 (patch)
tree1db1454a7f2dcb3453370cea0ca995ec9188a9d2 /src/Java/gtPlusPlus/core/tileentities/general
parent84cce1bba9a1091f2428ebee464cbfdf57491def (diff)
downloadGT5-Unofficial-678a32be304bcffe457cf869ba6c5d57bdc1b2e1.tar.gz
GT5-Unofficial-678a32be304bcffe457cf869ba6c5d57bdc1b2e1.tar.bz2
GT5-Unofficial-678a32be304bcffe457cf869ba6c5d57bdc1b2e1.zip
$ Fixed the XP Convertor.
% Rewrote base tile entity system. % Added hashCode() to Pair.java. % Changed some calculations on Materials. % Made Rocket Engines produce heavy pollution.
Diffstat (limited to 'src/Java/gtPlusPlus/core/tileentities/general')
-rw-r--r--src/Java/gtPlusPlus/core/tileentities/general/TileEntityXpConverter.java399
1 files changed, 192 insertions, 207 deletions
diff --git a/src/Java/gtPlusPlus/core/tileentities/general/TileEntityXpConverter.java b/src/Java/gtPlusPlus/core/tileentities/general/TileEntityXpConverter.java
index 403d331151..2816596515 100644
--- a/src/Java/gtPlusPlus/core/tileentities/general/TileEntityXpConverter.java
+++ b/src/Java/gtPlusPlus/core/tileentities/general/TileEntityXpConverter.java
@@ -7,24 +7,21 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
-import net.minecraft.tileentity.TileEntity;
-
-import gtPlusPlus.api.objects.Logger;
+import gtPlusPlus.api.objects.minecraft.BTF_FluidTank;
+import gtPlusPlus.core.tileentities.base.TileBasicTank;
import gtPlusPlus.core.util.minecraft.EnchantingUtils;
import gtPlusPlus.core.util.minecraft.PlayerUtils;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.*;
-public class TileEntityXpConverter extends TileEntity implements IFluidHandler {
+public class TileEntityXpConverter extends TileBasicTank {
- public FluidTank tankEssence = new FluidTank((int) (64000*EnchantingUtils.RATIO_MOB_ESSENCE_TO_LIQUID_XP));
- public FluidTank tankLiquidXp = new FluidTank(64000);
- private boolean needsUpdate = false;
+ public BTF_FluidTank tankEssence = new BTF_FluidTank((int) (64000*EnchantingUtils.RATIO_MOB_ESSENCE_TO_LIQUID_XP));
+ public BTF_FluidTank tankLiquidXp = new BTF_FluidTank(64000);
private boolean mConvertToEssence = true;
- private int updateTimer = 0;
- private long mTickTime = 0;
public TileEntityXpConverter() {
+ super (4, 32000);
}
private void changeMode(){
@@ -36,278 +33,266 @@ public class TileEntityXpConverter extends TileEntity implements IFluidHandler {
this.mConvertToEssence = true;
return;
}
- }
-
- private boolean isServerSide(){
- if (this.getWorldObj().isRemote){
- return false;
- }
- else {
- return true;
- }
- }
+ }
- @Override
- public int fill(final ForgeDirection from, final FluidStack resource, final boolean doFill) {
- this.needsUpdate = true;
- Logger.WARNING("Ticking. | mConvertToEssence: "+this.mConvertToEssence);
+ public float getAdjustedVolume() {
if (this.mConvertToEssence){
- if (resource.isFluidEqual(EnchantingUtils.getLiquidXP(1))){
- Logger.WARNING("fill(tankLiquidXp)");
- return this.tankLiquidXp.fill(resource, doFill);
- }
- else {
- Logger.WARNING("Looking for Liquid Xp, Instead found "+resource.getLocalizedName()+".");
+ if ((this.tankLiquidXp.getFluid() != null) && (this.tankLiquidXp.getFluidAmount() >= 100) && (this.tankEssence.getFluidAmount() <= (this.tankEssence.getCapacity()-(100*EnchantingUtils.RATIO_MOB_ESSENCE_TO_LIQUID_XP)))){
+ final FluidStack bigStorage = EnchantingUtils.getEssenceFromLiquidXp(100);
+ this.tankEssence.fill(bigStorage, true);
+ this.tankLiquidXp.drain(100, true);
+ return (this.tankEssence.getCapacity()-this.tankEssence.getFluidAmount());
}
}
else {
- if (resource.isFluidEqual(EnchantingUtils.getMobEssence(1))){
- Logger.WARNING("fill(tankEssence)");
- return this.tankEssence.fill(resource, doFill);
- }
- else {
- Logger.WARNING("Looking for Essence, Instead found "+resource.getLocalizedName()+".");
+ final double rm = EnchantingUtils.RATIO_MOB_ESSENCE_TO_LIQUID_XP;
+ if ((this.tankEssence.getFluid() != null) && (this.tankEssence.getFluidAmount() >= rm) && (this.tankLiquidXp.getFluidAmount() <= (this.tankLiquidXp.getCapacity()-rm))){
+ final FluidStack bigStorage = EnchantingUtils.getLiquidXP(1);
+ this.tankLiquidXp.fill(bigStorage, true);
+ this.tankEssence.drain((int) rm, true);
+ return (this.tankLiquidXp.getCapacity()-this.tankLiquidXp.getFluidAmount());
}
- }
- Logger.WARNING("fill(0)");
- return 0;
+ }
+ return 0f;
}
@Override
- public FluidStack drain(final ForgeDirection from, final FluidStack resource, final boolean doDrain) {
- this.needsUpdate = true;
- if (this.mConvertToEssence){
- if (resource.isFluidEqual(EnchantingUtils.getMobEssence(1))){
- Logger.WARNING("drain(mConvertToEssence)");
- return this.tankEssence.drain(resource.amount, doDrain);
- }
- }
- else {
- if (resource.isFluidEqual(EnchantingUtils.getLiquidXP(1))){
- Logger.WARNING("drain(tankLiquidXp)");
- return this.tankLiquidXp.drain(resource.amount, doDrain);
- }
- }
- Logger.WARNING("drain(null)");
- return null;
+ public void readFromNBT(final NBTTagCompound tag) {
+ this.tankEssence.readFromNBT(tag);
+ this.tankLiquidXp.readFromNBT(tag);
+ this.mConvertToEssence = tag.getBoolean("mConvertToEssence");
+ super.readFromNBT(tag);
}
@Override
- public FluidStack drain(final ForgeDirection from, final int maxDrain, final boolean doDrain) {
- this.needsUpdate = true;
- Logger.WARNING("drain(Ex)");
- final FluidStack fluid_Essence = this.tankEssence.getFluid();
- final FluidStack fluid_Xp = this.tankLiquidXp.getFluid();
- if ((fluid_Essence == null) && (fluid_Xp == null)) {
- return null;
- }
+ public void writeToNBT(final NBTTagCompound tag) {
+ this.tankEssence.writeToNBT(tag);
+ this.tankLiquidXp.writeToNBT(tag);
+ tag.setBoolean("mConvertToEssence", this.mConvertToEssence);
+ super.writeToNBT(tag);
+ }
- FluidStack fluid;
- FluidTank tank;
+ @Override
+ public Packet getDescriptionPacket() {
+ final NBTTagCompound tag = new NBTTagCompound();
+ this.writeToNBT(tag);
+ return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, this.blockMetadata, tag);
+ }
- if (this.mConvertToEssence){
- fluid = fluid_Essence;
- tank = this.tankEssence;
- }
- else {
- fluid = fluid_Xp;
- tank = this.tankLiquidXp;
- }
+ @Override
+ public void onDataPacket(final NetworkManager net, final S35PacketUpdateTileEntity pkt) {
+ final NBTTagCompound tag = pkt.func_148857_g();
+ this.readFromNBT(tag);
+ }
- int drained = maxDrain;
- if (fluid.amount < drained) {
- drained = fluid.amount;
+ public void onScrewdriverRightClick(final byte aSide, final EntityPlayer aPlayer, final float aX, final float aY, final float aZ) {
+ if (this.isServerSide()){
+ if (this.mConvertToEssence){
+ PlayerUtils.messagePlayer(aPlayer, "Converting from Mob Essence to Liquid Xp.");
+ }
+ else {
+ PlayerUtils.messagePlayer(aPlayer, "Converting from Liquid Xp to Mob Essence.");
+ }
+ //Mode Change
+ this.changeMode();
}
+ }
- final FluidStack stack = new FluidStack(fluid, drained);
- if (doDrain) {
- fluid.amount -= drained;
- if (fluid.amount <= 0) {
- fluid = null;
- }
+ public void onRightClick(final byte aSide, final EntityPlayer aPlayer, final int aX, final int aY, final int aZ) {
+ if ((Keyboard.isKeyDown(42)) || (Keyboard.isKeyDown(54))) {
+ String mInput;
+ String mOutput;
- if (this != null) {
- FluidEvent.fireEvent(new FluidEvent.FluidDrainingEvent(fluid, this.getWorldObj(), this.xCoord,
- this.yCoord, this.zCoord, tank, 0));
+ if (this.mConvertToEssence){
+ mInput = "Liquid Xp";
+ mOutput = "Mob Essence";
+ }
+ else {
+ mInput = "Mob Essence";
+ mOutput = "Liquid Xp";
}
- }
+ PlayerUtils.messagePlayer(aPlayer, "Input: "+mInput+".");
+ PlayerUtils.messagePlayer(aPlayer, "Output: "+mOutput+".");
+ }
+ }
- if (this.mConvertToEssence){
- this.tankEssence = tank;
+ @Override
+ public boolean onPreTick(long aTick) {
+ boolean aSuperResult = super.onPreTick(aTick);
+ long aTankSpaceLeft = 0;
+ double aAmount = 0;
+ int aRuns = 0;
+ if (this.mConvertToEssence) {
+ aTankSpaceLeft = (this.tankEssence.getCapacity()-this.tankEssence.getFluidAmount());
+ aAmount = EnchantingUtils.getEssenceFromLiquidXp(100).amount;
}
else {
- this.tankLiquidXp = tank;
+ aTankSpaceLeft = (this.tankLiquidXp.getCapacity()-this.tankLiquidXp.getFluidAmount());
+ aAmount = EnchantingUtils.RATIO_MOB_ESSENCE_TO_LIQUID_XP;
}
-
- Logger.WARNING("drain(Ex2)");
- return stack;
+ aRuns = (int) (aTankSpaceLeft / aAmount);
+ for (int i=0;i<aRuns;i++) {
+ if (getAdjustedVolume() == 0) {
+ break;
+ }
+ }
+ return aSuperResult;
}
@Override
- public boolean canFill(final ForgeDirection from, final Fluid fluid) {
- if (this.mConvertToEssence){
- if (this.tankEssence.getFluidAmount() < this.tankEssence.getCapacity()){
- Logger.WARNING("canFill(mConvertToEssence)");
- return true;
+ public boolean isLiquidInput(byte aSide) {
+ if (mConvertToEssence) {
+ if (aSide == 0 || aSide == 1) {
+ return false;
}
- }
- else {
- if (this.tankLiquidXp.getFluidAmount() < this.tankLiquidXp.getCapacity()){
- Logger.WARNING("canFill(tankLiquidXp)");
+ } else {
+ if (aSide == 0 || aSide == 1) {
return true;
}
}
- Logger.WARNING("canFill(false)");
return false;
}
@Override
- public boolean canDrain(final ForgeDirection from, final Fluid fluid) {
- if (this.mConvertToEssence){
- if (this.tankEssence.getFluidAmount() > 0){
+ public boolean isLiquidOutput(byte aSide) {
+ if (mConvertToEssence) {
+ if (aSide == 0 || aSide == 1) {
return true;
}
- }
- else {
- if (this.tankLiquidXp.getFluidAmount() > 0){
- return true;
+ } else {
+ if (aSide == 0 || aSide == 1) {
+ return false;
}
}
- Logger.WARNING("canDrain(false)");
return false;
}
@Override
- public FluidTankInfo[] getTankInfo(final ForgeDirection from) {
- if (this.mConvertToEssence){
- return new FluidTankInfo[] { this.tankEssence.getInfo() };
- }
- else {
- return new FluidTankInfo[] { this.tankLiquidXp.getInfo() };
+ public int fill(ForgeDirection aSide, FluidStack aFluid, boolean doFill) {
+ if (mConvertToEssence) {
+ if (aSide != ForgeDirection.UP && aSide != ForgeDirection.DOWN) {
+ return this.tankLiquidXp.fill(aFluid, doFill);
+ }
+ } else {
+ if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) {
+ return this.tankEssence.fill(aFluid, doFill);
+ }
}
+ return 0;
}
- public float getAdjustedVolume() {
- Logger.WARNING("AdjustedVolume()");
- this.needsUpdate = true;
- final float amount = this.tankLiquidXp.getFluidAmount();
- final float capacity = this.tankLiquidXp.getCapacity();
- final float volume = (amount / capacity) * 0.8F;
- return volume;
+ @Override
+ public FluidStack drain(ForgeDirection aSide, int maxDrain, boolean doDrain) {
+ if (mConvertToEssence) {
+ if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) {
+ return this.tankEssence.drain(maxDrain, doDrain);
+ }
+ } else {
+ if (aSide != ForgeDirection.UP && aSide != ForgeDirection.DOWN) {
+ return this.tankLiquidXp.drain(maxDrain, doDrain);
+ }
+ }
+ return null;
}
@Override
- public void updateEntity() {
-
- if (this.isServerSide()){
- this.mTickTime++;
-
- if (this.needsUpdate) {
- if (this.updateTimer == 0) {
- this.updateTimer = 10; // every 10 ticks it will send an update
- } else {
- --this.updateTimer;
- if (this.updateTimer == 0) {
- this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
- this.needsUpdate = false;
- }
- }
+ public FluidStack drain(ForgeDirection aSide, FluidStack aFluid, boolean doDrain) {
+ if (mConvertToEssence) {
+ if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) {
+ return this.tankEssence.drain(aFluid, doDrain);
}
+ } else {
+ if (aSide != ForgeDirection.UP && aSide != ForgeDirection.DOWN) {
+ return this.tankLiquidXp.drain(aFluid, doDrain);
+ }
+ }
+ return null;
+ }
-
- if (this.mConvertToEssence){
- if ((this.tankLiquidXp.getFluid() != null) && (this.tankLiquidXp.getFluidAmount() >= 100) && (this.tankEssence.getFluidAmount() <= (this.tankEssence.getCapacity()-(100*EnchantingUtils.RATIO_MOB_ESSENCE_TO_LIQUID_XP)))){
- final FluidStack bigStorage = EnchantingUtils.getEssenceFromLiquidXp(100);
- this.tankEssence.fill(bigStorage, true);
- this.tankLiquidXp.drain(100, true);
- this.needsUpdate = true;
- Logger.WARNING("B->A");
- }
+ @Override
+ public boolean canFill(ForgeDirection aSide, Fluid aFluid) {
+ if (mConvertToEssence) {
+ if (aSide != ForgeDirection.UP && aSide != ForgeDirection.DOWN) {
+ return this.tankLiquidXp.canTankBeFilled();
}
- else {
- final double rm = EnchantingUtils.RATIO_MOB_ESSENCE_TO_LIQUID_XP;
- if ((this.tankEssence.getFluid() != null) && (this.tankEssence.getFluidAmount() >= rm) && (this.tankLiquidXp.getFluidAmount() <= (this.tankLiquidXp.getCapacity()-rm))){
- final FluidStack bigStorage = EnchantingUtils.getLiquidXP(1);
- this.tankLiquidXp.fill(bigStorage, true);
- this.tankEssence.drain((int) rm, true);
- this.needsUpdate = true;
- Logger.WARNING("A->B");
- }
+ } else {
+ if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) {
+ return this.tankEssence.canTankBeFilled();
}
}
- else {
- }
- this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
- this.markDirty();
-
- if ((this.mTickTime % 20) == 0){
+ return false;
+ }
+ @Override
+ public boolean canDrain(ForgeDirection aSide, Fluid aFluid) {
+ if (mConvertToEssence) {
+ if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) {
+ return this.tankEssence.canTankBeEmptied();
+ }
+ } else {
+ if (aSide != ForgeDirection.UP && aSide != ForgeDirection.DOWN) {
+ return this.tankLiquidXp.canTankBeEmptied();
+ }
}
-
+ return false;
}
@Override
- public void readFromNBT(final NBTTagCompound tag) {
- this.tankEssence.readFromNBT(tag);
- this.tankLiquidXp.readFromNBT(tag);
- this.mConvertToEssence = tag.getBoolean("mConvertToEssence");
- super.readFromNBT(tag);
+ public FluidTankInfo[] getTankInfo(ForgeDirection aSide) {
+ if (aSide == ForgeDirection.UP || aSide == ForgeDirection.DOWN) {
+ return new FluidTankInfo[] { this.tankEssence.getInfo() };
+ } else {
+ return new FluidTankInfo[] { this.tankLiquidXp.getInfo() };
+
+ }
}
@Override
- public void writeToNBT(final NBTTagCompound tag) {
- this.tankEssence.writeToNBT(tag);
- this.tankLiquidXp.writeToNBT(tag);
- tag.setBoolean("mConvertToEssence", this.mConvertToEssence);
- super.writeToNBT(tag);
+ public FluidStack getFluid() {
+ if (mConvertToEssence) {
+ return this.tankEssence.getFluid();
+ }
+ else {
+ return this.tankLiquidXp.getFluid();
+ }
}
@Override
- public Packet getDescriptionPacket() {
- final NBTTagCompound tag = new NBTTagCompound();
- this.writeToNBT(tag);
- return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, this.blockMetadata, tag);
+ public int getFluidAmount() {
+ if (mConvertToEssence) {
+ return this.tankEssence.getFluidAmount();
+ }
+ else {
+ return this.tankLiquidXp.getFluidAmount();
+ }
}
@Override
- public void onDataPacket(final NetworkManager net, final S35PacketUpdateTileEntity pkt) {
- final NBTTagCompound tag = pkt.func_148857_g();
- this.readFromNBT(tag);
+ public FluidTankInfo getInfo() {
+ if (mConvertToEssence) {
+ return this.tankEssence.getInfo();
+ } else {
+ return this.tankLiquidXp.getInfo();
+ }
}
- public void onScrewdriverRightClick(final byte aSide, final EntityPlayer aPlayer, final float aX, final float aY, final float aZ) {
- if (this.isServerSide()){
- if (this.mConvertToEssence){
- PlayerUtils.messagePlayer(aPlayer, "Converting from Mob Essence to Liquid Xp.");
- }
- else {
- PlayerUtils.messagePlayer(aPlayer, "Converting from Liquid Xp to Mob Essence.");
- }
- //Mode Change
- this.changeMode();
+ @Override
+ public int fill(FluidStack resource, boolean doFill) {
+ if (mConvertToEssence) {
+ return this.tankEssence.fill(resource, doFill);
+ } else {
+ return this.tankLiquidXp.fill(resource, doFill);
}
}
- public void onRightClick(final byte aSide, final EntityPlayer aPlayer, final int aX, final int aY, final int aZ) {
-
- if ((Keyboard.isKeyDown(42)) || (Keyboard.isKeyDown(54))) {
- String mInput;
- String mOutput;
-
- if (this.mConvertToEssence){
- mInput = "Liquid Xp";
- mOutput = "Mob Essence";
- }
- else {
- mInput = "Mob Essence";
- mOutput = "Liquid Xp";
- }
-
- PlayerUtils.messagePlayer(aPlayer, "Input: "+mInput+".");
- PlayerUtils.messagePlayer(aPlayer, "Output: "+mOutput+".");
+ @Override
+ public FluidStack drain(int maxDrain, boolean doDrain) {
+ if (mConvertToEssence) {
+ return this.tankEssence.drain(maxDrain, doDrain);
+ } else {
+ return this.tankLiquidXp.drain(maxDrain, doDrain);
}
-
}
}