Skip to content

Commit 07dbce2

Browse files
committed
It's like, actually functional now, yay
1 parent a8af292 commit 07dbce2

File tree

10 files changed

+64
-32
lines changed

10 files changed

+64
-32
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ local.properties
3636
.settings/
3737
.loadpath
3838

39+
## VSCode/VSCodium
40+
.vscode/*
41+
3942
# External tool builders
4043
.externalToolBuilders/
4144

@@ -57,3 +60,4 @@ local.properties
5760
Ponder
5861
Ponder/
5962
.Ponder/
63+
.vscode/launch.json

src/main/java/com/simibubi/create/content/equipment/armor/DivingHelmetItem.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
import net.minecraft.resources.ResourceLocation;
1212
import net.minecraft.server.level.ServerPlayer;
13+
import net.minecraft.world.effect.MobEffectInstance;
14+
import net.minecraft.world.effect.MobEffects;
1315
import net.minecraft.world.entity.Entity;
1416
import net.minecraft.world.entity.EquipmentSlot;
1517
import net.minecraft.world.entity.LivingEntity;
@@ -119,7 +121,10 @@ public static void breatheUnderwater(LivingEntity entity) {
119121
if (entity instanceof ServerPlayer sp)
120122
AllAdvancements.DIVING_SUIT.awardTo(sp);
121123

122-
event.setCanBreathe(true);
123-
event.setCanRefillAir(true);
124+
// TODO: Find a way to make this work in Fabric if possible
125+
// event.setCanBreathe(true);
126+
// event.setCanRefillAir(true);
127+
entity.setAirSupply(Math.min(entity.getMaxAirSupply(), entity.getAirSupply() + 10));
128+
entity.addEffect(new MobEffectInstance(MobEffects.WATER_BREATHING, 30, 0, true, false, true));
124129
}
125130
}

src/main/java/com/simibubi/create/content/equipment/armor/RemainingAirOverlay.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import net.minecraft.client.gui.GuiGraphics;
1212
import net.minecraft.client.player.LocalPlayer;
1313
import net.minecraft.network.chat.Component;
14+
import net.minecraft.tags.FluidTags;
1415
import net.minecraft.util.StringUtil;
1516
import net.minecraft.world.item.ItemStack;
1617
import net.minecraft.world.level.GameType;
@@ -29,7 +30,8 @@ public static void render(GuiGraphics graphics, int width, int height) {
2930
if (!player.getCustomData()
3031
.contains("VisualBacktankAir"))
3132
return;
32-
if (!player.canDrownInFluidType(player.getEyeInFluidType()) && !player.isInLava())
33+
// TODO: Find a way to make this work in Fabric if possible
34+
if (/*!player.canDrownInFluidType(player.getEyeInFluidType())*/ !player.isEyeInFluid(FluidTags.WATER) && !player.isInLava())
3335
return;
3436

3537
int timeLeft = player.getCustomData()

