Fixed Distillation tower & Sawmill

This commit is contained in:
TheDarkDnKTv 2021-02-25 21:04:03 +02:00
parent 3f8aba2e6c
commit 1b0103ab7c
13 changed files with 106 additions and 424 deletions

View file

@ -87,7 +87,7 @@ public class RecipeLogic {
} else {
previousRecipe = null;
wasNoEnergy = true;
base.setActive(false);
triggerMachine(false);
}
}
}

View file

@ -58,7 +58,7 @@ public class GT_ModHandler {
* Returns a Liquid Stack with given amount of Water.
*/
public static FluidStack getWater(long aAmount) {
return FluidRegistry.getFluidStack("water", (int)aAmount);
return new FluidStack(FluidRegistry.WATER, (int) aAmount);
}
/**
@ -73,7 +73,7 @@ public class GT_ModHandler {
* Returns a Liquid Stack with given amount of Lava.
*/
public static FluidStack getLava(long aAmount) {
return FluidRegistry.getFluidStack("lava", (int)aAmount);
return new FluidStack(FluidRegistry.LAVA, (int) aAmount);
}
/**
@ -529,7 +529,7 @@ public class GT_ModHandler {
try {
cofh.thermalexpansion.api.crafting.CraftingHandlers.sawmill.addRecipe(aRF, aInput1, outputs[0], outputs.length > 1 ? outputs[1] : null, aChance, true);
} catch(Throwable e) {/*Do nothing*/}
RecipeMaps.SAWMILL.factory().EUt(30).duration(200*aInput1.stackSize).setShaped(true).inputs(aInput1, GT_Items.Cell_Water.get(1)).outputs(outputs).output(GT_Items.Cell_Empty.get(1)).buildAndRegister();
RecipeMaps.SAWMILL.factory().EUt(30).duration(200*aInput1.stackSize).setShaped(true).inputs(aInput1).input(getWater(1000)).outputs(outputs).buildAndRegister();
return true;
}

View file

