Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
reobf committed Feb 11, 2024
1 parent c59a191 commit b5521b6
Show file tree
Hide file tree
Showing 11 changed files with 291 additions and 40 deletions.
104 changes: 76 additions & 28 deletions src/main/java/reobf/proghatches/block/TileIOHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import scala.None$;
import li.cil.oc.util.ExtendedWorld$;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import scala.Option;
import scala.Some;
import scala.Tuple2;
Expand Down Expand Up @@ -259,10 +261,19 @@ public void onConnect(Node node) {
public void onDisconnect(Node node) {


}
}
public void markDirty()
{
final Chunk chunk = worldObj.getChunkFromBlockCoords(xCoord, zCoord);
if (chunk != null) {
chunk.setChunkModified();
}
//this.worldObj.markTileEntityChunkModified(this.xCoord, this.yCoord, this.zCoord, this);

}
boolean init;
public void updateEntity() {
this.markDirty();

dead=false;
super.updateEntity();

Expand Down Expand Up @@ -510,37 +521,73 @@ public Object[] getCustomName(final Context context, final Arguments args) {
return new Object[]{TileIOHub.this.getInventoryName()};
}
@Callback(doc = "function(address:string):boolean -- Swap the inventory between this IO Hub and another IO Hub. Return whether operation successes.")
public Object[] swap(final Context context, final Arguments args) {

public Object[] swap(final Context context, final Arguments args) {markDirty();
final String address = args.checkString(0);
final int entry = args.checkInteger(1);
final int amount = args.optInteger(2, 1000);

final Node n =node().network().node(address);
if (n == null) {
return new Object[] {false,"no such component"};
// throw new IllegalArgumentException("no such component");
}
if (!(n instanceof Component)) {
return new Object[] {false,"no such component"};
//throw new IllegalArgumentException("no such component");
}
final li.cil.oc.api.network.Environment env = n.host();
if (!(env instanceof TileIOHub.OCApi)) {
return new Object[] {false,"not a iohub"};
//throw new IllegalArgumentException("not a iohub");
}
final TileIOHub.OCApi database = ( TileIOHub.OCApi)env;
database.markDirty();
//do not directly swap ref just in case...
ItemStack[] ia = Arrays.stream(inv).map(ItemStack::copy).toArray( ItemStack[]::new);
NBTTagCompound[] fa = Arrays.stream(ft).map(s->s.writeToNBT(new NBTTagCompound())).toArray(NBTTagCompound[]::new);
ItemStack[] ib = Arrays.stream(database.TileIOHubthis().inv).map(ItemStack::copy).toArray(ItemStack[]::new);
NBTTagCompound[] fb = Arrays.stream(database.TileIOHubthis().ft).map(s->s.writeToNBT(new NBTTagCompound())).toArray(NBTTagCompound[]::new);

for(int i=0;i<ib.length;i++){
database.TileIOHubthis().inv[i]=(ItemStack) ia[i];
inv[i]=(ItemStack) ib[i];
}
for(int i=0;i<fb.length;i++){
database.TileIOHubthis().ft[i].readFromNBT((NBTTagCompound) fa[i]);
ft[i].readFromNBT((NBTTagCompound) fb[i]);
}


return new Object[] {true};

throw new UnsupportedOperationException("NYI");
//throw new UnsupportedOperationException("NYI");
}


private TileIOHub TileIOHubthis(){return TileIOHub.this;}
private void markDirty(){TileIOHub.this.markDirty();}

@APIType({"fluid"})
@Callback(doc = "function(tankSide:number, inventorySide:number, inventorySlot:number [, count:number [, sourceTank:number [, outputSide:number[, outputSlot:number]]]]):boolean, number -- Transfer some fluid from the tank to the container. Returns operation result and filled amount")
public Object[] transferFluidFromTankToContainer(final Context context, final Arguments args) {
public Object[] transferFluidFromTankToContainer(final Context context, final Arguments args) {markDirty();
return FluidContainerTransfer$class.transferFluidFromTankToContainer(this, context, args);
}
@APIType({"fluid"})
@Callback(doc = "function(inventorySide:number, inventorySlot:number, tankSide:number [, count:number [, outputSide:number[, outputSlot:number]]]):boolean, number -- Transfer some fluid from the container to the tank. Returns operation result and filled amount")
public Object[] transferFluidFromContainerToTank(final Context context, final Arguments args) {
public Object[] transferFluidFromContainerToTank(final Context context, final Arguments args) {markDirty();
return FluidContainerTransfer$class.transferFluidFromContainerToTank(this, context, args);
}
@APIType({"fluid"})
@Callback(doc = "function(sourceSide:number, sourceSlot:number, sinkSide:number, sinkSlot:number[, count:number [, sourceOutputSide:number[, sinkOutputSide:number[, sourceOutputSlot:number[, sinkOutputSlot:number]]]]]):boolean, number -- Transfer some fluid from a container to another container. Returns operation result and filled amount")
public Object[] transferFluidBetweenContainers(final Context context, final Arguments args) {
public Object[] transferFluidBetweenContainers(final Context context, final Arguments args) {markDirty();
return FluidContainerTransfer$class.transferFluidBetweenContainers(this, context, args);
}
@APIType({"item"})
@Callback(doc = "function(sourceSide:number, sinkSide:number[, count:number[, sourceSlot:number[, sinkSlot:number]]]):number -- Transfer some items between two inventories.")
public Object[] transferItem(final Context context, final Arguments args) {
public Object[] transferItem(final Context context, final Arguments args) {markDirty();
return InventoryTransfer$class.transferItem(this, context, args);
}
@APIType({"fluid"})
@Callback(doc = "function(sourceSide:number, sinkSide:number[, count:number [, sourceTank:number]]):boolean, number -- Transfer some fluid between two tanks. Returns operation result and filled amount")
public Object[] transferFluid(final Context context, final Arguments args) {
public Object[] transferFluid(final Context context, final Arguments args) {markDirty();
return InventoryTransfer$class.transferFluid(this, context, args);
}
@APIType({"fluid"})
Expand Down Expand Up @@ -715,7 +762,7 @@ public Object[] getInventoryName(final Context context, final Arguments args) {
}
@APIType({"item"})
@Callback(doc = "function(side:number, slot:number, dbAddress:string, dbSlot:number):boolean -- Store an item stack description in the specified slot of the database with the specified address.")
public Object[] store(final Context context, final Arguments args) {
public Object[] store(final Context context, final Arguments args) {markDirty();
return WorldInventoryAnalytics$class.store(this, context, args);
}

Expand Down Expand Up @@ -743,12 +790,12 @@ public Object[] getFluidInInternalTank(final Context context, final Arguments ar
}
@APIType({"fluid"})
@Callback(doc = "function([amount:number]):boolean -- Transfers fluid from a tank in the selected inventory slot to the selected tank.")
public Object[] drain(final Context context, final Arguments args) {
public Object[] drain(final Context context, final Arguments args) {markDirty();
return TankInventoryControl$class.drain(this, context, args);
}
@APIType({"fluid"})
@Callback(doc = "function([amount:number]):boolean -- Transfers fluid from the selected tank to a tank in the selected inventory slot.")
public Object[] fill(final Context context, final Arguments args) {
public Object[] fill(final Context context, final Arguments args) {markDirty();
return TankInventoryControl$class.fill(this, context, args);
}@APIType({"item"})
@Callback(doc = "function([slot:number]):table -- Get a description of the stack in the specified slot or the selected slot.")
Expand All @@ -762,7 +809,7 @@ public Object[] isEquivalentTo(final Context context, final Arguments args) {
}
@APIType({"item"})
@Callback(doc = "function(slot:number, dbAddress:string, dbSlot:number):boolean -- an item stack description in the specified slot of the database with the specified address.")
public Object[] storeInternal(final Context context, final Arguments args) {
public Object[] storeInternal(final Context context, final Arguments args) {markDirty();
return InventoryAnalytics$class.storeInternal(this, context, args);
}
@APIType({"item"})
Expand Down Expand Up @@ -804,7 +851,7 @@ public int selectedSlot() {

@Override
public void selectedSlot_$eq(int arg0) {

markDirty();
if(arg0<0+1||arg0>=inv.length+1){throw new RuntimeException("invalid slot");}
slotselected=arg0;

Expand Down Expand Up @@ -860,6 +907,7 @@ public int selectedTank() {

@Override
public void selectedTank_$eq(int arg0) {
markDirty();
if(arg0<0+1||arg0>=ft.length+1){throw new RuntimeException("invalid slot");}
tankselected=arg0;

Expand Down Expand Up @@ -924,7 +972,7 @@ public Object[] compareFluidTo(final Context context, final Arguments args) {
}
@APIType({"fluid"})
@Callback(doc = "function(index:number[, count:number=1000]):boolean -- Move the specified amount of fluid from the selected tank into the specified tank.")
public Object[] transferFluidTo(final Context context, final Arguments args) {
public Object[] transferFluidTo(final Context context, final Arguments args) {markDirty();
return TankControl$class.transferFluidTo(this, context, args);
}
@APIType({"item"})
Expand Down Expand Up @@ -953,7 +1001,7 @@ public Object[] compareTo(final Context context, final Arguments args) {
}
@APIType({"item"})
@Callback(doc = "function(toSlot:number[, amount:number]):boolean -- Move up to the specified amount of items from the selected slot into the specified slot.")
public Object[] transferTo(final Context context, final Arguments args) {
public Object[] transferTo(final Context context, final Arguments args) {markDirty();
return InventoryControl$class.transferTo(this, context, args);
}

Expand All @@ -969,24 +1017,24 @@ public Object[] getItemInventorySize(final Context context, final Arguments args
}
@APIType({"item"})
@Callback(doc = "function(inventorySlot:number, slot:number[, count:number=64]):number -- Drops an item into the specified slot in the item inventory.")
public Object[] dropIntoItemInventory(final Context context, final Arguments args) {
public Object[] dropIntoItemInventory(final Context context, final Arguments args) {markDirty();
return ItemInventoryControl$class.dropIntoItemInventory(this, context, args);
}
@APIType({"item"})
@Callback(doc = "function(inventorySlot:number, slot:number[, count:number=64]):number -- Sucks an item out of the specified slot in the item inventory.")
public Object[] suckFromItemInventory(final Context context, final Arguments args) {
public Object[] suckFromItemInventory(final Context context, final Arguments args) {markDirty();
return ItemInventoryControl$class.suckFromItemInventory(this, context, args);
}

@APIType({"item"})

@Callback(doc = "function(facing:number, slot:number[, count:number[, fromSide:number]]):boolean -- Drops the selected item stack into the specified slot of an inventory.")
public Object[] dropIntoSlot(final Context context, final Arguments args) {
public Object[] dropIntoSlot(final Context context, final Arguments args) {markDirty();
return InventoryWorldControlMk2$class.dropIntoSlot(this, context, args);
}
@APIType({"item"})
@Callback(doc = "function(facing:number, slot:number[, count:number[, fromSide:number]]):boolean -- Sucks items from the specified slot of an inventory.")
public Object[] suckFromSlot(final Context context, final Arguments args) {
public Object[] suckFromSlot(final Context context, final Arguments args) {markDirty();
return InventoryWorldControlMk2$class.suckFromSlot(this, context, args);
}

Expand Down Expand Up @@ -1021,7 +1069,7 @@ public Object[] allItems(final Context context, final Arguments args) {
}
@APIType({"item","ae"})
@Callback(doc = "function(filter:table, dbAddress:string[, startSlot:number[, count:number]]): Boolean -- Store items in the network matching the specified filter in the database with the specified address.")
public Object[] storeAE(final Context context, final Arguments args) {
public Object[] storeAE(final Context context, final Arguments args) {markDirty();
return NetworkControl$class.store(this, context, args);
}
@APIType({"fluid","ae"})
Expand Down Expand Up @@ -1085,7 +1133,7 @@ public IMEMonitor<IAEItemStack> getItemInventory() {
}
@APIType({"item","ae"})
@Callback(doc = "function([number:amount]):number -- Transfer selected items to your ae system.")
public Object[] sendItems(final Context context, final Arguments args) {
public Object[] sendItems(final Context context, final Arguments args) {markDirty();

final IInventory invRobot = TileIOHub.this;
if (invRobot.getSizeInventory() <= 0) {
Expand Down Expand Up @@ -1125,7 +1173,7 @@ public Object[] sendItems(final Context context, final Arguments args) {
}
@APIType({"item","ae"})
@Callback(doc = "function(database:address, entry:number[, number:amount]):number -- Get items from your ae system.")
public Object[] requestItems(final Context context, final Arguments args) {
public Object[] requestItems(final Context context, final Arguments args) {markDirty();
final String address = args.checkString(0);
final int entry = args.checkInteger(1);
final int amount = args.optInteger(2, 64);
Expand Down Expand Up @@ -1199,7 +1247,7 @@ public IMEMonitor<IAEFluidStack> getFluidInventory() {
return (IMEMonitor<IAEFluidStack>)storage.getFluidInventory();
}@APIType({"fluid","ae"})
@Callback(doc = "function([number:amount]):number -- Transfer selected fluid to your ae system.")
public Object[] sendFluids(final Context context, final Arguments args) {
public Object[] sendFluids(final Context context, final Arguments args) {markDirty();
final int selected =selectedTank();
final MultiTank tanks = tank();
if (tanks.tankCount() <= 0) {
Expand Down Expand Up @@ -1231,7 +1279,7 @@ public Object[] sendFluids(final Context context, final Arguments args) {

@APIType({"fluid","ae"})
@Callback(doc = "function(database:address, entry:number[, number:amount]):number -- Get fluid from your ae system.")
public Object[] requestFluids(final Context context, final Arguments args) {
public Object[] requestFluids(final Context context, final Arguments args) {markDirty();
final String address = args.checkString(0);
final int entry = args.checkInteger(1);
final int amount = args.optInteger(2, 1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static gregtech.api.metatileentity.BaseTileEntity.TOOLTIP_DELAY;
import static reobf.proghatches.main.Config.defaultObj;

import java.io.IOException;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Method;
Expand All @@ -26,6 +27,7 @@
import net.minecraft.nbt.JsonToNBT;
import net.minecraft.nbt.NBTException;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.PacketBuffer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.ResourceLocation;
Expand Down Expand Up @@ -56,6 +58,7 @@
import com.gtnewhorizons.modularui.common.widget.Scrollable;
import com.gtnewhorizons.modularui.common.widget.SlotGroup;
import com.gtnewhorizons.modularui.common.widget.SlotWidget;
import com.gtnewhorizons.modularui.common.widget.SyncedWidget;
import com.gtnewhorizons.modularui.common.widget.TextWidget;

import cpw.mods.fml.relauncher.Side;
Expand Down Expand Up @@ -631,9 +634,11 @@ public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
super.onPostTick(aBaseMetaTileEntity, aTick);
if (aBaseMetaTileEntity.getWorld().isRemote) return;


if(dirty){updateSlots();markDirty();}
dirty=dirty||(!highEfficiencyMode());

if(dirty){updateSlots();}
dirty=dirty||getBaseMetaTileEntity().hasInventoryBeenModified();
//System.out.println(dirty);
//dirty=dirty||(!highEfficiencyMode());
boolean on=(this.getBaseMetaTileEntity().isAllowedToWork());
for (DualInvBuffer inv0 : this.sortByEmpty()) {
if(on&&dirty){
Expand Down Expand Up @@ -678,6 +683,7 @@ public ArrayList<DualInvBuffer> sortByEmpty() {
}

public void classify() {
if(isRemote())return;
for (DualInvBuffer inv0 : this.sortByEmpty()) {
if (inv0.full() == false) inv0.classify(this.mStoredFluid, mInventory);
}
Expand Down Expand Up @@ -987,6 +993,11 @@ public List<String> getExtraTooltip() {
() -> inv0.toTag()
.toString(),
s -> inv0.fromTag(cv(s))));





return builder.build();
}

Expand Down Expand Up @@ -1041,7 +1052,12 @@ public void addUIWidgets(Builder builder, UIBuildContext buildContext) {
}

builder.widget(createPowerSwitchButton(builder));

builder.widget(new SyncedWidget(){
//player operation is more complicated, always set to true when GUI open
public void detectAndSendChanges(boolean init) {BufferedDualInputHatch.this.dirty=true;};
@Override public void readOnClient(int id, PacketBuffer buf) throws IOException {}
@Override public void readOnServer(int id, PacketBuffer buf) throws IOException {}});

super.addUIWidgets(builder, buildContext);
// builder.widget(widget);

Expand Down Expand Up @@ -1290,7 +1306,11 @@ public void getWailaBody(ItemStack itemStack, List<String> currenttip, IWailaDat

}


private Boolean isRemote;
public boolean isRemote(){
if(isRemote==null)isRemote=this.getBaseMetaTileEntity().getWorld().isRemote;
return isRemote;
}
@Override
public void updateSlots() {
inv0.forEach(DualInvBuffer::updateSlots);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) {
super.onFirstTick(aBaseMetaTileEntity);
}

boolean program;
boolean program=true;//default: ON

@Override
public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCraf

}
}

dirty=true;
classify();

justHadNewItems = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,15 @@ public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {

return new ProgrammingCircuitProvider(mName, mTier, 1, mDescriptionArray, mTextures);
}
@Override
public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, ForgeDirection side, ForgeDirection aFacing,
int colorIndex, boolean aActive, boolean redstoneLevel) {

return super.getTexture(aBaseMetaTileEntity, side, aFacing, colorIndex, aActive, redstoneLevel);



}
@Override
public ITexture[] getTexturesActive(ITexture aBaseTexture) {
return GT_Mod.gregtechproxy.mRenderIndicatorsOnHatch
Expand Down
Loading

0 comments on commit b5521b6

Please sign in to comment.