Skip to content

Commit 865c2b4

Browse files
committed
first pass
1 parent 5b5be70 commit 865c2b4

File tree

18 files changed

+76
-83
lines changed

18 files changed

+76
-83
lines changed

src/main/java/com/simibubi/create/api/behaviour/display/DisplayTarget.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static void reserve(int line, BlockEntity target, DisplayLinkContext cont
5656
if (line == 0)
5757
return;
5858

59-
CompoundTag tag = target.getPersistentData();
59+
CompoundTag tag = target.getCustomData();
6060
CompoundTag compound = tag.getCompound("DisplayLink");
6161
compound.putLong("Line" + line, context.blockEntity()
6262
.getBlockPos()
@@ -65,7 +65,7 @@ public static void reserve(int line, BlockEntity target, DisplayLinkContext cont
6565
}
6666

6767
public boolean isReserved(int line, BlockEntity target, DisplayLinkContext context) {
68-
CompoundTag tag = target.getPersistentData();
68+
CompoundTag tag = target.getCustomData();
6969
CompoundTag compound = tag.getCompound("DisplayLink");
7070

7171
if (!compound.contains("Line" + line))

src/main/java/com/simibubi/create/api/behaviour/movement/MovementBehaviour.java

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

2121
import net.fabricmc.api.EnvType;
2222
import net.fabricmc.api.Environment;
23+
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant;
24+
import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction;
25+
26+
import io.github.fabricators_of_create.porting_lib.transfer.TransferUtil;
2327

2428
/**
2529
* MovementBehaviors, also known as Actors, provide behavior to blocks mounted on contraptions.
@@ -67,8 +71,14 @@ default boolean mustTickWhileDisabled() {
6771

6872
default void dropItem(MovementContext context, ItemStack stack) {
6973
ItemStack remainder;
70-
if (AllConfigs.server().kinetics.moveItemsToStorage.get())
71-
remainder = ItemHandlerHelper.insertItem(context.contraption.getStorage().getAllItems(), stack, false);
74+
if (AllConfigs.server().kinetics.moveItemsToStorage.get()) {
75+
try (Transaction t = TransferUtil.getTransaction()) {
76+
long inserted = context.contraption.getStorage().getAllItems().insert(ItemVariant.of(stack), stack.getCount(), t);
77+
remainder = stack.copy();
78+
remainder.shrink((int) inserted);
79+
t.commit();
80+
}
81+
}
7282
else
7383
remainder = stack;
7484
if (remainder.isEmpty())

src/main/java/com/simibubi/create/api/contraption/storage/item/menu/MountedStorageMenus.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static MenuProvider createGeneric(Component menuName, SlottedStackStorage
3535
return null;
3636

3737
// make sure rows are full
38-
if (handler.getSlots() % 9 != 0)
38+
if (handler.getSlotCount() % 9 != 0)
3939
return null;
4040

4141
MenuType<?> type = GENERIC_CHEST_MENUS.get(rows - 1);

src/main/java/com/simibubi/create/content/contraptions/Contraption.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ protected BlockEntity readBlockEntity(Level level, StructureBlockInfo info, Comp
10151015
BlockEntity be = entityBlock.newBlockEntity(pos, state);
10161016
postprocessReadBlockEntity(level, be);
10171017
if (be != null && nbt != null) {
1018-
be.handleUpdateTag(nbt);
1018+
be.load(nbt);
10191019
}
10201020

10211021
return be;

src/main/java/com/simibubi/create/content/fluids/tank/CreativeFluidTankBlockEntity.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,18 @@
66
import com.mojang.serialization.Codec;
77
import com.mojang.serialization.codecs.RecordCodecBuilder;
88
import com.simibubi.create.foundation.fluid.SmartFluidTank;
9-
10-
import io.github.fabricators_of_create.porting_lib.transfer.fluid.FluidTank;
9+
import com.simibubi.create.foundation.utility.CreateCodecs;
1110

1211
import net.minecraft.core.BlockPos;
1312
import net.minecraft.network.chat.Component;
14-
import net.minecraft.util.ExtraCodecs;
1513
import net.minecraft.world.level.block.entity.BlockEntityType;
1614
import net.minecraft.world.level.block.state.BlockState;
1715

1816
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant;
1917
import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext;
2018

2119
import io.github.fabricators_of_create.porting_lib.fluids.FluidStack;
20+
import io.github.fabricators_of_create.porting_lib.transfer.fluid.FluidTank;
2221

2322
public class CreativeFluidTankBlockEntity extends FluidTankBlockEntity {
2423

@@ -39,7 +38,7 @@ public boolean addToGoggleTooltip(List<Component> tooltip, boolean isPlayerSneak
3938
public static class CreativeSmartFluidTank extends SmartFluidTank {
4039
public static final Codec<CreativeSmartFluidTank> CODEC = RecordCodecBuilder.create(i -> i.group(
4140
FluidStack.CODEC.fieldOf("fluid").forGetter(FluidTank::getFluid),
42-
ExtraCodecs.NON_NEGATIVE_INT.fieldOf("capacity").forGetter(FluidTank::getCapacity)
41+
CreateCodecs.NON_NEGATIVE_LONG.fieldOf("capacity").forGetter(FluidTank::getCapacity)
4342
).apply(i, (fluid, capacity) -> {
4443
CreativeSmartFluidTank tank = new CreativeSmartFluidTank(capacity, $ -> {});
4544
tank.setFluid(fluid);

src/main/java/com/simibubi/create/content/logistics/factoryBoard/FactoryPanelBehaviour.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,7 @@ public boolean writeToClipboard(CompoundTag tag, Direction side) {
10441044
}
10451045

10461046
private void tickOutline() {
1047-
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> LogisticallyLinkedClientHandler.tickPanel(this));
1047+
EnvExecutor.runWhenOn(EnvType.CLIENT, () -> () -> LogisticallyLinkedClientHandler.tickPanel(this));
10481048
}
10491049

10501050
@Override

src/main/java/com/simibubi/create/content/logistics/packagePort/PackagePortMenu.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public ItemStack quickMoveStack(Player player, int index) {
5252
return ItemStack.EMPTY;
5353

5454
ItemStack stack = clickedSlot.getItem();
55-
int size = contentHolder.inventory.getSlots();
55+
int size = contentHolder.inventory.getSlotCount();
5656
boolean success = false;
5757
if (index < size) {
5858
success = !moveItemStackTo(stack, size, slots.size(), false);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,13 @@ public void divideAndSendTo(ServerPlayer player, BlockPos pos) {
173173
continue;
174174

175175
AllPackets.getChannel()
176-
.send(target, new LogisticalStockResponsePacket(false, pos, currentList));
176+
.sendToClient(new LogisticalStockResponsePacket(false, pos, currentList), player);
177177
currentList = null;
178178
}
179179

180180
if (currentList != null)
181181
AllPackets.getChannel()
182-
.send(target, new LogisticalStockResponsePacket(true, pos, currentList));
182+
.sendToClient(new LogisticalStockResponsePacket(true, pos, currentList), player);
183183
}
184184

185185
public CompoundTag write() {

src/main/java/com/simibubi/create/content/trains/entity/CarriageContraptionEntity.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,14 @@
2828
import com.simibubi.create.infrastructure.config.AllConfigs;
2929

3030
import net.createmod.catnip.data.Couple;
31+
import net.createmod.catnip.data.Iterate;
3132
import net.createmod.catnip.math.VecHelper;
3233
import net.createmod.catnip.theme.Color;
33-
34-
import net.fabricmc.api.EnvType;
35-
import net.fabricmc.api.Environment;
36-
3734
import net.minecraft.core.BlockPos;
3835
import net.minecraft.core.Direction;
3936
import net.minecraft.core.Direction.Axis;
4037
import net.minecraft.core.particles.ParticleTypes;
4138
import net.minecraft.nbt.CompoundTag;
42-
import net.minecraft.network.chat.CommonComponents;
4339
import net.minecraft.network.FriendlyByteBuf;
4440
import net.minecraft.network.chat.CommonComponents;
4541
import net.minecraft.network.chat.Component;
@@ -56,7 +52,6 @@
5652
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo;
5753
import net.minecraft.world.phys.Vec3;
5854

59-
6055
import net.fabricmc.api.EnvType;
6156
import net.fabricmc.api.Environment;
6257

src/main/java/com/simibubi/create/content/trains/station/GlobalStation.java

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@
3030
import net.minecraft.world.level.block.entity.BlockEntity;
3131
import net.minecraft.world.level.block.state.BlockState;
3232

33+
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant;
34+
import net.fabricmc.fabric.api.transfer.v1.storage.Storage;
35+
import net.fabricmc.fabric.api.transfer.v1.storage.StorageView;
36+
import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction;
3337

38+
import io.github.fabricators_of_create.porting_lib.transfer.TransferUtil;
3439
import io.github.fabricators_of_create.porting_lib.transfer.item.ItemStackHandler;
3540

3641
public class GlobalStation extends SingleBlockEntityEdgePoint {
@@ -181,7 +186,7 @@ public void runMailTransfer() {
181186
.getLevel(getBlockEntityDimension());
182187
}
183188

184-
IItemHandlerModifiable carriageInventory = carriage.storage.getAllItems();
189+
Storage<ItemVariant> carriageInventory = carriage.storage.getAllItems();
185190
if (carriageInventory == null)
186191
continue;
187192

@@ -191,22 +196,22 @@ public void runMailTransfer() {
191196
BlockPos pos = entry.getKey();
192197
PostboxBlockEntity box = null;
193198

194-
IItemHandlerModifiable postboxInventory = port.offlineBuffer;
199+
ItemStackHandler postboxInventory = port.offlineBuffer;
195200
if (level != null && level.isLoaded(pos)
196201
&& level.getBlockEntity(pos) instanceof PostboxBlockEntity ppbe) {
197202
postboxInventory = ppbe.inventory;
198203
box = ppbe;
199204
}
200205

201-
for (int slot = 0; slot < postboxInventory.getSlots(); slot++) {
206+
for (int slot = 0; slot < postboxInventory.getSlotCount(); slot++) {
202207
ItemStack stack = postboxInventory.getStackInSlot(slot);
203208
if (!PackageItem.isPackage(stack))
204209
continue;
205210
if (PackageItem.matchAddress(stack, port.address))
206211
continue;
207212

208-
ItemStack result = ItemHandlerHelper.insertItemStacked(carriageInventory, stack, false);
209-
if (!result.isEmpty())
213+
long inserted = TransferUtil.insertItem(carriageInventory, stack);
214+
if (inserted == 0)
210215
continue;
211216

212217
postboxInventory.setStackInSlot(slot, ItemStack.EMPTY);
@@ -217,39 +222,41 @@ public void runMailTransfer() {
217222
}
218223

219224
// Export to station
220-
for (int slot = 0; slot < carriageInventory.getSlots(); slot++) {
221-
ItemStack stack = carriageInventory.getStackInSlot(slot);
222-
if (!PackageItem.isPackage(stack))
223-
continue;
225+
try (Transaction t = Transaction.openOuter()) {
226+
for (StorageView<ItemVariant> view : carriageInventory.nonEmptyViews()) {
227+
ItemVariant resource = view.getResource();
228+
if (!PackageItem.isPackage(resource))
229+
continue;
224230

225-
for (Entry<BlockPos, GlobalPackagePort> entry : connectedPorts.entrySet()) {
226-
GlobalPackagePort port = entry.getValue();
227-
BlockPos pos = entry.getKey();
228-
PostboxBlockEntity box = null;
231+
for (Entry<BlockPos, GlobalPackagePort> entry : connectedPorts.entrySet()) {
232+
GlobalPackagePort port = entry.getValue();
233+
BlockPos pos = entry.getKey();
234+
PostboxBlockEntity box = null;
229235

230-
if (!PackageItem.matchAddress(stack, port.address))
231-
continue;
236+
if (!PackageItem.matchAddress(resource, port.address))
237+
continue;
232238

233-
IItemHandler postboxInventory = port.offlineBuffer;
234-
if (level != null && level.isLoaded(pos)
235-
&& level.getBlockEntity(pos) instanceof PostboxBlockEntity ppbe) {
236-
postboxInventory = ppbe.inventory;
237-
box = ppbe;
238-
}
239+
ItemStackHandler postboxInventory = port.offlineBuffer;
240+
if (level != null && level.isLoaded(pos)
241+
&& level.getBlockEntity(pos) instanceof PostboxBlockEntity ppbe) {
242+
postboxInventory = ppbe.inventory;
243+
box = ppbe;
244+
}
239245

240-
ItemStack result = ItemHandlerHelper.insertItemStacked(postboxInventory, stack, false);
241-
if (!result.isEmpty())
242-
continue;
246+
long inserted = postboxInventory.insert(resource, view.getAmount(), t);
247+
if (inserted != 0)
248+
continue;
243249

244-
Create.RAILWAYS.markTracksDirty();
245-
carriageInventory.setStackInSlot(slot, ItemStack.EMPTY);
246-
if (box != null)
247-
box.spawnParticles();
250+
Create.RAILWAYS.markTracksDirty();
251+
view.extract(resource, view.getAmount(), t);
252+
if (box != null)
253+
box.spawnParticles();
248254

249-
break;
255+
break;
256+
}
250257
}
258+
t.commit();
251259
}
252-
253260
}
254261
}
255262

src/main/java/com/simibubi/create/content/trains/station/StationBlockEntity.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,6 @@
6464
import net.createmod.catnip.data.WorldAttached;
6565
import net.createmod.catnip.math.VecHelper;
6666
import net.createmod.catnip.nbt.NBTHelper;
67-
68-
import net.fabricmc.api.EnvType;
69-
import net.fabricmc.api.Environment;
70-
71-
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant;
72-
import net.fabricmc.fabric.api.transfer.v1.storage.Storage;
73-
7467
import net.minecraft.ChatFormatting;
7568
import net.minecraft.core.BlockPos;
7669
import net.minecraft.core.BlockPos.MutableBlockPos;
@@ -992,7 +985,7 @@ public void attachPackagePort(PackagePortBlockEntity ppbe) {
992985
private void restoreOfflineBuffer(PackagePortBlockEntity ppbe, GlobalPackagePort globalPackagePort) {
993986
if (!globalPackagePort.primed)
994987
return;
995-
for (int i = 0; i < globalPackagePort.offlineBuffer.getSlots(); i++) {
988+
for (int i = 0; i < globalPackagePort.offlineBuffer.getSlotCount(); i++) {
996989
ppbe.inventory.setStackInSlot(i, globalPackagePort.offlineBuffer.getStackInSlot(i));
997990
globalPackagePort.offlineBuffer.setStackInSlot(i, ItemStack.EMPTY);
998991
}

src/main/java/com/simibubi/create/foundation/data/CreateBlockEntityBuilder.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import net.minecraft.world.level.block.entity.BlockEntity;
2323
import net.minecraft.world.level.block.entity.BlockEntityType;
2424

25-
2625
import net.fabricmc.api.EnvType;
2726

2827
public class CreateBlockEntityBuilder<T extends BlockEntity, P> extends BlockEntityBuilder<T, P> {
@@ -102,7 +101,7 @@ public CreateBlockEntityBuilder<T, P> visual(
102101
protected void registerVisualizer() {
103102
var visualFactory = this.visualFactory;
104103
if (visualFactory != null) {
105-
NonNullPredicate<T> renderNormally = this.renderNormally;
104+
Predicate<T> renderNormally = this.renderNormally;
106105
SimpleBlockEntityVisualizer.builder(getEntry())
107106
.factory(visualFactory.get())
108107
.skipVanillaRender(be -> !renderNormally.test(be))

src/main/java/com/simibubi/create/foundation/data/CreateEntityBuilder.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import net.minecraft.world.entity.EntityType;
1717
import net.minecraft.world.entity.MobCategory;
1818

19-
2019
import net.fabricmc.api.EnvType;
2120

2221
@ParametersAreNonnullByDefault
@@ -56,7 +55,7 @@ public CreateEntityBuilder<T, P> visual(NonNullSupplier<SimpleEntityVisualizer.F
5655
protected void registerVisualizer() {
5756
var visualFactory = this.visualFactory;
5857
if (visualFactory != null) {
59-
NonNullPredicate<T> renderNormally = this.renderNormally;
58+
Predicate<T> renderNormally = this.renderNormally;
6059
SimpleEntityVisualizer.builder(getEntry())
6160
.factory(visualFactory.get())
6261
.skipVanillaRender(entity -> !renderNormally.test(entity))

src/main/java/com/simibubi/create/foundation/fluid/FluidIngredient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ public abstract class FluidIngredient implements Predicate<FluidStack> {
3434

3535
public List<FluidStack> matchingFluidStacks;
3636

37-
public static FluidIngredient fromTag(TagKey<Fluid> tag, int amount) {
37+
public static FluidIngredient fromTag(TagKey<Fluid> tag, long amount) {
3838
FluidTagIngredient ingredient = new FluidTagIngredient();
3939
ingredient.tag = tag;
4040
ingredient.amountRequired = amount;
4141
return ingredient;
4242
}
4343

44-
public static FluidIngredient fromFluid(Fluid fluid, int amount) {
44+
public static FluidIngredient fromFluid(Fluid fluid, long amount) {
4545
FluidStackIngredient ingredient = new FluidStackIngredient();
4646
ingredient.fluid = fluid;
4747
ingredient.amountRequired = amount;

src/main/java/com/simibubi/create/foundation/item/ItemHelper.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import net.minecraft.world.level.Level;
2626
import net.minecraft.world.level.block.entity.BlockEntity;
2727

28+
import net.fabricmc.fabric.api.transfer.v1.item.ItemStorage;
2829
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant;
2930
import net.fabricmc.fabric.api.transfer.v1.storage.Storage;
3031
import net.fabricmc.fabric.api.transfer.v1.storage.StorageView;
@@ -91,10 +92,7 @@ public static void addToList(ItemStack stack, List<ItemStack> stacks) {
9192
// }
9293

9394
public static <T extends IBE<? extends BlockEntity>> int calcRedstoneFromBlockEntity(T ibe, Level level, BlockPos pos) {
94-
return ibe.getBlockEntityOptional(level, pos)
95-
.map(be -> be.getCapability(ForgeCapabilities.ITEM_HANDLER))
96-
.map(lo -> lo.map(ItemHelper::calcRedstoneFromInventory).orElse(0))
97-
.orElse(0);
95+
return calcRedstoneFromInventory(ItemStorage.SIDED.find(level, pos, null));
9896
}
9997

10098
public static int calcRedstoneFromInventory(@Nullable Storage<ItemVariant> inv) {

src/main/java/com/simibubi/create/foundation/utility/CreateCodecs.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ private static Codec<Double> doubleRangeWithMessage(double min, double max, Func
115115
if (isMeat) builder.meat();
116116
if (canAlwaysEat) builder.alwaysEat();
117117
if (isFastFood) builder.fast();
118-
for (FoodEffect effect : effects) builder.effect(effect.effectSupplier(), effect.probability());
118+
for (FoodEffect effect : effects) builder.effect(effect.effect(), effect.probability());
119119

120120
return builder.build();
121121
}));

src/main/java/com/simibubi/create/infrastructure/config/AllConfigs.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77

88
import org.apache.commons.lang3.tuple.Pair;
99

10+
import com.simibubi.create.Create;
1011
import com.simibubi.create.api.stress.BlockStressValues;
1112

1213
import fuzs.forgeconfigapiport.api.config.v2.ForgeConfigRegistry;
13-
import fuzs.forgeconfigapiport.api.config.v2.ModConfigEvents;
1414
import net.createmod.catnip.config.ConfigBase;
15-
1615
import net.minecraftforge.common.ForgeConfigSpec;
1716
import net.minecraftforge.fml.config.ModConfig;
1817

0 commit comments

Comments
 (0)