Skip to content

Fixed compilation errors and problems with Packages and Packagers #1785

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

Open
wants to merge 3 commits into
base: mc1.20.1/fabric/dev
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ local.properties
.settings/
.loadpath

## VSCode/VSCodium
.vscode/*

# External tool builders
.externalToolBuilders/

Expand All @@ -57,3 +60,4 @@ local.properties
Ponder
Ponder/
.Ponder/
.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.network.chat.Component;
import net.minecraft.tags.FluidTags;
import net.minecraft.util.StringUtil;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.GameType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,19 +216,18 @@ public void entityInside(BlockState state, Level worldIn, BlockPos pos, Entity e
if (BeltTunnelInteractionHandler.getTunnelOnPosition(worldIn, pos) != null)
return;
withBlockEntityDo(worldIn, pos, be -> {
ItemEntity itemEntity = (ItemEntity) entityIn;
Storage<ItemVariant> handler = be.getItemStorage(null);
if (handler == null)
return;
ItemStack inEntity = itemEntity.getItem();
try (Transaction t = TransferUtil.getTransaction()) {
long inserted = handler.insert(ItemVariant.of(inEntity), inEntity.getCount(), t);
long inserted = handler.insert(ItemVariant.of(asItem), asItem.getCount(), t);
asItem.shrink((int) inserted);
if (inserted == 0)
return;
if (inEntity.getCount() == inserted) {
itemEntity.discard();
} else {
inEntity.shrink((int) inserted);
if (asItem.getCount() == inserted) {
entityIn.discard();
} else if (entityIn instanceof ItemEntity itemEntity && asItem.getCount() != itemEntity.getItem().getCount()) {
itemEntity.setItem(asItem);
}
t.commit();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public EntityDimensions getDimensions(Pose pPose) {

@Override
public void recreateFromPacket(ClientboundAddEntityPacket packet) {
this.setDeltaMovement(packet.getXa(), packet.getYa(), packet.getZa());
super.recreateFromPacket(packet);
this.clientPosition = this.position();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,26 +358,22 @@ public boolean unwrapBox(ItemStack box, TransactionContext ctx) {
BlockPos target = worldPosition.relative(facing.getOpposite());
BlockState targetState = level.getBlockState(target);

UnpackingHandler handler = UnpackingHandler.REGISTRY.get(targetState);
UnpackingHandler handler = UnpackingHandler.REGISTRY.get(targetState);
UnpackingHandler toUse = handler != null ? handler : UnpackingHandler.DEFAULT;

// fabric: copy the items to actually unpack later
List<ItemStack> copy = items.stream().map(ItemStack::copy).toList();

// note: handler may modify the passed items
boolean unpacked = toUse.unpack(level, target, targetState, facing, items, orderContext, true);
boolean unpacked = toUse.unpack(level, target, targetState, facing, items, orderContext, false);

if (unpacked) {
TransactionCallback.onSuccess(ctx, () -> {
toUse.unpack(level, target, targetState, facing, copy, orderContext, false);
previouslyUnwrapped = box;
animationInward = true;
animationTicks = CYCLE;
notifyUpdate();
});
previouslyUnwrapped = box;
animationInward = true;
animationTicks = CYCLE;
}

return true;
return unpacked;
}

public void attemptToSend(List<PackagingRequest> queuedRequests) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
import net.fabricmc.fabric.api.transfer.v1.storage.StoragePreconditions;
import net.fabricmc.fabric.api.transfer.v1.storage.base.SingleSlotStorage;
import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext;

import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext.Result;
import net.fabricmc.fabric.api.transfer.v1.transaction.base.SnapshotParticipant;
import io.github.fabricators_of_create.porting_lib.transfer.callbacks.TransactionCallback;

public class PackagerItemHandler implements SingleSlotStorage<ItemVariant> {
public class PackagerItemHandler extends SnapshotParticipant<ItemStack> implements SingleSlotStorage<ItemVariant> {

private final PackagerBlockEntity blockEntity;

private boolean unpackSuccessful = false;

public PackagerItemHandler(PackagerBlockEntity blockEntity) {
this.blockEntity = blockEntity;
}
Expand All @@ -27,8 +30,9 @@ public long insert(ItemVariant resource, long maxAmount, TransactionContext tran
if (!PackageItem.isPackage(resource))
return 0;
ItemStack stack = resource.toStack(1);
this.updateSnapshots(transaction);
if (blockEntity.unwrapBox(stack, transaction)) {
TransactionCallback.onSuccess(transaction, blockEntity::scheduleStockCheck);
this.unpackSuccessful = true;
return 1;
} else {
return 0;
Expand All @@ -43,9 +47,8 @@ public long extract(ItemVariant resource, long maxAmount, TransactionContext tra
ItemStack box = blockEntity.heldBox;
if (!resource.matches(box))
return 0;

this.updateSnapshots(transaction);
blockEntity.heldBox = ItemStack.EMPTY;
TransactionCallback.onSuccess(transaction, blockEntity::notifyUpdate);
return box.getCount();
}

Expand All @@ -68,4 +71,23 @@ public long getAmount() {
public long getCapacity() {
return 1;
}

@Override
protected ItemStack createSnapshot() {
return blockEntity.heldBox.copy();
}

@Override
protected void readSnapshot(ItemStack snapshot) {
blockEntity.heldBox = snapshot;
}

@Override
protected void onFinalCommit() {
if (this.unpackSuccessful) {
blockEntity.scheduleStockCheck();
this.unpackSuccessful = false;
}
blockEntity.notifyUpdate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ protected void initCapability() {
}
}

Storage<ItemVariant> combinedInvWrapper = new CombinedStorage<>(SameSizeCombinedInvWrapper.create(invs));
Storage<ItemVariant> combinedInvWrapper = SameSizeCombinedInvWrapper.create(List.of(invs));
combinedInvWrapper = new VersionedInventoryWrapper(combinedInvWrapper);
itemCapability = combinedInvWrapper;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant;
import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction;

import io.github.fabricators_of_create.porting_lib.transfer.TransferUtil;
import io.github.fabricators_of_create.porting_lib.transfer.item.ItemHandlerHelper;

public enum CrafterUnpackingHandler implements UnpackingHandler {
Expand All @@ -43,7 +43,7 @@ public boolean unpack(Level level, BlockPos pos, BlockState state, Direction sid
if (inventories.isEmpty())
return false;

try (Transaction t = Transaction.openOuter()) {
try (Transaction t = TransferUtil.getTransaction()) {
// insert in the order's defined ordering
int max = Math.min(inventories.size(), craftingContext.size());
outer: for (int i = 0; i < max; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.simibubi.create.api.packager.unpacking.UnpackingHandler;
import com.simibubi.create.content.logistics.stockTicker.PackageOrderWithCrafts;

import io.github.fabricators_of_create.porting_lib.transfer.TransferUtil;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.item.ItemStack;
Expand All @@ -30,7 +31,7 @@ public boolean unpack(Level level, BlockPos pos, BlockState state, Direction sid
if (targetInv == null)
return false;

try (Transaction t = Transaction.openOuter()) {
try (Transaction t = TransferUtil.getTransaction()) {
for (ItemStack stack : items) {
long inserted = targetInv.insert(ItemVariant.of(stack), stack.getCount(), t);
if (inserted != stack.getCount()) {
Expand Down