@ -28,36 +28,26 @@ public class GT_Container_DistillationTower extends GT_ContainerMetaTile_Machine
addSlotToContainer(new GT_Slot_Output(mTileEntity, 5, 98, 59));
}
public int mProgress, mMaxProgress, mProgressScale;
public boolean mMachine = true;
@SuppressWarnings("rawtypes")
public void detectAndSendChanges() {
super.detectAndSendChanges();
if (mTileEntity.isClientSide() || mTileEntity.getMetaTileEntity() == null) return;
mMachine = ((GT_MetaTileEntity_DistillationTower)mTileEntity.getMetaTileEntity()).mMachine;
mProgress = ((GT_MetaTileEntity_DistillationTower)mTileEntity.getMetaTileEntity()).getProgresstime();
mMaxProgress = ((GT_MetaTileEntity_DistillationTower)mTileEntity.getMetaTileEntity()).maxProgresstime();
mProgressScale = Math.max(0, Math.min(72, (mProgress>0?1:0) + (mProgress * 72) / (mMaxProgress<1?1:mMaxProgress)));
mMachine = ((GT_MetaTileEntity_DistillationTower)mTileEntity.getMetaTileEntity()).isStructComplete();
Iterator var2 = this.crafters.iterator();
while (var2.hasNext()) {
ICrafting var1 = (ICrafting)var2.next();
var1.sendProgressBarUpdate(this, 100, mProgress);
var1.sendProgressBarUpdate(this, 101, mMaxProgress);
var1.sendProgressBarUpdate(this, 102, mProgressScale);
var1.sendProgressBarUpdate(this, 103, mMachine?1:0);
var1.sendProgressBarUpdate(this, 100, mMachine?1:0);
}
}
@SideOnly(Side.CLIENT)
public void updateProgressBar(int par1, int par2) {
super.updateProgressBar(par1, par2);
switch (par1) {
case 100: mProgress = par2; break;
case 101: mMaxProgress = par2; break;
case 102: mProgressScale = par2; break;
case 103: mMachine = (par2!=0); break;
if (par1 == 100) {
mMachine = par2 != 0;
}
}

View file

@ -26,40 +26,32 @@ public class GT_Container_Sawmill extends GT_ContainerMetaTile_Machine {
addSlotToContainer(new GT_Slot_Output(mTileEntity, 3, 104, 25));
addSlotToContainer(new GT_Slot_Output(mTileEntity, 4, 122, 25));
}
public int mProgress, mMaxProgress, mProgressScale, mWaterAmount;
public int mWaterAmount = 0;
public boolean mMachine = true;
@SuppressWarnings("rawtypes")
public void detectAndSendChanges() {
super.detectAndSendChanges();
if (mTileEntity.isClientSide() || mTileEntity.getMetaTileEntity() == null) return;
mMachine = ((GT_MetaTileEntity_Sawmill)mTileEntity.getMetaTileEntity()).mMachine;
mWaterAmount = ((GT_MetaTileEntity_Sawmill)mTileEntity.getMetaTileEntity()).mWaterAmount;
mProgress = ((GT_MetaTileEntity_Sawmill)mTileEntity.getMetaTileEntity()).getProgresstime();
mMaxProgress = ((GT_MetaTileEntity_Sawmill)mTileEntity.getMetaTileEntity()).maxProgresstime();
mProgressScale = Math.max(0, Math.min(20, (mProgress>0?1:0) + (mProgress * 20) / (mMaxProgress<1?1:mMaxProgress)));
mMachine = ((GT_MetaTileEntity_Sawmill)mTileEntity.getMetaTileEntity()).isStructComplete();
mWaterAmount = ((GT_MetaTileEntity_Sawmill)mTileEntity.getMetaTileEntity()).getFluidAmount();
Iterator var2 = this.crafters.iterator();
while (var2.hasNext()) {
ICrafting var1 = (ICrafting)var2.next();
var1.sendProgressBarUpdate(this, 100, mProgress);
var1.sendProgressBarUpdate(this, 101, mMaxProgress);
var1.sendProgressBarUpdate(this, 102, mProgressScale);
var1.sendProgressBarUpdate(this, 103, mMachine?1:0);
var1.sendProgressBarUpdate(this, 104, mWaterAmount);
var1.sendProgressBarUpdate(this, 102, mWaterAmount);
}
}
@SideOnly(Side.CLIENT)
public void updateProgressBar(int par1, int par2) {
super.updateProgressBar(par1, par2);
switch (par1) {
case 100: mProgress = par2; break;
case 101: mMaxProgress = par2; break;
case 102: mProgressScale = par2; break;
case 103: mMachine = (par2!=0); break;
case 104: mWaterAmount = par2; break;
if (par1 == 103) {
mMachine = par2 != 0;
} else if (par1 == 102) {
mWaterAmount = par2;
}
}

View file

@ -16,16 +16,10 @@ public class GT_GUIContainer_DistillationTower extends GT_GUIContainerMetaTile_M
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
fontRenderer.drawString("Distillation" , 116, 4, 4210752);
fontRenderer.drawString("Tower" , 116, 12, 4210752);
if (!((GT_Container_DistillationTower)mContainer).mMachine) {
fontRenderer.drawString("Incomplete" , 116, 20, 4210752);
fontRenderer.drawString("Machine" , 116, 28, 4210752);
fontRenderer.drawString("Casing!" , 116, 36, 4210752);
}
if (((mContainer).mDisplayErrorCode & 1) != 0) {
fontRenderer.drawString("Insufficient" , 116, 44, 4210752);
fontRenderer.drawString("Energy" , 116, 52, 4210752);
fontRenderer.drawString("Line!" , 116, 60, 4210752);
}
if (!((GT_Container_DistillationTower)mContainer).mMachine)
fontRenderer.drawSplitString("Incomplete Machine Casing!", 116, 20, 60, 4210752);
if (((mContainer).mDisplayErrorCode & 1) != 0)
fontRenderer.drawSplitString("Insufficient Energy Line!", 116, 48, 60, 4210752);
}
@Override
@ -36,7 +30,8 @@ public class GT_GUIContainer_DistillationTower extends GT_GUIContainerMetaTile_M
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
if (mContainer != null && mContainer.mProgressTime>0) {
int tScale = ((GT_Container_DistillationTower)mContainer).mProgressScale;
GT_Container_DistillationTower cont = (GT_Container_DistillationTower)mContainer;
int tScale = Math.max(0, Math.min(72, (cont.mProgressTime>0?1:0) + (cont.mProgressTime * 72) / (cont.mMaxProgressTime<1?1:cont.mMaxProgressTime)));
drawTexturedModalRect(x + 80, y + 76-tScale, 176, 76-tScale, 16, tScale);
}
}

View file

