mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-03-04 06:44:40 +01:00
Requested data
- Make AutoRequestData immutable, convert into a record and copy to make changes around the code to account for this
This commit is contained in:
parent
638eb2c6a5
commit
2078a78f84
9 changed files with 69 additions and 86 deletions
|
@ -27,7 +27,7 @@ registrate_version = MC1.21-1.3.0+61
|
|||
flywheel_minecraft_version = 1.21.1
|
||||
flywheel_version = 1.0.0-beta-1
|
||||
flywheel_version_range = [1.0.0-alpha,2.0)
|
||||
ponder_version = 1.0.26
|
||||
ponder_version = 1.0.30
|
||||
jei_minecraft_version = 1.21.1
|
||||
jei_version = 19.21.0.247
|
||||
curios_minecraft_version = 1.21.1
|
||||
|
|
|
@ -286,11 +286,6 @@ public class AllDataComponents {
|
|||
builder -> builder.persistent(Codec.BOOL).networkSynchronized(ByteBufCodecs.BOOL)
|
||||
);
|
||||
|
||||
public static final DataComponentType<BlockPos> DISPLAY_LINK_SELECTED_POS = register(
|
||||
"display_link_selected_pos",
|
||||
builder -> builder.persistent(BlockPos.CODEC).networkSynchronized(BlockPos.STREAM_CODEC)
|
||||
);
|
||||
|
||||
public static final DataComponentType<BottleType> POTION_FLUID_BOTTLE_TYPE = register(
|
||||
"potion_fluid_bottle_type",
|
||||
builder -> builder.persistent(BottleType.CODEC).networkSynchronized(BottleType.STREAM_CODEC)
|
||||
|
|
|
@ -25,11 +25,11 @@ import com.simibubi.create.content.logistics.tableCloth.TableClothBlockEntity;
|
|||
import com.simibubi.create.content.trains.track.TrackPlacement.PlacementInfo;
|
||||
import com.simibubi.create.foundation.gui.AllGuiTextures;
|
||||
|
||||
import net.createmod.catnip.gui.element.GuiGameElement;
|
||||
import net.createmod.catnip.animation.AnimationTickHolder;
|
||||
import net.createmod.catnip.data.Couple;
|
||||
import net.createmod.catnip.data.Iterate;
|
||||
import net.createmod.catnip.data.Pair;
|
||||
import net.createmod.catnip.gui.element.GuiGameElement;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.DeltaTracker;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
@ -39,7 +39,6 @@ import net.minecraft.client.gui.screens.inventory.tooltip.TooltipRenderUtil;
|
|||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.CraftingContainer;
|
||||
import net.minecraft.world.item.Item;
|
||||
|
@ -54,6 +53,7 @@ import net.minecraft.world.level.GameType;
|
|||
import net.minecraft.world.phys.EntityHitResult;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraft.world.phys.HitResult.Type;
|
||||
|
||||
import net.neoforged.neoforge.items.ItemHandlerHelper;
|
||||
import net.neoforged.neoforge.items.ItemStackHandler;
|
||||
|
||||
|
@ -154,7 +154,7 @@ public class BlueprintOverlayRenderer {
|
|||
.copyWithCount(dce.getPaymentAmount()),
|
||||
!dce.getPaymentItem()
|
||||
.isEmpty() && shopContext.stockLevel() > shopContext.purchases()));
|
||||
for (BigItemStack entry : dce.requestData.encodedRequest.stacks())
|
||||
for (BigItemStack entry : dce.requestData.encodedRequest().stacks())
|
||||
results.add(entry.stack.copyWithCount(entry.count));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,37 +1,16 @@
|
|||
package com.simibubi.create.content.logistics.packager;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.apache.commons.lang3.mutable.MutableBoolean;
|
||||
import org.apache.commons.lang3.mutable.MutableInt;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import com.simibubi.create.content.logistics.stockTicker.PackageOrder;
|
||||
|
||||
import net.createmod.catnip.codecs.CatnipCodecs;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public record PackagingRequest(ItemStack item, MutableInt count, String address, int linkIndex,
|
||||
MutableBoolean finalLink, MutableInt packageCounter, int orderId, @Nullable PackageOrder context) {
|
||||
public PackagingRequest(ItemStack item, MutableInt count, String address, int linkIndex,
|
||||
MutableBoolean finalLink, MutableInt packageCounter, int orderId, Optional<PackageOrder> context) {
|
||||
this(item, count, address, linkIndex, finalLink, packageCounter, orderId, context.orElse(null));
|
||||
}
|
||||
|
||||
public static final Codec<PackagingRequest> CODEC = RecordCodecBuilder.create(instance -> instance.group(
|
||||
ItemStack.CODEC.fieldOf("item").forGetter(PackagingRequest::item),
|
||||
CatnipCodecs.MUTABLE_INT_CODEC.fieldOf("count").forGetter(PackagingRequest::count),
|
||||
Codec.STRING.fieldOf("address").forGetter(PackagingRequest::address),
|
||||
Codec.INT.fieldOf("link_index").forGetter(PackagingRequest::linkIndex),
|
||||
CatnipCodecs.MUTABLE_BOOLEAN_CODEC.fieldOf("final_link").forGetter(PackagingRequest::finalLink),
|
||||
CatnipCodecs.MUTABLE_INT_CODEC.fieldOf("package_counter").forGetter(PackagingRequest::packageCounter),
|
||||
Codec.INT.fieldOf("order_id").forGetter(PackagingRequest::orderId),
|
||||
PackageOrder.CODEC.optionalFieldOf("context").forGetter(i -> Optional.ofNullable(i.context()))
|
||||
).apply(instance, PackagingRequest::new));
|
||||
|
||||
public static PackagingRequest create(ItemStack item, int count, String address, int linkIndex,
|
||||
MutableBoolean finalLink, int packageCount, int orderId, @Nullable PackageOrder context) {
|
||||
return new PackagingRequest(item, new MutableInt(count), address, linkIndex, finalLink,
|
||||
|
|
|
@ -15,7 +15,8 @@ import net.minecraft.world.entity.player.Player;
|
|||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
public class AutoRequestData {
|
||||
public record AutoRequestData(PackageOrder encodedRequest, String encodedTargetAddress, BlockPos targetOffset,
|
||||
String targetDim, boolean isValid, PackageOrder encodedRequestContext) {
|
||||
public static final Codec<AutoRequestData> CODEC = RecordCodecBuilder.create(instance -> instance.group(
|
||||
PackageOrder.CODEC.fieldOf("encoded_request").forGetter(i -> i.encodedRequest),
|
||||
Codec.STRING.fieldOf("encoded_target_address").forGetter(i -> i.encodedTargetAddress),
|
||||
|
@ -35,39 +36,34 @@ public class AutoRequestData {
|
|||
AutoRequestData::new
|
||||
);
|
||||
|
||||
public PackageOrder encodedRequest = PackageOrder.empty();
|
||||
public PackageOrder encodedRequestContext = PackageOrder.empty();
|
||||
public String encodedTargetAddress = "";
|
||||
public BlockPos targetOffset = BlockPos.ZERO;
|
||||
public String targetDim = "null";
|
||||
public boolean isValid = false;
|
||||
|
||||
public AutoRequestData() {}
|
||||
|
||||
public AutoRequestData(PackageOrder encodedRequest, String encodedTargetAdress, BlockPos targetOffset, String targetDim, boolean isValid, PackageOrder encodedRequestContext) {
|
||||
this.encodedRequest = encodedRequest;
|
||||
this.encodedRequestContext = encodedRequestContext;
|
||||
this.encodedTargetAddress = encodedTargetAdress;
|
||||
this.targetOffset = targetOffset;
|
||||
this.targetDim = targetDim;
|
||||
this.isValid = isValid;
|
||||
public AutoRequestData() {
|
||||
this(PackageOrder.empty(), "", BlockPos.ZERO, "null", false, PackageOrder.empty());
|
||||
}
|
||||
|
||||
public AutoRequestData copy() {
|
||||
AutoRequestData data = new AutoRequestData();
|
||||
data.encodedRequest = encodedRequest;
|
||||
data.encodedRequestContext = encodedRequestContext;
|
||||
data.encodedTargetAddress = encodedTargetAddress;
|
||||
data.targetOffset = targetOffset;
|
||||
data.targetDim = targetDim;
|
||||
data.isValid = isValid;
|
||||
return data;
|
||||
return new AutoRequestData(
|
||||
encodedRequest,
|
||||
encodedTargetAddress,
|
||||
targetOffset,
|
||||
targetDim,
|
||||
isValid,
|
||||
encodedRequestContext
|
||||
);
|
||||
}
|
||||
|
||||
public AutoRequestData copyWithOffset(BlockPos position) {
|
||||
return new AutoRequestData(
|
||||
encodedRequest,
|
||||
encodedTargetAddress,
|
||||
position.offset(targetOffset),
|
||||
targetDim,
|
||||
isValid,
|
||||
encodedRequestContext
|
||||
);
|
||||
}
|
||||
|
||||
public void writeToItem(BlockPos position, ItemStack itemStack) {
|
||||
AutoRequestData copy = copy();
|
||||
copy.targetOffset = position.offset(targetOffset);
|
||||
itemStack.set(AllDataComponents.AUTO_REQUEST_DATA, copy);
|
||||
itemStack.set(AllDataComponents.AUTO_REQUEST_DATA, copyWithOffset(position));
|
||||
}
|
||||
|
||||
public static AutoRequestData readFromItem(Level level, Player player, BlockPos position, ItemStack itemStack) {
|
||||
|
@ -75,12 +71,21 @@ public class AutoRequestData {
|
|||
if (requestData == null)
|
||||
return null;
|
||||
|
||||
requestData.targetOffset = requestData.targetOffset.subtract(position);
|
||||
requestData.isValid =
|
||||
BlockPos targetOffset = requestData.targetOffset.subtract(position);
|
||||
boolean isValid =
|
||||
requestData.targetOffset.closerThan(BlockPos.ZERO, 128) && requestData.targetDim.equals(level.dimension()
|
||||
.location()
|
||||
.toString());
|
||||
|
||||
requestData = new AutoRequestData(
|
||||
requestData.encodedRequest,
|
||||
requestData.encodedTargetAddress,
|
||||
targetOffset,
|
||||
requestData.targetDim,
|
||||
isValid,
|
||||
requestData.encodedRequestContext
|
||||
);
|
||||
|
||||
if (player != null)
|
||||
CreateLang
|
||||
.translate(requestData.isValid ? "redstone_requester.keeper_connected"
|
||||
|
|
|
@ -98,15 +98,11 @@ public class RedstoneRequesterBlock extends Block implements IBE<RedstoneRequest
|
|||
if (!isRequester && !isShopCloth)
|
||||
return;
|
||||
|
||||
AutoRequestData autoRequestData = new AutoRequestData();
|
||||
autoRequestData.encodedRequest = order;
|
||||
autoRequestData.encodedRequestContext = orderContext;
|
||||
autoRequestData.encodedTargetAddress = address;
|
||||
autoRequestData.targetOffset = be.getBlockPos();
|
||||
autoRequestData.targetDim = player.level()
|
||||
String targetDim = player.level()
|
||||
.dimension()
|
||||
.location()
|
||||
.toString();
|
||||
AutoRequestData autoRequestData = new AutoRequestData(order, address, be.getBlockPos(), targetDim, false, orderContext);
|
||||
|
||||
autoRequestData.writeToItem(BlockPos.ZERO, stack);
|
||||
|
||||
|
@ -127,7 +123,7 @@ public class RedstoneRequesterBlock extends Block implements IBE<RedstoneRequest
|
|||
AutoRequestData data = pStack.get(AllDataComponents.AUTO_REQUEST_DATA);
|
||||
|
||||
//noinspection DataFlowIssue
|
||||
for (BigItemStack entry : data.encodedRequest.stacks()) {
|
||||
for (BigItemStack entry : data.encodedRequest().stacks()) {
|
||||
pTooltip.add(entry.stack.getHoverName()
|
||||
.copy()
|
||||
.append(" x")
|
||||
|
@ -148,9 +144,9 @@ public class RedstoneRequesterBlock extends Block implements IBE<RedstoneRequest
|
|||
AutoRequestData data = AutoRequestData.readFromItem(pLevel, player, requesterPos, pStack);
|
||||
if (data == null)
|
||||
return;
|
||||
rrbe.encodedRequest = data.encodedRequest;
|
||||
rrbe.encodedRequestContext = data.encodedRequestContext;
|
||||
rrbe.encodedTargetAdress = data.encodedTargetAddress;
|
||||
rrbe.encodedRequest = data.encodedRequest();
|
||||
rrbe.encodedRequestContext = data.encodedRequestContext();
|
||||
rrbe.encodedTargetAdress = data.encodedTargetAddress();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ public class ShoppingListItem extends Item {
|
|||
if (!(level.getBlockEntity(entry.getValue()) instanceof TableClothBlockEntity dcbe))
|
||||
continue;
|
||||
input.add(dcbe.getPaymentItem(), dcbe.getPaymentAmount() * entry.getFirst());
|
||||
for (BigItemStack stackEntry : dcbe.requestData.encodedRequest.stacks())
|
||||
for (BigItemStack stackEntry : dcbe.requestData.encodedRequest().stacks())
|
||||
output.add(stackEntry.stack, stackEntry.count * entry.getFirst());
|
||||
}
|
||||
|
||||
|
|
|
@ -21,9 +21,9 @@ import com.simibubi.create.foundation.blockEntity.behaviour.filtering.FilteringB
|
|||
import com.simibubi.create.foundation.utility.CreateLang;
|
||||
|
||||
import net.createmod.catnip.codecs.CatnipCodecUtils;
|
||||
import net.createmod.catnip.platform.CatnipServices;
|
||||
import net.createmod.catnip.data.IntAttached;
|
||||
import net.createmod.catnip.nbt.NBTHelper;
|
||||
import net.createmod.catnip.platform.CatnipServices;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
|
@ -75,7 +75,7 @@ public class TableClothBlockEntity extends SmartBlockEntity {
|
|||
public List<ItemStack> getItemsForRender() {
|
||||
if (isShop()) {
|
||||
if (renderedItemsForShop == null)
|
||||
renderedItemsForShop = requestData.encodedRequest.stacks()
|
||||
renderedItemsForShop = requestData.encodedRequest().stacks()
|
||||
.stream()
|
||||
.map(b -> b.stack)
|
||||
.limit(4)
|
||||
|
@ -102,7 +102,7 @@ public class TableClothBlockEntity extends SmartBlockEntity {
|
|||
}
|
||||
|
||||
public boolean isShop() {
|
||||
return !requestData.encodedRequest.isEmpty();
|
||||
return !requestData.encodedRequest().isEmpty();
|
||||
}
|
||||
|
||||
public ItemInteractionResult use(Player player, BlockHitResult ray) {
|
||||
|
@ -185,7 +185,7 @@ public class TableClothBlockEntity extends SmartBlockEntity {
|
|||
}
|
||||
|
||||
UUID tickerID = null;
|
||||
BlockPos tickerPos = requestData.targetOffset.offset(worldPosition);
|
||||
BlockPos tickerPos = requestData.targetOffset().offset(worldPosition);
|
||||
if (level.getBlockEntity(tickerPos) instanceof StockTickerBlockEntity stbe && stbe.isKeeperPresent())
|
||||
tickerID = stbe.behaviour.freqId;
|
||||
|
||||
|
@ -247,7 +247,7 @@ public class TableClothBlockEntity extends SmartBlockEntity {
|
|||
}
|
||||
|
||||
ItemStack newListItem =
|
||||
ShoppingListItem.saveList(AllItems.SHOPPING_LIST.asStack(), list, requestData.encodedTargetAddress);
|
||||
ShoppingListItem.saveList(AllItems.SHOPPING_LIST.asStack(), list, requestData.encodedTargetAddress());
|
||||
|
||||
if (player.getItemInHand(InteractionHand.MAIN_HAND)
|
||||
.isEmpty())
|
||||
|
@ -260,7 +260,7 @@ public class TableClothBlockEntity extends SmartBlockEntity {
|
|||
}
|
||||
|
||||
public int getStockLevelForTrade(@Nullable ShoppingList otherPurchases) {
|
||||
BlockPos tickerPos = requestData.targetOffset.offset(worldPosition);
|
||||
BlockPos tickerPos = requestData.targetOffset().offset(worldPosition);
|
||||
if (!(level.getBlockEntity(tickerPos) instanceof StockTickerBlockEntity stbe))
|
||||
return 0;
|
||||
|
||||
|
@ -282,7 +282,7 @@ public class TableClothBlockEntity extends SmartBlockEntity {
|
|||
.getFirst();
|
||||
|
||||
int smallestQuotient = Integer.MAX_VALUE;
|
||||
for (BigItemStack entry : requestData.encodedRequest.stacks())
|
||||
for (BigItemStack entry : requestData.encodedRequest().stacks())
|
||||
if (entry.count > 0)
|
||||
smallestQuotient = Math.min(smallestQuotient,
|
||||
(recentSummary.getCountOf(entry.stack) - modifierSummary.getCountOf(entry.stack)) / entry.count);
|
||||
|
|
|
@ -107,10 +107,14 @@ public class TableClothScenes {
|
|||
scene.world()
|
||||
.modifyBlockEntity(util.grid()
|
||||
.at(3, 2, 3), TableClothBlockEntity.class, be -> {
|
||||
AutoRequestData d = new AutoRequestData();
|
||||
d.encodedRequest = new PackageOrder(List.of(new BigItemStack(grass)));
|
||||
d.isValid = true;
|
||||
be.requestData = d;
|
||||
be.requestData = new AutoRequestData(
|
||||
new PackageOrder(List.of(new BigItemStack(grass))),
|
||||
"",
|
||||
BlockPos.ZERO,
|
||||
"null",
|
||||
true,
|
||||
PackageOrder.empty()
|
||||
);
|
||||
be.priceTag.setFilter(new ItemStack(Items.DIAMOND));
|
||||
be.priceTag.count = 1;
|
||||
be.facing = Direction.NORTH;
|
||||
|
@ -245,10 +249,14 @@ public class TableClothScenes {
|
|||
scene.world()
|
||||
.modifyBlockEntity(util.grid()
|
||||
.at(5, 2, 1), TableClothBlockEntity.class, be -> {
|
||||
AutoRequestData d = new AutoRequestData();
|
||||
d.encodedRequest = new PackageOrder(List.of(new BigItemStack(logItem1)));
|
||||
d.isValid = true;
|
||||
be.requestData = d;
|
||||
be.requestData = new AutoRequestData(
|
||||
new PackageOrder(List.of(new BigItemStack(logItem1))),
|
||||
"",
|
||||
BlockPos.ZERO,
|
||||
"null",
|
||||
true,
|
||||
PackageOrder.empty()
|
||||
);
|
||||
be.facing = Direction.NORTH;
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue