diff options
Diffstat (limited to 'src')
5 files changed, 135 insertions, 31 deletions
diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java index dfefd70687..0d06c4ec03 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java @@ -1,5 +1,11 @@ package gregtech.api.metatileentity;
+import static gregtech.api.enums.GT_Values.NW;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
import cpw.mods.fml.common.FMLLog;
import gregtech.api.GregTech_API;
import gregtech.api.enums.Textures;
@@ -9,7 +15,11 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.interfaces.tileentity.IPipeRenderedTileEntity;
import gregtech.api.net.GT_Packet_TileEntity;
import gregtech.api.objects.GT_ItemStack;
-import gregtech.api.util.*;
+import gregtech.api.util.GT_CoverBehavior;
+import gregtech.api.util.GT_Log;
+import gregtech.api.util.GT_ModHandler;
+import gregtech.api.util.GT_OreDictUnificator;
+import gregtech.api.util.GT_Utility;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
@@ -28,12 +38,6 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import static gregtech.api.enums.GT_Values.NW;
-
/**
* NEVER INCLUDE THIS FILE IN YOUR MOD!!!
* <p/>
@@ -179,7 +183,7 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE mMetaTileEntity.setBaseMetaTileEntity(this);
}
- long tTime = System.currentTimeMillis();
+ long tTime = System.nanoTime();
int tCode = 0;
try { for (tCode = 0; hasValidMetaTileEntity() && tCode >= 0; ) {
@@ -294,11 +298,11 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE }
if (isServerSide() && hasValidMetaTileEntity()) {
- tTime = System.currentTimeMillis() - tTime;
+ tTime = System.nanoTime() - tTime;
if (mTimeStatistics.length > 0)
mTimeStatistics[mTimeStatisticsIndex = (mTimeStatisticsIndex + 1) % mTimeStatistics.length] = (int) tTime;
- if (tTime > 0 && tTime > GregTech_API.MILLISECOND_THRESHOLD_UNTIL_LAG_WARNING && mTickTimer > 1000 && getMetaTileEntity().doTickProfilingMessageDuringThisTick() && mLagWarningCount++ < 10)
- FMLLog.warning("WARNING: Possible Lag Source at [%s,%s,%s] in Dimension %s with %s ms caused by an instance of %s", xCoord, yCoord, zCoord, worldObj.provider.dimensionId, tTime, getMetaTileEntity().getClass());
+ if (tTime > 0 && tTime > (GregTech_API.MILLISECOND_THRESHOLD_UNTIL_LAG_WARNING*1000000) && mTickTimer > 1000 && getMetaTileEntity().doTickProfilingMessageDuringThisTick() && mLagWarningCount++ < 10)
+ FMLLog.warning("WARNING: Possible Lag Source at [%s,%s,%s] in Dimension %s with %s ns caused by an instance of %s", xCoord, yCoord, zCoord, worldObj.provider.dimensionId, tTime, getMetaTileEntity().getClass());
}
mWorkUpdate = mInventoryChanged = false;
@@ -391,8 +395,14 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE if (aLogLevel > 1) {
if (mTimeStatistics.length > 0) {
double tAverageTime = 0;
- for (int tTime : mTimeStatistics) tAverageTime += tTime;
- tList.add("Average CPU-load of ~" + (tAverageTime / mTimeStatistics.length) + "ms since " + mTimeStatistics.length + " ticks.");
+ double tWorstTime = 0;
+ for (int tTime : mTimeStatistics) {
+ tAverageTime += tTime;
+ if (tTime > tWorstTime) {
+ tWorstTime = tTime;
+ }
+ }
+ tList.add("Average CPU-load of ~" + (tAverageTime / mTimeStatistics.length) + "ns since " + mTimeStatistics.length + " ticks with worst time of " + tWorstTime + "ns.");
}
if (mLagWarningCount > 0) {
tList.add("Caused " + (mLagWarningCount >= 10 ? "more than 10" : mLagWarningCount) + " Lag Spike Warnings (anything taking longer than " + GregTech_API.MILLISECOND_THRESHOLD_UNTIL_LAG_WARNING + "ms) on the Server.");
@@ -1180,11 +1190,11 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE return false;
if(isFill && mMetaTileEntity.isLiquidInput((byte) aSide.ordinal())
- && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidIn((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()), mMetaTileEntity.getFluid() == null ? null : mMetaTileEntity.getFluid().getFluid(), this))
+ && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidIn((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()), aFluid, this))
return true;
if (!isFill && mMetaTileEntity.isLiquidOutput((byte) aSide.ordinal())
- && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()), mMetaTileEntity.getFluid() == null ? null : mMetaTileEntity.getFluid().getFluid(), this))
+ && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()),aFluid, this))
return true;
return false;
diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java index d44ada526f..95f3416a00 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java @@ -277,7 +277,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE } mRunningThroughTick = true; - long tTime = System.currentTimeMillis(); + long tTime = System.nanoTime(); int tCode = 0; boolean aSideServer = isServerSide(); boolean aSideClient = isClientSide(); @@ -573,11 +573,11 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE } if (aSideServer && hasValidMetaTileEntity()) { - tTime = System.currentTimeMillis() - tTime; + tTime = System.nanoTime() - tTime; if (mTimeStatistics.length > 0) mTimeStatistics[mTimeStatisticsIndex = (mTimeStatisticsIndex + 1) % mTimeStatistics.length] = (int) tTime; - if (tTime > 0 && tTime > GregTech_API.MILLISECOND_THRESHOLD_UNTIL_LAG_WARNING && mTickTimer > 1000 && getMetaTileEntity().doTickProfilingMessageDuringThisTick() && mLagWarningCount++ < 10) - System.out.println("WARNING: Possible Lag Source at [" + xCoord + ", " + yCoord + ", " + zCoord + "] in Dimension " + worldObj.provider.dimensionId + " with " + tTime + "ms caused by an instance of " + getMetaTileEntity().getClass()); + if (tTime > 0 && tTime > (GregTech_API.MILLISECOND_THRESHOLD_UNTIL_LAG_WARNING*1000000) && mTickTimer > 1000 && getMetaTileEntity().doTickProfilingMessageDuringThisTick() && mLagWarningCount++ < 10) + System.out.println("WARNING: Possible Lag Source at [" + xCoord + ", " + yCoord + ", " + zCoord + "] in Dimension " + worldObj.provider.dimensionId + " with " + tTime + "ns caused by an instance of " + getMetaTileEntity().getClass()); } mWorkUpdate = mInventoryChanged = mRunningThroughTick = false; @@ -706,8 +706,16 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE if (aLogLevel > 1) { if (mTimeStatistics.length > 0) { double tAverageTime = 0; - for (int tTime : mTimeStatistics) tAverageTime += tTime; - tList.add("Average CPU-load of ~" + (tAverageTime / mTimeStatistics.length) + "ms since " + mTimeStatistics.length + " ticks."); + double tWorstTime = 0; + for (int tTime : mTimeStatistics) { + tAverageTime += tTime; + if (tTime > tWorstTime) { + tWorstTime = tTime; + } + // Uncomment this line to print out tick-by-tick times. + //tList.add("tTime " + tTime); + } + tList.add("Average CPU-load of ~" + (tAverageTime / mTimeStatistics.length) + "ns over " + mTimeStatistics.length + " ticks with worst time of " + tWorstTime + "ns."); } if (mLagWarningCount > 0) { tList.add("Caused " + (mLagWarningCount >= 10 ? "more than 10" : mLagWarningCount) + " Lag Spike Warnings (anything taking longer than " + GregTech_API.MILLISECOND_THRESHOLD_UNTIL_LAG_WARNING + "ms) on the Server."); diff --git a/src/main/java/gregtech/common/covers/GT_Cover_Fluidfilter.java b/src/main/java/gregtech/common/covers/GT_Cover_Fluidfilter.java index 2d271ffccf..46ac0b42a3 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_Fluidfilter.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_Fluidfilter.java @@ -61,16 +61,18 @@ public class GT_Cover_Fluidfilter @Override public boolean letsFluidIn(byte aSide, int aCoverID, int aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { - if(aFluid==null){return true;} + if(aFluid==null){ + return true; + } int aFilterMode = aCoverVariable & 7; int aFilterFluid = aCoverVariable >>> 3; - return aFluid.getID() == aFilterFluid ? (aFilterMode == 0 || aFilterMode == 2 ? true : false) : (aFilterMode == 1 || aFilterMode == 3 ? true : false); + return aFluid.getID() == aFilterFluid ? aFilterMode == 0 || aFilterMode == 2 : aFilterMode == 1 || aFilterMode == 3; } @Override public boolean letsFluidOut(byte aSide, int aCoverID, int aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { int aFilterMode = aCoverVariable & 7; - return aFilterMode == 0 || aFilterMode == 1 ? false : true; + return aFilterMode != 0 && aFilterMode != 1; } public boolean alwaysLookConnected(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { diff --git a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ChestBuffer.java b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ChestBuffer.java index 7385bb31b1..e73631cd93 100644 --- a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ChestBuffer.java +++ b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ChestBuffer.java @@ -10,6 +10,12 @@ import gregtech.api.util.GT_Utility; import gregtech.common.gui.GT_Container_ChestBuffer; import gregtech.common.gui.GT_GUIContainer_ChestBuffer; import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; + +import java.util.Arrays; +import java.util.Comparator; public class GT_MetaTileEntity_ChestBuffer extends GT_MetaTileEntity_Buffer { @@ -49,16 +55,94 @@ public class GT_MetaTileEntity_ChestBuffer } protected void moveItems(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { - fillStacksIntoFirstSlots(); - super.moveItems(aBaseMetaTileEntity, aTimer); - fillStacksIntoFirstSlots(); + if(aBaseMetaTileEntity.hasInventoryBeenModified()) { + fillStacksIntoFirstSlots(); + } + // mSuccess will be negative if the call is caused by the %200 aTimer, always try to push. Otherwise it will be positive. + // For the first 6 ticks after a successful move (49->44), push every tick. Then go to every 5 ticks. + if ( (mSuccess <= 0 ) || (mSuccess > 43) || ((mSuccess % 5) == 0 )){ + super.moveItems(aBaseMetaTileEntity, aTimer); + } + // mSuccesss is set to 50 on a successful move + if(mSuccess == 50) { + fillStacksIntoFirstSlots(); + } + if(mSuccess < 0) { + mSuccess = 0; + } + } + +// Implementation using Java built in sort algorithm +// Uses terribad string comparison to sort against. Would be better if we did something else? + protected void sortStacks() { + Arrays.sort(this.mInventory, new Comparator<ItemStack>() { + @Override + // Taken from https://gist.github.com/Choonster/876acc3217229e172e46 + public int compare(ItemStack o1, ItemStack o2) { + if( o2 == null ) + return -1; + if( o1 == null ) + return 1; + Item item1 = o1.getItem(); + Item item2 = o2.getItem(); + + // If item1 is a block and item2 isn't, sort item1 before item2 + if (((item1 instanceof ItemBlock)) && (!(item2 instanceof ItemBlock))) { + return -1; + } + + // If item2 is a block and item1 isn't, sort item1 after item2 + if (((item2 instanceof ItemBlock)) && (!(item1 instanceof ItemBlock))) { + return 1; + } + + // If the items are blocks, use the string comparison + if ((item1 instanceof ItemBlock)) { // only need to check one since we did the check above + String displayName1 = o1.getDisplayName(); + String displayName2 = o2.getDisplayName(); + int result = displayName1.compareToIgnoreCase(displayName2); + //System.out.println("sorter: " + displayName1 + " " + displayName2 + " " + result); + return result; + } else + { + // Not a block. Use the ID and damage to compare them. + int id1 = Item.getIdFromItem( item1 ); + int id2 = Item.getIdFromItem( item2 ); + if ( id1 < id2 ) { + return -1; + } + if ( id1 > id2 ) { + return 1; + } + // id1 must equal id2, get their damage and compare + id1 = o1.getItemDamage(); + id2 = o2.getItemDamage(); + + if ( id1 < id2 ) { + return -1; + } + if ( id1 > id2 ) { + return 1; + } + return 0; + } + } + }); } protected void fillStacksIntoFirstSlots() { - for (int i = 0; i < this.mInventory.length - 1; i++) { - for (int j = i + 1; j < this.mInventory.length - 1; j++) { - if ((this.mInventory[j] != null) && ((this.mInventory[i] == null) || (GT_Utility.areStacksEqual(this.mInventory[i], this.mInventory[j])))) { + sortStacks(); + // Merge small stacks together + for (int i = 0; i < this.mInventory.length-1;) { + //System.out.println( (this.mInventory[i] == null) ? "Slot empty " + i : "Slot " + i + " holds " + this.mInventory[i].getDisplayName()); + for (int j = i + 1; j < this.mInventory.length; j++) { + if ((this.mInventory[j] != null) && ((GT_Utility.areStacksEqual(this.mInventory[i], this.mInventory[j])))) { GT_Utility.moveStackFromSlotAToSlotB(getBaseMetaTileEntity(), getBaseMetaTileEntity(), j, i, (byte) 64, (byte) 1, (byte) 64, (byte) 1); + //System.out.println( "Moving slot " + j + " into slot " + i ); + } + else { + i=j; + break; // No more matching items for this i, do next i } } } diff --git a/src/main/java/gregtech/loaders/postload/GT_MachineRecipeLoader.java b/src/main/java/gregtech/loaders/postload/GT_MachineRecipeLoader.java index b60b7dc5c2..8d9f567b61 100644 --- a/src/main/java/gregtech/loaders/postload/GT_MachineRecipeLoader.java +++ b/src/main/java/gregtech/loaders/postload/GT_MachineRecipeLoader.java @@ -100,7 +100,7 @@ public class GT_MachineRecipeLoader implements Runnable { GT_Values.RA.addMixerRecipe(GT_OreDictUnificator.get(tPrefix, Materials.Copper, 3L), GT_OreDictUnificator.get(tPrefix, Materials.Zinc, 1L), GT_Values.NI, GT_Values.NI, GT_Values.NI, GT_Utility.getIntegratedCircuit(1), GT_Values.NF, GT_Values.NF, GT_OreDictUnificator.getDust(Materials.Brass, 4L * tPrefix.mMaterialAmount), (int) (400L * tPrefix.mMaterialAmount / 3628800L), 8); GT_Values.RA.addMixerRecipe(GT_OreDictUnificator.get(tPrefix, Materials.Copper, 3L), GT_OreDictUnificator.get(tPrefix, Materials.Tin, 1L), GT_Values.NI, GT_Values.NI, GT_Values.NI, GT_Utility.getIntegratedCircuit(1), GT_Values.NF, GT_Values.NF, GT_OreDictUnificator.getDust(Materials.Bronze, 4L * tPrefix.mMaterialAmount), (int) (400L * tPrefix.mMaterialAmount / 3628800L), 8); GT_Values.RA.addMixerRecipe(GT_OreDictUnificator.get(tPrefix, Materials.Copper, 1L), GT_OreDictUnificator.get(tPrefix, Materials.Nickel, 1L), GT_Values.NI, GT_Values.NI, GT_Values.NI, GT_Utility.getIntegratedCircuit(1), GT_Values.NF, GT_Values.NF, GT_OreDictUnificator.getDust(Materials.Cupronickel, 2L * tPrefix.mMaterialAmount), (int) (200L * tPrefix.mMaterialAmount / 3628800L), 24); - GT_Values.RA.addMixerRecipe(GT_OreDictUnificator.get(tPrefix, Materials.Copper, 1L), GT_OreDictUnificator.get(tPrefix, Materials.Gold, 4L), GT_Values.NI, GT_Values.NI, GT_Values.NI, GT_Utility.getIntegratedCircuit(1), GT_Values.NF, GT_Values.NF, GT_OreDictUnificator.getDust(Materials.RoseGold, 5L * tPrefix.mMaterialAmount), (int) (500L * tPrefix.mMaterialAmount / 3628800L), 120); + GT_Values.RA.addMixerRecipe(GT_OreDictUnificator.get(tPrefix, Materials.Copper, 1L), GT_OreDictUnificator.get(tPrefix, Materials.Gold, 4L), GT_Values.NI, GT_Values.NI, GT_Values.NI, GT_Utility.getIntegratedCircuit(2), GT_Values.NF, GT_Values.NF, GT_OreDictUnificator.getDust(Materials.RoseGold, 5L * tPrefix.mMaterialAmount), (int) (500L * tPrefix.mMaterialAmount / 3628800L), 120); GT_Values.RA.addMixerRecipe(GT_OreDictUnificator.get(tPrefix, Materials.Copper, 1L), GT_OreDictUnificator.get(tPrefix, Materials.Silver, 4L), GT_Values.NI, GT_Values.NI, GT_Values.NI, GT_Utility.getIntegratedCircuit(1), GT_Values.NF, GT_Values.NF, GT_OreDictUnificator.getDust(Materials.SterlingSilver, 5L * tPrefix.mMaterialAmount), (int) (500L * tPrefix.mMaterialAmount / 3628800L), 120); GT_Values.RA.addMixerRecipe(GT_OreDictUnificator.get(tPrefix, Materials.Copper, 3L), GT_OreDictUnificator.get(tPrefix, Materials.Electrum, 2L), GT_Values.NI, GT_Values.NI, GT_Values.NI, GT_Utility.getIntegratedCircuit(1), GT_Values.NF, GT_Values.NF, GT_OreDictUnificator.getDust(Materials.BlackBronze, 5L * tPrefix.mMaterialAmount), (int) (500L * tPrefix.mMaterialAmount / 3628800L), 8); GT_Values.RA.addMixerRecipe(GT_OreDictUnificator.get(tPrefix, Materials.Bismuth, 1L), GT_OreDictUnificator.get(tPrefix, Materials.Brass, 4L), GT_Values.NI, GT_Values.NI, GT_Values.NI, GT_Utility.getIntegratedCircuit(1), GT_Values.NF, GT_Values.NF, GT_OreDictUnificator.getDust(Materials.BismuthBronze, 5L * tPrefix.mMaterialAmount), (int) (500L * tPrefix.mMaterialAmount / 3628800L), 8); |