Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug-Fixes related to machines. #131

Open
wants to merge 3 commits into
base: 1.21
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ public CompoundTag serializeNBT(HolderLookup.Provider provider) {
CompoundTag value = new CompoundTag();
value.putString("Name", action.getName());
value.putBoolean("LastState", lastRedstoneState);
value.putBoolean("ShouldWork", shouldWork);
return value;
}

@Override
public void deserializeNBT(HolderLookup.Provider provider, CompoundTag nbt) {
this.action = this.action.getValue(nbt.getString("Name"));
this.lastRedstoneState = nbt.getBoolean("LastState");
this.shouldWork = nbt.getBoolean("ShouldWork");
}

}
12 changes: 4 additions & 8 deletions src/main/java/com/hrznstudio/titanium/block/tile/ActiveTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,14 @@ public void serverTick(Level level, BlockPos pos, BlockState state, T blockEntit
if (level.getGameTime() % getFacingHandlerWorkTime() == 0) {
if (multiInventoryComponent != null) {
for (InventoryComponent<T> inventoryHandler : multiInventoryComponent.getInventoryHandlers()) {
if (inventoryHandler instanceof IFacingComponent) {
if (((IFacingComponent) inventoryHandler).work(this.level, this.worldPosition, this.getFacingDirection(), getFacingHandlerWorkAmount()))
break;
}
if (inventoryHandler instanceof IFacingComponent)
((IFacingComponent) inventoryHandler).work(this.level, this.worldPosition, this.getFacingDirection(), getFacingHandlerWorkAmount());
}
}
if (multiTankComponent != null) {
for (FluidTankComponent<T> tank : multiTankComponent.getTanks()) {
if (tank instanceof IFacingComponent) {
if (((IFacingComponent) tank).work(this.level, this.worldPosition, this.getFacingDirection(), getFacingHandlerWorkAmount()))
break;
}
if (tank instanceof IFacingComponent)
((IFacingComponent) tank).work(this.level, this.worldPosition, this.getFacingDirection(), getFacingHandlerWorkAmount());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ public int getSlots() {
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
InventoryComponent<T> handler = getFromSlot(slot);
if (handler != null) {
if (handler.getInsertPredicate().test(stack, slot)) {
return handler.insertItem(getRelativeSlot(handler, slot), stack, simulate);
int relativeSlot = getRelativeSlot(handler, slot);
if (handler.getInsertPredicate().test(stack, relativeSlot)) {
return handler.insertItem(relativeSlot, stack, simulate);
} else {
return stack;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,15 @@ private boolean transfer(FacingUtil.Sideness sideness, IItemHandler from, IItemH
ItemStack extracted = from.extractItem(slot, workAmount, true);
int outSlot = isValidForAnySlot(to, extracted);
if (!extracted.isEmpty() && outSlot != -1) {
ItemStack returned = to.insertItem(outSlot, extracted, false);
return !from.extractItem(slot, extracted.getCount() - returned.getCount(), false).isEmpty();
int returnCount = extracted.getCount();

do {
extracted.setCount(to.insertItem(outSlot, extracted.copy(), false).getCount());
outSlot = isValidForAnySlot(to, extracted);
if (outSlot == -1) break;
} while (!extracted.isEmpty());

return !from.extractItem(slot, returnCount - extracted.getCount(), false).isEmpty();
}
slotCache.put(sideness, getNextSlot(from, slot + 1));
return false;
Expand All @@ -217,8 +224,9 @@ private boolean transfer(FacingUtil.Sideness sideness, IItemHandler from, IItemH
private int isValidForAnySlot(IItemHandler dest, ItemStack stack) {
for (int i = 0; i < dest.getSlots(); i++) {
if (!dest.isItemValid(i, stack)) continue;
if (dest.getStackInSlot(i).isEmpty()) return i;
if (ItemStack.isSameItemSameComponents(dest.getStackInSlot(i), stack) && dest.getStackInSlot(i).getCount() < dest.getSlotLimit(i)) {
ItemStack slotStack = dest.getStackInSlot(i);
if (slotStack.isEmpty()) return i;
if (ItemStack.isSameItemSameComponents(slotStack, stack) && slotStack.getCount() < Math.min(slotStack.getMaxStackSize(), dest.getSlotLimit(i))) {
return i;
}
}
Expand Down