src/main/java/com/simibubi/create/content/kinetics/belt/BeltBlock.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,19 +216,19 @@ public void entityInside(BlockState state, Level worldIn, BlockPos pos, Entity e
216216
if (BeltTunnelInteractionHandler.getTunnelOnPosition(worldIn, pos) != null)
217217
return;
218218
withBlockEntityDo(worldIn, pos, be -> {
219-
ItemEntity itemEntity = (ItemEntity) entityIn;
219+
// ItemEntity itemEntity = (ItemEntity) entityIn;
220220
Storage<ItemVariant> handler = be.getItemStorage(null);
221221
if (handler == null)
222222
return;
223-
ItemStack inEntity = itemEntity.getItem();
224223
try (Transaction t = TransferUtil.getTransaction()) {
225-
long inserted = handler.insert(ItemVariant.of(inEntity), inEntity.getCount(), t);
224+
long inserted = handler.insert(ItemVariant.of(asItem), asItem.getCount(), t);
225+
asItem.shrink((int) inserted);
226226
if (inserted == 0)
227227
return;
228-
if (inEntity.getCount() == inserted) {
229-
itemEntity.discard();
230-
} else {
231-
inEntity.shrink((int) inserted);
228+
if (asItem.getCount() == inserted) {
229+
entityIn.discard();
230+
} else if (entityIn instanceof ItemEntity itemEntity && asItem.getCount() != itemEntity.getItem().getCount()) {
231+
itemEntity.setItem(asItem);
232232
}
233233
t.commit();
234234
}

src/main/java/com/simibubi/create/content/logistics/box/PackageEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public EntityDimensions getDimensions(Pose pPose) {
207207

208208
@Override
209209
public void recreateFromPacket(ClientboundAddEntityPacket packet) {
210-
this.setDeltaMovement(packet.getXa(), packet.getYa(), packet.getZa());
210+
super.recreateFromPacket(packet);
211211
this.clientPosition = this.position();
212212
}
213213

src/main/java/com/simibubi/create/content/logistics/packager/PackagerBlockEntity.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -358,26 +358,22 @@ public boolean unwrapBox(ItemStack box, TransactionContext ctx) {
358358
BlockPos target = worldPosition.relative(facing.getOpposite());
359359
BlockState targetState = level.getBlockState(target);
360360

361-
UnpackingHandler handler = UnpackingHandler.REGISTRY.get(targetState);
361+
UnpackingHandler handler = UnpackingHandler.REGISTRY.get(targetState);
362362
UnpackingHandler toUse = handler != null ? handler : UnpackingHandler.DEFAULT;
363363

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

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

370370
if (unpacked) {
371-
TransactionCallback.onSuccess(ctx, () -> {
372-
toUse.unpack(level, target, targetState, facing, copy, orderContext, false);
373-
previouslyUnwrapped = box;
374-
animationInward = true;
375-
animationTicks = CYCLE;
376-
notifyUpdate();
377-
});
371+
previouslyUnwrapped = box;
372+
animationInward = true;
373+
animationTicks = CYCLE;
378374
}
379375

380-
return true;
376+
return unpacked;
381377
}
382378

383379
public void attemptToSend(List<PackagingRequest> queuedRequests) {

src/main/java/com/simibubi/create/content/logistics/packager/PackagerItemHandler.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
import net.fabricmc.fabric.api.transfer.v1.storage.StoragePreconditions;
99
import net.fabricmc.fabric.api.transfer.v1.storage.base.SingleSlotStorage;
1010
import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext;
11-
11+
import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext.Result;
12+
import net.fabricmc.fabric.api.transfer.v1.transaction.base.SnapshotParticipant;
1213
import io.github.fabricators_of_create.porting_lib.transfer.callbacks.TransactionCallback;
1314

14-
public class PackagerItemHandler implements SingleSlotStorage<ItemVariant> {
15+
public class PackagerItemHandler extends SnapshotParticipant<ItemStack> implements SingleSlotStorage<ItemVariant> {
1516

1617
private final PackagerBlockEntity blockEntity;
1718

19+
private boolean unpackSuccessful = false;
20+
1821
public PackagerItemHandler(PackagerBlockEntity blockEntity) {
1922
this.blockEntity = blockEntity;
2023
}
@@ -27,8 +30,9 @@ public long insert(ItemVariant resource, long maxAmount, TransactionContext tran
2730
if (!PackageItem.isPackage(resource))
2831
return 0;
2932
ItemStack stack = resource.toStack(1);
33+
this.updateSnapshots(transaction);
3034
if (blockEntity.unwrapBox(stack, transaction)) {
31-
TransactionCallback.onSuccess(transaction, blockEntity::scheduleStockCheck);
35+
this.unpackSuccessful = true;
3236
return 1;
3337
} else {
3438
return 0;
@@ -43,9 +47,8 @@ public long extract(ItemVariant resource, long maxAmount, TransactionContext tra
4347
ItemStack box = blockEntity.heldBox;
4448
if (!resource.matches(box))
4549
return 0;
46-
50+
this.updateSnapshots(transaction);
4751
blockEntity.heldBox = ItemStack.EMPTY;
48-
TransactionCallback.onSuccess(transaction, blockEntity::notifyUpdate);
4952
return box.getCount();
5053
}
5154

@@ -68,4 +71,23 @@ public long getAmount() {
6871
public long getCapacity() {
6972
return 1;
7073
}
74+
75+
@Override
76+
protected ItemStack createSnapshot() {
77+
return blockEntity.heldBox.copy();
78+
}
79+
80+
@Override
81+
protected void readSnapshot(ItemStack snapshot) {
82+
blockEntity.heldBox = snapshot;
83+
}
84+
85+
@Override
86+
protected void onFinalCommit() {
87+
if (this.unpackSuccessful) {
88+
blockEntity.scheduleStockCheck();
89+
this.unpackSuccessful = false;
90+
}
91+
blockEntity.notifyUpdate();
92+
}
7193
}

src/main/java/com/simibubi/create/content/logistics/vault/ItemVaultBlockEntity.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,13 @@ private static void updateComaratorsInner(Level level, Block provokingBlock, Blo
162162
}
163163

164164
BlockState blockstate = level.getBlockState(updatePos);
165-
blockstate.onNeighborChange(level, updatePos, provokingPos);
165+
// TODO: Find a way to make this work in Fabric if possible
166+
// blockstate.onNeighborChange(level, updatePos, provokingPos);
166167
if (blockstate.isRedstoneConductor(level, updatePos)) {
167168
updatePos.move(direction);
168169
blockstate = level.getBlockState(updatePos);
169-
if (blockstate.getWeakChanges(level, updatePos)) {
170+
// TODO: Find a way to make this work in Fabric if possible
171+
if (/*blockstate.getWeakChanges(level, updatePos)*/ blockstate.is(Blocks.COMPARATOR)) {
170172
level.neighborChanged(blockstate, updatePos, provokingBlock, provokingPos, false);
171173
}
172174
}
@@ -359,7 +361,7 @@ protected void initCapability() {
359361
}
360362
}
361363

362-
Storage<ItemVariant> combinedInvWrapper = new CombinedStorage<>(SameSizeCombinedInvWrapper.create(invs));
364+
Storage<ItemVariant> combinedInvWrapper = SameSizeCombinedInvWrapper.create(List.of(invs));
363365
combinedInvWrapper = new VersionedInventoryWrapper(combinedInvWrapper);
364366
itemCapability = combinedInvWrapper;
365367

src/main/java/com/simibubi/create/impl/unpacking/CrafterUnpackingHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant;
2222
import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction;
23-
23+
import io.github.fabricators_of_create.porting_lib.transfer.TransferUtil;
2424
import io.github.fabricators_of_create.porting_lib.transfer.item.ItemHandlerHelper;
2525

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

46-
try (Transaction t = Transaction.openOuter()) {
46+
try (Transaction t = TransferUtil.getTransaction()) {
4747
// insert in the order's defined ordering
4848
int max = Math.min(inventories.size(), craftingContext.size());
4949
outer: for (int i = 0; i < max; i++) {

src/main/java/com/simibubi/create/impl/unpacking/DefaultUnpackingHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.simibubi.create.api.packager.unpacking.UnpackingHandler;
88
import com.simibubi.create.content.logistics.stockTicker.PackageOrderWithCrafts;
99

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

33-
try (Transaction t = Transaction.openOuter()) {
34+
try (Transaction t = TransferUtil.getTransaction()) {
3435
for (ItemStack stack : items) {
3536
long inserted = targetInv.insert(ItemVariant.of(stack), stack.getCount(), t);
3637
if (inserted != stack.getCount()) {

0 commit comments

Comments
 (0)