Added configurable weights to the ItemDistributor sides.
This commit is contained in:
parent
22fdaed164
commit
95a1d46086
1 changed files with 35 additions and 14 deletions
|
@ -9,13 +9,14 @@ import gregtech.api.objects.GT_RenderedTexture;
|
||||||
import gregtech.api.util.GT_Utility;
|
import gregtech.api.util.GT_Utility;
|
||||||
import gregtech.common.gui.GT_Container_ChestBuffer;
|
import gregtech.common.gui.GT_Container_ChestBuffer;
|
||||||
import gregtech.common.gui.GT_GUIContainer_ChestBuffer;
|
import gregtech.common.gui.GT_GUIContainer_ChestBuffer;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.entity.player.InventoryPlayer;
|
import net.minecraft.entity.player.InventoryPlayer;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
|
||||||
public class GT_MetaTileEntity_ItemDistributor extends GT_MetaTileEntity_Buffer {
|
public class GT_MetaTileEntity_ItemDistributor extends GT_MetaTileEntity_Buffer {
|
||||||
private byte[] weights = {1, 1, 1, 1, 1, 1};
|
private byte[] sideWeights = new byte[6];
|
||||||
boolean onlyOutputToInventories = true;
|
private byte currentSide = 0, currentSideItemCount = 0;
|
||||||
|
|
||||||
public GT_MetaTileEntity_ItemDistributor(int aID, String aName, String aNameRegional, int aTier) {
|
public GT_MetaTileEntity_ItemDistributor(int aID, String aName, String aNameRegional, int aTier) {
|
||||||
super(aID, aName, aNameRegional, aTier, 28, "Buffering lots of incoming Items");
|
super(aID, aName, aNameRegional, aTier, 28, "Buffering lots of incoming Items");
|
||||||
}
|
}
|
||||||
|
@ -34,7 +35,8 @@ public class GT_MetaTileEntity_ItemDistributor extends GT_MetaTileEntity_Buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {
|
public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {
|
||||||
return new GT_MetaTileEntity_ItemDistributor(this.mName, this.mTier, this.mInventory.length, this.mDescriptionArray, this.mTextures);
|
return new GT_MetaTileEntity_ItemDistributor(this.mName, this.mTier, this.mInventory.length, this.mDescriptionArray,
|
||||||
|
this.mTextures);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ITexture getOverlayIcon() {
|
public ITexture getOverlayIcon() {
|
||||||
|
@ -47,18 +49,30 @@ public class GT_MetaTileEntity_ItemDistributor extends GT_MetaTileEntity_Buffer
|
||||||
|
|
||||||
protected void moveItems(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) {
|
protected void moveItems(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) {
|
||||||
fillStacksIntoFirstSlots();
|
fillStacksIntoFirstSlots();
|
||||||
int tCost = 0;
|
int movedItems = 0;
|
||||||
for (byte side = 0; side < 6; side++) {
|
TileEntity adjacentTileEntity = aBaseMetaTileEntity.getTileEntityAtSide(currentSide);
|
||||||
TileEntity adjacentTileEntity = aBaseMetaTileEntity.getTileEntityAtSide(side);
|
int inspectedSides = 0;
|
||||||
if(!onlyOutputToInventories || adjacentTileEntity != null){
|
while (sideWeights[currentSide] == 0) {
|
||||||
tCost = GT_Utility.moveOneItemStack(aBaseMetaTileEntity, adjacentTileEntity,
|
currentSide = (byte) ((currentSide + 1) % 6);
|
||||||
side, GT_Utility.getOppositeSide(side), null, false, (byte) 64, (byte) 1, weights[side], weights[side]);
|
currentSideItemCount = 0;
|
||||||
|
adjacentTileEntity = aBaseMetaTileEntity.getTileEntityAtSide(currentSide);
|
||||||
|
inspectedSides += 1;
|
||||||
|
if (inspectedSides == 6) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (tCost > 0 || aBaseMetaTileEntity.hasInventoryBeenModified()) {
|
movedItems = GT_Utility.moveOneItemStack(aBaseMetaTileEntity, adjacentTileEntity, currentSide,
|
||||||
mSuccess = 50;
|
GT_Utility.getOppositeSide(currentSide), null, false, (byte) 64, (byte) 1,
|
||||||
aBaseMetaTileEntity.decreaseStoredEnergyUnits(Math.abs(tCost), true);
|
(byte) (sideWeights[currentSide] - currentSideItemCount), (byte) 1);
|
||||||
}
|
currentSideItemCount += movedItems;
|
||||||
|
if (currentSideItemCount >= sideWeights[currentSide]) {
|
||||||
|
currentSide = (byte) ((currentSide + 1) % 6);
|
||||||
|
currentSideItemCount = 0;
|
||||||
|
}
|
||||||
|
if (movedItems > 0 || aBaseMetaTileEntity.hasInventoryBeenModified()) {
|
||||||
|
mSuccess = 50;
|
||||||
|
aBaseMetaTileEntity.decreaseStoredEnergyUnits(Math.abs(movedItems), true);
|
||||||
|
}
|
||||||
fillStacksIntoFirstSlots();
|
fillStacksIntoFirstSlots();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,6 +88,13 @@ public class GT_MetaTileEntity_ItemDistributor extends GT_MetaTileEntity_Buffer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) {
|
||||||
|
sideWeights[aSide] += aPlayer.isSneaking() ? -1 : 1;
|
||||||
|
sideWeights[aSide] = (byte) ((sideWeights[aSide] + 128) % 128);
|
||||||
|
GT_Utility.sendChatToPlayer(aPlayer, trans("110", "Side Weight: " + sideWeights[aSide]));
|
||||||
|
}
|
||||||
|
|
||||||
public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) {
|
public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) {
|
||||||
return new GT_Container_ChestBuffer(aPlayerInventory, aBaseMetaTileEntity);
|
return new GT_Container_ChestBuffer(aPlayerInventory, aBaseMetaTileEntity);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue