Skip to content

Commit

Permalink
0.5.1g porting part V
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Aug 10, 2024
1 parent 7bb541a commit 6c3d0e0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/simibubi/create/AllBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ public class AllBlocks {

public static final BlockEntry<WaterWheelStructuralBlock> WATER_WHEEL_STRUCTURAL =
REGISTRATE.block("water_wheel_structure", WaterWheelStructuralBlock::new)
.initialProperties(SharedProperties::wooden)
//.initialProperties(SharedProperties::wooden) fabric: make structual blocks non flammable
.blockstate((c, p) -> p.getVariantBuilder(c.get())
.forAllStatesExcept(BlockStateGen.mapToAir(p), WaterWheelStructuralBlock.FACING))
.properties(p -> p.noOcclusion().color(MaterialColor.DIRT))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,9 @@ public BlockPos getInformationSource(Level level, BlockPos pos, BlockState state
return stillValid(level, pos, state, false) ? getMaster(level, pos, state) : pos;
}

@Override
public boolean isFlammable(BlockState state, BlockGetter level, BlockPos pos, Direction direction) {
return false;
}
// fabric: handled in AllBlocks by not giving it the wood material
// @Override
// public boolean isFlammable(BlockState state, BlockGetter level, BlockPos pos, Direction direction) {
// return false;
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -455,20 +455,20 @@ private void tryClearingSpoutputOverflow() {
if (targetInv == null)
break;

ItemStack remainder = ItemHandlerHelper.insertItemStacked(targetInv, itemStack, true);
if (remainder.getCount() == itemStack.getCount())
long inserted = TransferUtil.insertItem(targetInv, itemStack);
if (inserted == 0)
continue;
if (filter != null && !filter.test(itemStack))
continue;

visualizedOutputItems.add(LongAttached.withZero(itemStack));
update = true;

remainder = ItemHandlerHelper.insertItemStacked(targetInv, itemStack.copy(), false);
if (remainder.isEmpty())
inserted = TransferUtil.insertItem(targetInv, itemStack.copy());
if (inserted == itemStack.getCount())
iterator.remove();
else
itemStack.setCount(remainder.getCount());
itemStack.setCount((int) inserted);
}

for (Iterator<FluidStack> iterator = spoutputFluidBuffer.iterator(); iterator.hasNext();) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import com.simibubi.create.foundation.item.SmartInventory;

import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant;
import net.fabricmc.fabric.api.transfer.v1.storage.StoragePreconditions;
import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction;
import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.items.ItemHandlerHelper;

public class BasinInventory extends SmartInventory {

Expand All @@ -18,44 +18,34 @@ public BasinInventory(int slots, BasinBlockEntity be) {

@Override
public long insert(ItemVariant resource, long maxAmount, TransactionContext transaction) {
StoragePreconditions.notBlankNotNegative(resource, maxAmount);
if (!insertionAllowed)
return 0;
// Only insert if no other slot already has a stack of this item
for (int i = 0; i < getSlots(); i++)
if (i != slot && ItemHandlerHelper.canItemStacksStack(stack, inv.getStackInSlot(i)))
return stack;
try (Transaction test = transaction.openNested()) {
long contained = this.extract(resource, Long.MAX_VALUE, test);
if (contained != 0) {
// already have this item. can we stack?
long maxStackSize = Math.min(stackSize, resource.getItem().getMaxStackSize());
long space = Math.max(0, maxStackSize - contained);
if (space <= 0) {
// nope.
return 0;
} else {
// yes!
maxAmount = Math.min(space, maxAmount);
}
}
}
return super.insert(resource, maxAmount, transaction);
}

@Override
public ItemStack extractItem(int slot, int amount, boolean simulate) {
ItemStack extractItem = super.extractItem(slot, amount, simulate);
if (!simulate && !extractItem.isEmpty())
public long extract(ItemVariant resource, long maxAmount, TransactionContext transaction) {
long extractedAmount = super.extract(resource, maxAmount, transaction);
if (extractedAmount != 0)
blockEntity.notifyChangeOfContents();
return extractItem;
return extractedAmount;
}

// old code:
// @Override
// public long insert(ItemVariant resource, long maxAmount, TransactionContext transaction) {
// StoragePreconditions.notBlankNotNegative(resource, maxAmount);
// if (!insertionAllowed)
// return 0;
// // Only insert if no other slot already has a stack of this item
// try (Transaction test = transaction.openNested()) {
// long contained = this.extract(resource, Long.MAX_VALUE, test);
// if (contained != 0) {
// // already have this item. can we stack?
// long maxStackSize = Math.min(stackSize, resource.getItem().getMaxStackSize());
// long space = Math.max(0, maxStackSize - contained);
// if (space <= 0) {
// // nope.
// return 0;
// } else {
// // yes!
// maxAmount = Math.min(space, maxAmount);
// }
// }
// }
// return super.insert(resource, maxAmount, transaction);
// }

}

0 comments on commit 6c3d0e0

Please sign in to comment.