@ -33,7 +33,8 @@ public class GT_GUIContainer_Sawmill extends GT_GUIContainerMetaTile_Machine {
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
if (mContainer != null) {
int tScale = ((GT_Container_Sawmill)mContainer).mProgressScale;
GT_Container_Sawmill cont = (GT_Container_Sawmill) mContainer;
int tScale = Math.max(0, Math.min(20, (cont.mProgressTime > 0?1:0) + (cont.mProgressTime * 20) / (cont.mMaxProgressTime<1?1:cont.mMaxProgressTime)));
if (mContainer.mProgressTime > 0) drawTexturedModalRect(x + 58, y + 28, 176, 0, tScale, 11);
tScale = ((GT_Container_Sawmill)mContainer).mWaterAmount/550;

View file

@ -25,7 +25,7 @@ public class RecipeMaps {
public static final RecipeMap<BlastFurnanceRecipeFactory> BLAST_FURNANCE = new RecipeMap<>(1, 2, 1, 2, new BlastFurnanceRecipeFactory());
public static final RecipeMap<SimpleRecipeFactory> BRONZE_BLAST_FURNANCE = new RecipeMap<>(1, 2, 1, 2, new SimpleRecipeFactory());
public static final RecipeMap<SimpleRecipeFactory> IMPLOSION_COMPRESSOR= new RecipeMap<>(1, 2, 1, 2, new SimpleRecipeFactory()); //
public static final RecipeMap<SimpleRecipeFactory> SAWMILL = new RecipeMap<>(1, 2, 1, 3, new SimpleRecipeFactory()); //
public static final RecipeMap<SimpleRecipeFactory> SAWMILL = new RecipeMap<>(1, 2, 1, 3, 0, 1, 0, 0, new SimpleRecipeFactory()); //
public static final RecipeMap<SimpleRecipeFactory> VACUUM_FREEZER = new RecipeMap<>(1, 1, 1, 1, new SimpleRecipeFactory()); // -----------------
public static final RecipeMap<SimpleRecipeFactory> CHEMICAL = new RecipeMap<>(1, 2, 1, 1, new SimpleRecipeFactory());
public static final RecipeMap<SimpleRecipeFactory> DISTILLATION = new RecipeMap<>(1, 2, 1, 4, new SimpleRecipeFactory());

View file

@ -63,10 +63,16 @@ public abstract class BaseMultiWorkable extends MetaTileEntity implements IRecip
@Override
public void onPostTick() {
if (getBaseMetaTileEntity().isServerSide() && needCheckStruct) {
structComplete = checkMachine();
needCheckStruct = false;
getBaseMetaTileEntity().setActive(structComplete);
if (getBaseMetaTileEntity().isServerSide()) {
if (needCheckStruct) {
structComplete = checkMachine();
needCheckStruct = false;
getBaseMetaTileEntity().setActive(structComplete);
}
if (structComplete) {
recipeLogic.update();
}
}
}
@ -91,13 +97,15 @@ public abstract class BaseMultiWorkable extends MetaTileEntity implements IRecip
public void startProcess() {}
@Override
public void endProcess() {}
public void endProcess() {
getBaseMetaTileEntity().setErrorDisplayID(0);
}
@Override
public void stutterProcess() {
if (GregTech_API.sConstantEnergy) {
int val = (int) (recipeLogic.getMaxProgressTime() * 0.1D);
getBaseMetaTileEntity().setErrorDisplayID(1);
if (recipeLogic.getProgressTime() > val)
recipeLogic.increaseProgressTime(-val);
}

View file

@ -91,6 +91,7 @@ public class GT_MetaTileEntity_BlastFurnace extends BaseMultiWorkable {
getBaseMetaTileEntity().openGUI(aPlayer, 113);
}
@Override
protected boolean checkMachine() {
int xDir = ForgeDirection.getOrientation(getBaseMetaTileEntity().getFrontFacing()).offsetX*2, yDir = ForgeDirection.getOrientation(getBaseMetaTileEntity().getFrontFacing()).offsetY*2, zDir = ForgeDirection.getOrientation(getBaseMetaTileEntity().getFrontFacing()).offsetZ*2;
mHeatCapacity = mHeatingCoilTier * 500;
@ -121,9 +122,9 @@ public class GT_MetaTileEntity_BlastFurnace extends BaseMultiWorkable {
public void onPostTick() {
super.onPostTick();
if (getBaseMetaTileEntity().isServerSide()) {
if (structComplete) {
recipeLogic.update();
} else mHeatCapacity = 0;
if (!structComplete) {
mHeatCapacity = 0;
}
}
}

View file

@ -61,6 +61,7 @@ public class GT_MetaTileEntity_BronzeBlastFurnace extends BaseMultiWorkable {
getBaseMetaTileEntity().openGUI(aPlayer, 170);
}
@Override
protected boolean checkMachine() {
int xDir = ForgeDirection.getOrientation(getBaseMetaTileEntity().getBackFacing()).offsetX, zDir = ForgeDirection.getOrientation(getBaseMetaTileEntity().getBackFacing()).offsetZ;
for (int i = -1; i < 2; i++) for (int j = -1; j < 3; j++) for (int k = -1; k < 2; k++) if (xDir+i != 0 || j != 0 || zDir+k != 0) {

View file

@ -1,112 +1,56 @@
package gregtechmod.common.tileentities.machines.multi;
import java.util.List;
import java.util.Map;
import gregtechmod.api.GregTech_API;
import gregtechmod.api.interfaces.IGregTechTileEntity;
import gregtechmod.api.metatileentity.MetaTileEntity;
import gregtechmod.api.recipe.Recipe;
import gregtechmod.api.util.GT_ModHandler;
import gregtechmod.api.util.GT_Utility;
import gregtechmod.api.util.InfoBuilder;
import gregtechmod.api.util.ListAdapter;
import gregtechmod.common.recipe.RecipeMaps;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
public class GT_MetaTileEntity_DistillationTower extends MetaTileEntity {
public class GT_MetaTileEntity_DistillationTower extends BaseMultiWorkable {
public int mProgresstime = 0, mMaxProgresstime = 0, mEUt = 0, mUpdate = 5;
private ItemStack mOutputItem1, mOutputItem2, mOutputItem3, mOutputItem4;
public boolean mMachine = false;
public GT_MetaTileEntity_DistillationTower(int aID, String mName) {
super(aID, mName);
super(aID, mName, RecipeMaps.DISTILLATION);
}
public GT_MetaTileEntity_DistillationTower() {
super(RecipeMaps.DISTILLATION);
}
@Override public boolean isTransformerUpgradable() {return true;}
@Override public boolean isOverclockerUpgradable() {return true;}
@Override public boolean isBatteryUpgradable() {return true;}
@Override public boolean isSimpleMachine() {return false;}
@Override public boolean isFacingValid(byte aFacing) {return aFacing > 1;}
@Override public boolean isEnetInput() {return true;}
@Override public boolean isInputFacing(byte aSide) {return true;}
@Override public int maxEUInput() {return 128;}
@Override public int maxEUStore() {return 10000;}
@Override public int maxRFStore() {return maxEUStore();}
@Override public int maxSteamStore() {return maxEUStore();}
@Override public int getInvSize() {return 6;}
@Override public void onRightclick(EntityPlayer aPlayer) {getBaseMetaTileEntity().openGUI(aPlayer, 127);}
@Override public boolean isAccessAllowed(EntityPlayer aPlayer) {return true;}
@Override public int getProgresstime() {return mProgresstime;}
@Override public int maxProgresstime() {return mMaxProgresstime;}
@Override public int increaseProgress(int aProgress) {mProgresstime += aProgress; return mMaxProgresstime-mProgresstime;}
@Override
public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {
return new GT_MetaTileEntity_DistillationTower();
}
@Override
public List<ItemStack> getOutputItems() {
return new ListAdapter<>(mInventory, 2, 5);
}
@Override
public void saveNBTData(NBTTagCompound aNBT) {
aNBT.setInteger("mEUt", mEUt);
aNBT.setInteger("mProgresstime", mProgresstime);
aNBT.setInteger("mMaxProgresstime", mMaxProgresstime);
if (mOutputItem1 != null) {
NBTTagCompound tNBT = new NBTTagCompound();
mOutputItem1.writeToNBT(tNBT);
aNBT.setTag("mOutputItem1", tNBT);
}
if (mOutputItem2 != null) {
NBTTagCompound tNBT = new NBTTagCompound();
mOutputItem2.writeToNBT(tNBT);
aNBT.setTag("mOutputItem2", tNBT);
}
if (mOutputItem3 != null) {
NBTTagCompound tNBT = new NBTTagCompound();
mOutputItem3.writeToNBT(tNBT);
aNBT.setTag("mOutputItem3", tNBT);
}
if (mOutputItem4 != null) {
NBTTagCompound tNBT = new NBTTagCompound();
mOutputItem4.writeToNBT(tNBT);
aNBT.setTag("mOutputItem4", tNBT);
}
super.saveNBTData(aNBT);
}
@Override
public void loadNBTData(NBTTagCompound aNBT) {
mUpdate = 5;
mEUt = aNBT.getInteger("mEUt");
mProgresstime = aNBT.getInteger("mProgresstime");
mMaxProgresstime = aNBT.getInteger("mMaxProgresstime");
NBTTagCompound tNBT1 = (NBTTagCompound)aNBT.getTag("mOutputItem1");
if (tNBT1 != null) {
mOutputItem1 = GT_Utility.loadItem(tNBT1);
}
NBTTagCompound tNBT2 = (NBTTagCompound)aNBT.getTag("mOutputItem2");
if (tNBT2 != null) {
mOutputItem2 = GT_Utility.loadItem(tNBT2);
}
NBTTagCompound tNBT3 = (NBTTagCompound)aNBT.getTag("mOutputItem3");
if (tNBT3 != null) {
mOutputItem3 = GT_Utility.loadItem(tNBT3);
}
NBTTagCompound tNBT4 = (NBTTagCompound)aNBT.getTag("mOutputItem4");
if (tNBT4 != null) {
mOutputItem4 = GT_Utility.loadItem(tNBT4);
}
super.loadNBTData(aNBT);
}
private boolean checkMachine() {
@Override
protected boolean checkMachine() {
int xDir = ForgeDirection.getOrientation(getBaseMetaTileEntity().getFrontFacing()).offsetX*2, yDir = ForgeDirection.getOrientation(getBaseMetaTileEntity().getFrontFacing()).offsetY*2, zDir = ForgeDirection.getOrientation(getBaseMetaTileEntity().getFrontFacing()).offsetZ*2;
for (int i = -1; i < 2; i++) for (int j = 0; j < 5; j++) for (int k = -1; k < 2; k++) {
Block tBlockID = getBaseMetaTileEntity().getBlockOffset(-xDir+i, -yDir+j, -zDir+k);
@ -127,100 +71,9 @@ public class GT_MetaTileEntity_DistillationTower extends MetaTileEntity {
return true;
}
@Override
public void onMachineBlockUpdate() {
mUpdate = 5;
}
@Override
public void onPostTick() {
if (getBaseMetaTileEntity().isServerSide()) {
if (mUpdate--==0) {
mMachine = checkMachine();
}
getBaseMetaTileEntity().setActive(mMachine);
if (mMachine && mMaxProgresstime > 0) {
if (mProgresstime < 0 || getBaseMetaTileEntity().decreaseStoredEnergyUnits(mEUt*(int)Math.pow(4, getBaseMetaTileEntity().getOverclockerUpgradeCount()), false)) {
if ((mProgresstime+=(int)Math.pow(2, getBaseMetaTileEntity().getOverclockerUpgradeCount()))>=mMaxProgresstime) {
addOutputProducts();
mOutputItem1 = null;
mOutputItem2 = null;
mOutputItem3 = null;
mOutputItem4 = null;
mProgresstime = 0;
mMaxProgresstime = 0;
getBaseMetaTileEntity().setErrorDisplayID(0);
}
} else {
if (GregTech_API.sConstantEnergy) {
mProgresstime = -10;
getBaseMetaTileEntity().setErrorDisplayID(1);
}
}
} else {
if (getBaseMetaTileEntity().isAllowedToWork() && getBaseMetaTileEntity().getUniversalEnergyStored() > 100) checkRecipe();
}
}
}
private void addOutputProducts() {
if (mOutputItem1 != null)
if (mInventory[2] == null)
mInventory[2] = GT_Utility.copy(mOutputItem1);
else if (GT_Utility.areStacksEqual(mInventory[2], mOutputItem1))
mInventory[2].stackSize = Math.min(mOutputItem1.getMaxStackSize(), mOutputItem1.stackSize + mInventory[2].stackSize);
if (mOutputItem2 != null)
if (mInventory[3] == null)
mInventory[3] = GT_Utility.copy(mOutputItem2);
else if (GT_Utility.areStacksEqual(mInventory[3], mOutputItem2))
mInventory[3].stackSize = Math.min(mOutputItem2.getMaxStackSize(), mOutputItem2.stackSize + mInventory[3].stackSize);
if (mOutputItem3 != null)
if (mInventory[4] == null)
mInventory[4] = GT_Utility.copy(mOutputItem3);
else if (GT_Utility.areStacksEqual(mInventory[4], mOutputItem3))
mInventory[4].stackSize = Math.min(mOutputItem3.getMaxStackSize(), mOutputItem3.stackSize + mInventory[4].stackSize);
if (mOutputItem4 != null)
if (mInventory[5] == null)
mInventory[5] = GT_Utility.copy(mOutputItem4);
else if (GT_Utility.areStacksEqual(mInventory[5], mOutputItem4))
mInventory[5].stackSize = Math.min(mOutputItem4.getMaxStackSize(), mOutputItem4.stackSize + mInventory[5].stackSize);
}
private boolean spaceForOutput(Recipe aRecipe) {
if (mInventory[2] == null || aRecipe.getOutput(0) == null || (mInventory[2].stackSize + aRecipe.getOutput(0).stackSize <= mInventory[2].getMaxStackSize() && GT_Utility.areStacksEqual(mInventory[2], aRecipe.getOutput(0))))
if (mInventory[3] == null || aRecipe.getOutput(1) == null || (mInventory[3].stackSize + aRecipe.getOutput(1).stackSize <= mInventory[3].getMaxStackSize() && GT_Utility.areStacksEqual(mInventory[3], aRecipe.getOutput(1))))
if (mInventory[4] == null || aRecipe.getOutput(2) == null || (mInventory[4].stackSize + aRecipe.getOutput(2).stackSize <= mInventory[4].getMaxStackSize() && GT_Utility.areStacksEqual(mInventory[4], aRecipe.getOutput(2))))
if (mInventory[5] == null || aRecipe.getOutput(3) == null || (mInventory[5].stackSize + aRecipe.getOutput(3).stackSize <= mInventory[5].getMaxStackSize() && GT_Utility.areStacksEqual(mInventory[5], aRecipe.getOutput(3))))
return true;
return false;
}
private boolean checkRecipe() {
if (!mMachine) return false;
Recipe tRecipe = Recipe.findEqualRecipe(false, false, Recipe.sDistillationRecipes, mInventory[0], mInventory[1]);
if (tRecipe != null) {
if (spaceForOutput(tRecipe)) {
if (tRecipe.isRecipeInputEqual(true, true, mInventory[0], mInventory[1])) {
if (mInventory[0] != null) if (mInventory[0].stackSize == 0) mInventory[0] = null;
if (mInventory[1] != null) if (mInventory[1].stackSize == 0) mInventory[1] = null;
mMaxProgresstime = tRecipe.mDuration;
mEUt = tRecipe.mEUt;
mOutputItem1 = GT_Utility.copy(tRecipe.getOutput(0));
mOutputItem2 = GT_Utility.copy(tRecipe.getOutput(1));
mOutputItem3 = GT_Utility.copy(tRecipe.getOutput(2));
mOutputItem4 = GT_Utility.copy(tRecipe.getOutput(3));
return true;
}
}
}
return false;
super.onPostTick();
}
@Override
@ -231,20 +84,7 @@ public class GT_MetaTileEntity_DistillationTower extends MetaTileEntity {
return 71;
return 78;
}
@Override
public Map<String, List<Object>> getInfoData() {
return InfoBuilder.create()
.newKey("sensor.progress.percentage", mProgresstime * 100.0D / mMaxProgresstime)
.newKey("sensor.progress.secs", mProgresstime / 20)
.newKey("sensor.progress.secs", mMaxProgresstime / 20)
.build();
}
@Override
public boolean isGivingInformation() {
return true;
}
@Override
public String getDescription() {
return "metatileentity.GT_DistillationTower.tooltip";

View file

@ -1,104 +1,73 @@
package gregtechmod.common.tileentities.machines.multi;
import java.util.List;
import java.util.Map;
import gregtechmod.api.GregTech_API;
import gregtechmod.api.interfaces.IGregTechTileEntity;
import gregtechmod.api.metatileentity.MetaTileEntity;
import gregtechmod.api.recipe.Recipe;
import gregtechmod.api.util.GT_ModHandler;
import gregtechmod.api.util.GT_Utility;
import gregtechmod.api.util.InfoBuilder;
import gregtechmod.api.util.ListAdapter;
import gregtechmod.common.recipe.RecipeMaps;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidStack;
public class GT_MetaTileEntity_Sawmill extends MetaTileEntity {
public class GT_MetaTileEntity_Sawmill extends BaseMultiWorkable {
public int mProgresstime = 0, mMaxProgresstime = 0, mEUt = 0, mUpdate = 5, mWaterAmount = 0;
private ItemStack mOutputItem1, mOutputItem2, mOutputItem3;
public boolean mMachine = false;
private FluidStack[] fluids = new FluidStack[] { GT_ModHandler.getWater(0) };
public GT_MetaTileEntity_Sawmill(int aID, String mName) {
super(aID, mName);
super(aID, mName, RecipeMaps.SAWMILL);
}
public GT_MetaTileEntity_Sawmill() {
super(RecipeMaps.SAWMILL);
}
@Override public boolean isTransformerUpgradable() {return true;}
@Override public boolean isOverclockerUpgradable() {return true;}
@Override public boolean isBatteryUpgradable() {return true;}
@Override public boolean isSimpleMachine() {return false;}
@Override public boolean isFacingValid(byte aFacing) {return aFacing == 0;}
@Override public boolean isEnetInput() {return true;}
@Override public boolean isInputFacing(byte aSide) {return true;}
@Override public int maxEUInput() {return 128;}
@Override public int maxEUStore() {return 10000;}
@Override public int maxRFStore() {return maxEUStore();}
@Override public int maxSteamStore() {return maxEUStore();}
@Override public int getInvSize() {return 6;}
@Override public void onRightclick(EntityPlayer aPlayer) {getBaseMetaTileEntity().openGUI(aPlayer, 116);}
@Override public boolean isAccessAllowed(EntityPlayer aPlayer) {return true;}
@Override public int getProgresstime() {return mProgresstime;}
@Override public int maxProgresstime() {return mMaxProgresstime;}
@Override public int increaseProgress(int aProgress) {mProgresstime += aProgress; return mMaxProgresstime-mProgresstime;}
@Override
public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {
return new GT_MetaTileEntity_Sawmill();
}
@Override
public List<ItemStack> getOutputItems() {
return new ListAdapter<>(mInventory, 2, 4);
}
@Override
public List<FluidStack> getFluidInputs() {
if (fluids == null) {
return new ListAdapter<>(new FluidStack[1]);
}
return new ListAdapter<>(fluids);
}
@Override
public void saveNBTData(NBTTagCompound aNBT) {
aNBT.setInteger("mEUt", mEUt);
aNBT.setInteger("mWaterAmount", mWaterAmount);
aNBT.setInteger("mProgresstime", mProgresstime);
aNBT.setInteger("mMaxProgresstime", mMaxProgresstime);
if (mOutputItem1 != null) {
NBTTagCompound tNBT = new NBTTagCompound();
mOutputItem1.writeToNBT(tNBT);
aNBT.setTag("mOutputItem1", tNBT);
}
if (mOutputItem2 != null) {
NBTTagCompound tNBT = new NBTTagCompound();
mOutputItem2.writeToNBT(tNBT);
aNBT.setTag("mOutputItem2", tNBT);
}
if (mOutputItem3 != null) {
NBTTagCompound tNBT = new NBTTagCompound();
mOutputItem3.writeToNBT(tNBT);
aNBT.setTag("mOutputItem3", tNBT);
}
super.saveNBTData(aNBT);
if (GT_Utility.isFluidStackValid(fluids[0])) {
fluids[0].writeToNBT(aNBT);
}
}
@Override
public void loadNBTData(NBTTagCompound aNBT) {
mUpdate = 5;
mEUt = aNBT.getInteger("mEUt");
mWaterAmount = aNBT.getInteger("mWaterAmount");
mProgresstime = aNBT.getInteger("mProgresstime");
mMaxProgresstime = aNBT.getInteger("mMaxProgresstime");
NBTTagCompound tNBT1 = (NBTTagCompound)aNBT.getTag("mOutputItem1");
if (tNBT1 != null) {
mOutputItem1 = GT_Utility.loadItem(tNBT1);
}
NBTTagCompound tNBT2 = (NBTTagCompound)aNBT.getTag("mOutputItem2");
if (tNBT2 != null) {
mOutputItem2 = GT_Utility.loadItem(tNBT2);
}
NBTTagCompound tNBT3 = (NBTTagCompound)aNBT.getTag("mOutputItem3");
if (tNBT3 != null) {
mOutputItem3 = GT_Utility.loadItem(tNBT3);
super.loadNBTData(aNBT);
FluidStack stack = FluidStack.loadFluidStackFromNBT(aNBT);
if (GT_Utility.isFluidStackValid(stack)) {
fluids[0] = stack;
}
}
private boolean checkMachine() {
protected boolean checkMachine() {
for (int i = -1; i < 2; i++) for (int j = 1; j < 2; j++) for (int k = -1; k < 2; k++) {
if (getBaseMetaTileEntity().getBlockOffset(i, j-2, k) != GregTech_API.sBlockList[0]) return false;
if (getBaseMetaTileEntity().getMetaIDOffset (i, j-2, k) != (i==0&&k==0?14:13)) return false;
@ -106,105 +75,6 @@ public class GT_MetaTileEntity_Sawmill extends MetaTileEntity {
return true;
}
@Override
public void onMachineBlockUpdate() {
mUpdate = 5;
}
@Override
public void onPostTick() {
if (getBaseMetaTileEntity().isServerSide()) {
if (mUpdate--==0) {
mMachine = checkMachine();
}
getBaseMetaTileEntity().setActive(mMachine);
if (mMachine && mMaxProgresstime > 0) {
if (mProgresstime < 0 || getBaseMetaTileEntity().decreaseStoredEnergyUnits(mEUt*(int)Math.pow(4, getBaseMetaTileEntity().getOverclockerUpgradeCount()), false)) {
if ((mProgresstime+=(int)Math.pow(2, getBaseMetaTileEntity().getOverclockerUpgradeCount()))>=mMaxProgresstime) {
addOutputProducts();
mOutputItem1 = null;
mOutputItem2 = null;
mOutputItem3 = null;
mProgresstime = 0;
mMaxProgresstime = 0;
getBaseMetaTileEntity().setErrorDisplayID(0);
}
} else {
if (GregTech_API.sConstantEnergy) {
mProgresstime = -10;
getBaseMetaTileEntity().setErrorDisplayID(1);
}
}
} else {
if (getBaseMetaTileEntity().isAllowedToWork() && getBaseMetaTileEntity().getUniversalEnergyStored() > 100) checkRecipe();
}
}
}
private void addOutputProducts() {
if (mOutputItem1 != null)
if (mInventory[2] == null)
mInventory[2] = GT_Utility.copy(mOutputItem1);
else if (GT_Utility.areStacksEqual(mInventory[2], mOutputItem1))
mInventory[2].stackSize = Math.min(mOutputItem1.getMaxStackSize(), mOutputItem1.stackSize + mInventory[2].stackSize);
if (mOutputItem2 != null)
if (mInventory[3] == null)
mInventory[3] = GT_Utility.copy(mOutputItem2);
else if (GT_Utility.areStacksEqual(mInventory[3], mOutputItem2))
mInventory[3].stackSize = Math.min(mOutputItem2.getMaxStackSize(), mOutputItem2.stackSize + mInventory[3].stackSize);
if (mOutputItem3 != null)
if (mInventory[4] == null)
mInventory[4] = GT_Utility.copy(mOutputItem3);
else if (GT_Utility.areStacksEqual(mInventory[4], mOutputItem3))
mInventory[4].stackSize = Math.min(mOutputItem3.getMaxStackSize(), mOutputItem3.stackSize + mInventory[4].stackSize);
}
private boolean spaceForOutput(Recipe aRecipe) {
if (mInventory[2] == null || aRecipe.getOutput(0) == null || (mInventory[2].stackSize + aRecipe.getOutput(0).stackSize <= mInventory[2].getMaxStackSize() && GT_Utility.areStacksEqual(mInventory[2], aRecipe.getOutput(0))))
if (mInventory[3] == null || aRecipe.getOutput(1) == null || (mInventory[3].stackSize + aRecipe.getOutput(1).stackSize <= mInventory[3].getMaxStackSize() && GT_Utility.areStacksEqual(mInventory[3], aRecipe.getOutput(1))))
if (mInventory[4] == null || aRecipe.getOutput(2) == null || (mInventory[4].stackSize + aRecipe.getOutput(2).stackSize <= mInventory[4].getMaxStackSize() && GT_Utility.areStacksEqual(mInventory[4], aRecipe.getOutput(2))))
if (mInventory[5] == null || aRecipe.getOutput(3) == null || (mInventory[5].stackSize + aRecipe.getOutput(3).stackSize <= mInventory[5].getMaxStackSize() && GT_Utility.areStacksEqual(mInventory[5], aRecipe.getOutput(3))))
return true;
return false;
}
private boolean checkRecipe() {
if (!mMachine) return false;
Recipe tRecipe = Recipe.findEqualRecipe(false, false, Recipe.sSawmillRecipes, mInventory[0], mInventory[1]);
if (tRecipe != null) {
if (spaceForOutput(tRecipe)) {
if (tRecipe.isRecipeInputEqual(true, true, mInventory[0], mInventory[1])) {
if (mInventory[0] != null) if (mInventory[0].stackSize == 0) mInventory[0] = null;
if (mInventory[1] != null) if (mInventory[1].stackSize == 0) mInventory[1] = null;
mMaxProgresstime = tRecipe.mDuration;
mEUt = tRecipe.mEUt;
mOutputItem1 = GT_Utility.copy(tRecipe.getOutput(0));
mOutputItem2 = GT_Utility.copy(tRecipe.getOutput(1));
mOutputItem3 = GT_Utility.copy(tRecipe.getOutput(2));
return true;
}
}
} else {
ItemStack tWaterStack = (mWaterAmount>=1000?GT_ModHandler.getWaterCell(mWaterAmount/1000):null);
tRecipe = Recipe.findEqualRecipe(false, false, Recipe.sSawmillRecipes, mInventory[0], tWaterStack);
if (tRecipe != null && spaceForOutput(tRecipe)) {
if (tRecipe.isRecipeInputEqual(true, true, mInventory[0], tWaterStack)) {
if (mInventory[0] != null) if (mInventory[0].stackSize == 0) mInventory[0] = null;
mWaterAmount-=((mWaterAmount/1000)-tWaterStack.stackSize)*1000;
mMaxProgresstime = tRecipe.mDuration;
mEUt = tRecipe.mEUt;
mOutputItem1 = GT_Utility.copy(tRecipe.getOutput(0));
mOutputItem2 = GT_Utility.copy(tRecipe.getOutput(1));
if (!GT_Utility.areStacksEqual(tRecipe.getOutput(2), GT_ModHandler.getEmptyCell(1))) mOutputItem3 = GT_Utility.copy(tRecipe.getOutput(2));
return true;
}
}
}
return false;
}
@Override
public boolean allowPullStack(int aIndex, byte aSide, ItemStack aStack) {
return aIndex>1;
@ -225,20 +95,7 @@ public class GT_MetaTileEntity_Sawmill extends MetaTileEntity {
return 76;
return 75;
}
@Override
public Map<String, List<Object>> getInfoData() {
return InfoBuilder.create()
.newKey("sensor.progress.percentage", mProgresstime * 100.0D / mMaxProgresstime)
.newKey("sensor.progress.secs", mProgresstime / 20)
.newKey("sensor.progress.secs", mMaxProgresstime / 20)
.build();
}
@Override
public boolean isGivingInformation() {
return true;
}
@Override
public String getDescription() {
return "metatileentity.GT_Sawmill.tooltip";
@ -246,25 +103,22 @@ public class GT_MetaTileEntity_Sawmill extends MetaTileEntity {
@Override
public int fill(FluidStack resource, boolean doFill) {
if (resource == null || resource.getFluidID() <= 0) return 0;
FluidStack tLiquid = GT_ModHandler.getWater(mWaterAmount);
if (!tLiquid.isFluidEqual(resource)) return 0;
int space = getCapacity() - tLiquid.amount;
if (resource.amount <= space) {
if (doFill && space > 0) {
mWaterAmount += resource.amount;
if (GT_Utility.isFluidStackValid(resource)) {
int space = getCapacity() - fluids[0].amount;
int toFill = resource.amount <= space ? resource.amount : space;
if (doFill) {
fluids[0].amount += toFill;
// TODO could be dupe, may change resource
}
return resource.amount;
} else {
if (doFill && space > 0) {
mWaterAmount = getCapacity();
}
return space;
return toFill;
}
return 0;
}
@Override public FluidStack getFluid() {return GT_ModHandler.getWater(mWaterAmount);}
@Override public FluidStack getFluid() {return fluids[0].copy();}
@Override public int getFluidAmount() {return fluids[0].amount;}
@Override public int getTankPressure() {return -100;}
@Override public int getCapacity() {return 10000;}
}

View file

@ -61,7 +61,7 @@ public class SawmillRecipeHandler extends GT_RecipeHandler {
return new CachedGT_Recipe(irecipe) {
@Override
protected Pair<Integer, Integer> getInputAligment(int itemIdx) {
return Pair.of(34, 16 - sOffsetY + (itemIdx * 18));
return Pair.of(29, 16 - sOffsetY + (itemIdx * 18));
}
@Override