diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/RefinedStorageApiImpl.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/RefinedStorageApiImpl.java index 1daca02e8..a7487641a 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/RefinedStorageApiImpl.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/RefinedStorageApiImpl.java @@ -614,7 +614,7 @@ public void openCraftingPreview(final List requests) { minecraft.setScreen(new AutocraftingPreviewScreen( minecraft.screen, inventory, - requests.stream().map(AutocraftingRequest::of).toList() + requests.stream().map(AutocraftingRequest::of).collect(Collectors.toList()) )); } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingPreviewContainerMenu.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingPreviewContainerMenu.java index a6d3da8ba..81054f343 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingPreviewContainerMenu.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingPreviewContainerMenu.java @@ -7,7 +7,6 @@ import com.refinedmods.refinedstorage.common.support.containermenu.ResourceSlotType; import com.refinedmods.refinedstorage.common.support.resource.ResourceContainerImpl; -import java.util.Collections; import java.util.List; import java.util.UUID; import javax.annotation.Nullable; @@ -33,7 +32,7 @@ public class AutocraftingPreviewContainerMenu extends AbstractResourceContainerM 48, ResourceSlotType.FILTER )); - this.requests = Collections.unmodifiableList(requests); + this.requests = requests; this.currentRequest = requests.getFirst(); } @@ -62,16 +61,35 @@ void amountChanged(final double amount) { } } - public void previewReceived(final UUID id, final AutocraftingPreview preview) { + public void previewResponseReceived(final UUID id, final AutocraftingPreview preview) { if (currentRequest.previewReceived(id, preview) && listener != null) { listener.previewChanged(preview); } } - public void loadCurrentRequest() { + void loadCurrentRequest() { if (listener != null) { currentRequest.clearPreview(); listener.requestChanged(currentRequest); } } + + void startRequest(final double amount) { + currentRequest.start(amount); + } + + boolean requestStarted(final UUID id) { + if (currentRequest.isStarted(id)) { + if (listener != null) { + listener.requestRemoved(currentRequest); + } + requests.remove(currentRequest); + if (!requests.isEmpty()) { + setCurrentRequest(requests.getFirst()); + return false; + } + return true; + } + return false; + } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingPreviewListener.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingPreviewListener.java index 984f2c520..eb6a0e3dd 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingPreviewListener.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingPreviewListener.java @@ -6,4 +6,6 @@ interface AutocraftingPreviewListener { void requestChanged(AutocraftingRequest request); void previewChanged(@Nullable AutocraftingPreview preview); + + void requestRemoved(AutocraftingRequest request); } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingPreviewProvider.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingPreviewProvider.java index 1d42cb723..558056cb7 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingPreviewProvider.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingPreviewProvider.java @@ -2,7 +2,8 @@ import com.refinedmods.refinedstorage.common.api.support.resource.PlatformResourceKey; -@FunctionalInterface public interface AutocraftingPreviewProvider { AutocraftingPreview getPreview(PlatformResourceKey resource, long amount); + + boolean start(PlatformResourceKey resource, long amount); } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingPreviewScreen.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingPreviewScreen.java index 03951eeed..4d19d30f0 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingPreviewScreen.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingPreviewScreen.java @@ -10,6 +10,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.UUID; import javax.annotation.Nullable; import com.google.common.util.concurrent.RateLimiter; @@ -63,7 +64,7 @@ public class AutocraftingPreviewScreen extends AbstractAmountScreen requestButtons = new ArrayList<>(); private final boolean requestsButtonsVisible; - private final RateLimiter requestRateLimiter = RateLimiter.create(0.5); + private final RateLimiter requestRateLimiter = RateLimiter.create(1); @Nullable private Double changedAmount; @@ -111,10 +112,7 @@ protected void init() { initRequestButtons(); } if (confirmButton != null) { - confirmButton.active = false; - confirmButton.setMessage(START); - confirmButton.setTooltip(null); - confirmButton.setError(false); + setStartDisabled(); } getMenu().loadCurrentRequest(); getExclusionZones().add(new Rect2i( @@ -144,12 +142,7 @@ private void initRequestButtons() { requestButton.visible = isCraftingRequestButtonVisible(y); } }); - final int totalRequestButtons = getMenu().getRequests().size() - REQUESTS_VISIBLE; - final int maxOffset = requestButtonsScrollbar.isSmoothScrolling() - ? totalRequestButtons * REQUEST_BUTTON_HEIGHT - : totalRequestButtons; - requestButtonsScrollbar.setEnabled(maxOffset > 0); - requestButtonsScrollbar.setMaxOffset(maxOffset); + updateRequestsScrollbar(); for (int i = 0; i < getMenu().getRequests().size(); ++i) { final AutocraftingRequest request = getMenu().getRequests().get(i); final int buttonY = getCraftingRequestButtonY(i); @@ -189,19 +182,17 @@ private void setPreview(@Nullable final AutocraftingPreview preview) { if (previewItemsScrollbar == null || confirmButton == null) { return; } - confirmButton.setMessage(START); if (preview == null) { previewItemsScrollbar.setEnabled(false); previewItemsScrollbar.setMaxOffset(0); - confirmButton.active = false; - confirmButton.setError(false); - confirmButton.setTooltip(null); + setStartDisabled(); return; } final int items = preview.items().size(); final int rows = Math.ceilDiv(items, COLUMNS) - ROWS_VISIBLE; previewItemsScrollbar.setMaxOffset(previewItemsScrollbar.isSmoothScrolling() ? rows * ROW_HEIGHT : rows); previewItemsScrollbar.setEnabled(rows > 0); + confirmButton.setMessage(START); confirmButton.active = preview.type() == AutocraftingPreviewType.SUCCESS; confirmButton.setError(preview.type() != AutocraftingPreviewType.SUCCESS); confirmButton.setTooltip(preview.type() == AutocraftingPreviewType.MISSING_RESOURCES @@ -406,16 +397,27 @@ protected void onAmountFieldChanged() { if (amountField == null || confirmButton == null) { return; } - confirmButton.active = false; - confirmButton.setError(false); - confirmButton.setTooltip(null); - confirmButton.setMessage(PENDING); + setPending(); getAndValidateAmount().ifPresentOrElse(amount -> { changedAmount = amount; amountField.setTextColor(0xFFFFFF); }, () -> amountField.setTextColor(0xFF5555)); } + private void setPending() { + confirmButton.active = false; + confirmButton.setError(false); + confirmButton.setTooltip(null); + confirmButton.setMessage(PENDING); + } + + private void setStartDisabled() { + confirmButton.active = false; + confirmButton.setError(false); + confirmButton.setTooltip(null); + confirmButton.setMessage(START); + } + @Override protected void containerTick() { super.containerTick(); @@ -432,6 +434,8 @@ protected void reset() { @Override protected boolean confirm(final Double amount) { + setPending(); + getMenu().startRequest(amount); return false; } @@ -444,4 +448,34 @@ public void requestChanged(final AutocraftingRequest request) { public void previewChanged(@Nullable final AutocraftingPreview preview) { setPreview(preview); } + + @Override + public void requestRemoved(final AutocraftingRequest request) { + requestButtons.removeIf(requestButton -> requestButton.getRequest() == request); + updateRequestsScrollbar(); + for (int i = 0; i < requestButtons.size(); ++i) { + final AutocraftingRequestButton requestButton = requestButtons.get(i); + final int buttonY = getCraftingRequestButtonY(i); + requestButton.setY(buttonY); + requestButton.visible = isCraftingRequestButtonVisible(buttonY); + } + } + + private void updateRequestsScrollbar() { + if (requestButtonsScrollbar == null) { + return; + } + final int totalRequestButtons = getMenu().getRequests().size() - REQUESTS_VISIBLE; + final int maxOffset = requestButtonsScrollbar.isSmoothScrolling() + ? totalRequestButtons * REQUEST_BUTTON_HEIGHT + : totalRequestButtons; + requestButtonsScrollbar.setEnabled(maxOffset > 0); + requestButtonsScrollbar.setMaxOffset(maxOffset); + } + + public void responseReceived(final UUID id, final boolean started) { + if (started && getMenu().requestStarted(id)) { + tryCloseToParent(); + } + } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingRequest.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingRequest.java index f3593d4ff..714845084 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingRequest.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/preview/AutocraftingRequest.java @@ -43,6 +43,14 @@ boolean trySendRequest(final double amountRequested) { return true; } + void start(final double amountRequested) { + if (!(resource instanceof PlatformResourceKey resourceKey)) { + return; + } + final long normalizedAmount = resourceKey.getResourceType().normalizeAmount(amountRequested); + C2SPackets.sendAutocraftingRequest(id, resourceKey, normalizedAmount); + } + ResourceKey getResource() { return resource; } @@ -69,4 +77,8 @@ void clearPreview() { pendingPreviewAmount = 0; preview = null; } + + boolean isStarted(final UUID startedId) { + return id.equals(startedId); + } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/AbstractGridContainerMenu.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/AbstractGridContainerMenu.java index f5ec39801..fcfe79c88 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/AbstractGridContainerMenu.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/AbstractGridContainerMenu.java @@ -507,6 +507,11 @@ public AutocraftingPreview getPreview(final PlatformResourceKey resource, final : AutocraftingPreviewType.SUCCESS, items); } + @Override + public boolean start(final PlatformResourceKey resource, final long amount) { + return true; + } + public boolean isLargeSlot(final Slot slot) { return false; } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/AbstractGridScreen.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/AbstractGridScreen.java index b124ae275..9747967b0 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/AbstractGridScreen.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/AbstractGridScreen.java @@ -524,7 +524,7 @@ private static boolean tryStartAutocrafting(final PlatformGridResource resource) requests.add(new ResourceAmount(request.resource(), request.amount() * 2)); requests.add(new ResourceAmount(request.resource(), request.amount() * 3)); requests.add(new ResourceAmount(request.resource(), request.amount() * 4)); - requests.add(new ResourceAmount(request.resource(), request.amount() * 5)); + requests.add(new ResourceAmount(request.resource(), request.amount() * 4)); } RefinedStorageApi.INSTANCE.openCraftingPreview(requests); return true; diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/amount/AbstractAmountScreen.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/amount/AbstractAmountScreen.java index f9cf67691..e585d2fcf 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/amount/AbstractAmountScreen.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/amount/AbstractAmountScreen.java @@ -286,7 +286,7 @@ private void tryConfirmAndCloseToParent() { }); } - private boolean tryCloseToParent() { + protected final boolean tryCloseToParent() { if (parent != null) { Minecraft.getInstance().setScreen(parent); return true; diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/c2s/AutocraftingRequestPacket.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/c2s/AutocraftingRequestPacket.java new file mode 100644 index 000000000..2b2ea00a0 --- /dev/null +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/c2s/AutocraftingRequestPacket.java @@ -0,0 +1,46 @@ +package com.refinedmods.refinedstorage.common.support.packet.c2s; + +import com.refinedmods.refinedstorage.common.api.support.resource.PlatformResourceKey; +import com.refinedmods.refinedstorage.common.autocrafting.preview.AutocraftingPreviewProvider; +import com.refinedmods.refinedstorage.common.support.packet.PacketContext; +import com.refinedmods.refinedstorage.common.support.packet.s2c.S2CPackets; +import com.refinedmods.refinedstorage.common.support.resource.ResourceCodecs; + +import java.util.UUID; + +import net.minecraft.core.UUIDUtil; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.server.level.ServerPlayer; + +import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createIdentifier; + +public record AutocraftingRequestPacket(UUID id, + PlatformResourceKey resource, + long amount) implements CustomPacketPayload { + public static final Type PACKET_TYPE = new Type<>( + createIdentifier("autocrafting_request") + ); + public static final StreamCodec STREAM_CODEC = + StreamCodec + .composite( + UUIDUtil.STREAM_CODEC, AutocraftingRequestPacket::id, + ResourceCodecs.STREAM_CODEC, AutocraftingRequestPacket::resource, + ByteBufCodecs.VAR_LONG, AutocraftingRequestPacket::amount, + AutocraftingRequestPacket::new + ); + + public static void handle(final AutocraftingRequestPacket packet, final PacketContext ctx) { + if (ctx.getPlayer().containerMenu instanceof AutocraftingPreviewProvider provider) { + final boolean started = provider.start(packet.resource(), packet.amount()); + S2CPackets.sendAutocraftingResponse((ServerPlayer) ctx.getPlayer(), packet.id, started); + } + } + + @Override + public Type type() { + return PACKET_TYPE; + } +} diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/c2s/C2SPackets.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/c2s/C2SPackets.java index 4aba50bee..bc20c2224 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/c2s/C2SPackets.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/c2s/C2SPackets.java @@ -137,4 +137,10 @@ public static void sendAutocraftingPreviewRequest(final UUID id, final long amount) { Platform.INSTANCE.sendPacketToServer(new AutocraftingPreviewRequestPacket(id, resource, amount)); } + + public static void sendAutocraftingRequest(final UUID id, + final PlatformResourceKey resource, + final long amount) { + Platform.INSTANCE.sendPacketToServer(new AutocraftingRequestPacket(id, resource, amount)); + } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/s2c/AutocraftingPreviewResponsePacket.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/s2c/AutocraftingPreviewResponsePacket.java index e09b02d5b..bd9c8a1f1 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/s2c/AutocraftingPreviewResponsePacket.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/s2c/AutocraftingPreviewResponsePacket.java @@ -1,7 +1,6 @@ package com.refinedmods.refinedstorage.common.support.packet.s2c; import com.refinedmods.refinedstorage.common.autocrafting.preview.AutocraftingPreview; -import com.refinedmods.refinedstorage.common.support.packet.PacketContext; import com.refinedmods.refinedstorage.common.util.ClientPlatformUtil; import java.util.UUID; @@ -26,7 +25,7 @@ public record AutocraftingPreviewResponsePacket(UUID id, AutocraftingPreview pre ); public static void handle(final AutocraftingPreviewResponsePacket packet) { - ClientPlatformUtil.craftingPreviewReceived(packet.id, packet.preview); + ClientPlatformUtil.autocraftingPreviewResponseReceived(packet.id, packet.preview); } @Override diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/s2c/AutocraftingResponsePacket.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/s2c/AutocraftingResponsePacket.java new file mode 100644 index 000000000..1b1467d63 --- /dev/null +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/s2c/AutocraftingResponsePacket.java @@ -0,0 +1,36 @@ +package com.refinedmods.refinedstorage.common.support.packet.s2c; + +import com.refinedmods.refinedstorage.common.util.ClientPlatformUtil; + +import java.util.UUID; + +import net.minecraft.core.UUIDUtil; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; + +import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createIdentifier; + +public record AutocraftingResponsePacket(UUID id, boolean started) implements CustomPacketPayload { + public static final Type PACKET_TYPE = new Type<>( + createIdentifier("autocrafting_response") + ); + + public static final StreamCodec STREAM_CODEC = + StreamCodec.composite( + UUIDUtil.STREAM_CODEC, AutocraftingResponsePacket::id, + ByteBufCodecs.BOOL, AutocraftingResponsePacket::started, + AutocraftingResponsePacket::new + ); + + public static void handle(final AutocraftingResponsePacket packet) { + ClientPlatformUtil.autocraftingResponseReceived(packet.id, packet.started); + } + + @Override + public Type type() { + return PACKET_TYPE; + } +} + diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/s2c/S2CPackets.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/s2c/S2CPackets.java index ab1ef3796..623a0bd79 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/s2c/S2CPackets.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/s2c/S2CPackets.java @@ -92,4 +92,10 @@ public static void sendAutocraftingPreviewResponse(final ServerPlayer player, final AutocraftingPreview preview) { Platform.INSTANCE.sendPacketToClient(player, new AutocraftingPreviewResponsePacket(id, preview)); } + + public static void sendAutocraftingResponse(final ServerPlayer player, + final UUID id, + final boolean started) { + Platform.INSTANCE.sendPacketToClient(player, new AutocraftingResponsePacket(id, started)); + } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/util/ClientPlatformUtil.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/util/ClientPlatformUtil.java index 07ce08854..065af4437 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/util/ClientPlatformUtil.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/util/ClientPlatformUtil.java @@ -35,9 +35,15 @@ public static void addNoPermissionToast(final Component message) { ); } - public static void craftingPreviewReceived(final UUID id, final AutocraftingPreview preview) { + public static void autocraftingPreviewResponseReceived(final UUID id, final AutocraftingPreview preview) { if (Minecraft.getInstance().screen instanceof AutocraftingPreviewScreen screen) { - screen.getMenu().previewReceived(id, preview); + screen.getMenu().previewResponseReceived(id, preview); + } + } + + public static void autocraftingResponseReceived(final UUID id, final boolean started) { + if (Minecraft.getInstance().screen instanceof AutocraftingPreviewScreen screen) { + screen.responseReceived(id, started); } } } diff --git a/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/ClientModInitializerImpl.java b/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/ClientModInitializerImpl.java index dd7ffd7ec..37e89fd79 100644 --- a/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/ClientModInitializerImpl.java +++ b/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/ClientModInitializerImpl.java @@ -20,6 +20,7 @@ import com.refinedmods.refinedstorage.common.support.network.item.NetworkItemPropertyFunction; import com.refinedmods.refinedstorage.common.support.packet.PacketHandler; import com.refinedmods.refinedstorage.common.support.packet.s2c.AutocraftingPreviewResponsePacket; +import com.refinedmods.refinedstorage.common.support.packet.s2c.AutocraftingResponsePacket; import com.refinedmods.refinedstorage.common.support.packet.s2c.CrafterNameUpdatePacket; import com.refinedmods.refinedstorage.common.support.packet.s2c.EnergyInfoPacket; import com.refinedmods.refinedstorage.common.support.packet.s2c.GridActivePacket; @@ -295,6 +296,10 @@ private void registerPacketHandlers() { AutocraftingPreviewResponsePacket.PACKET_TYPE, wrapHandler((packet, ctx) -> AutocraftingPreviewResponsePacket.handle(packet)) ); + ClientPlayNetworking.registerGlobalReceiver( + AutocraftingResponsePacket.PACKET_TYPE, + wrapHandler((packet, ctx) -> AutocraftingResponsePacket.handle(packet)) + ); } private static ClientPlayNetworking.PlayPayloadHandler wrapHandler( diff --git a/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/ModInitializerImpl.java b/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/ModInitializerImpl.java index 16747b7a0..dc3f23626 100644 --- a/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/ModInitializerImpl.java +++ b/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/ModInitializerImpl.java @@ -30,6 +30,7 @@ import com.refinedmods.refinedstorage.common.support.AbstractBaseBlock; import com.refinedmods.refinedstorage.common.support.packet.PacketHandler; import com.refinedmods.refinedstorage.common.support.packet.c2s.AutocraftingPreviewRequestPacket; +import com.refinedmods.refinedstorage.common.support.packet.c2s.AutocraftingRequestPacket; import com.refinedmods.refinedstorage.common.support.packet.c2s.CrafterNameChangePacket; import com.refinedmods.refinedstorage.common.support.packet.c2s.CraftingGridClearPacket; import com.refinedmods.refinedstorage.common.support.packet.c2s.CraftingGridRecipeTransferPacket; @@ -55,6 +56,7 @@ import com.refinedmods.refinedstorage.common.support.packet.c2s.StorageInfoRequestPacket; import com.refinedmods.refinedstorage.common.support.packet.c2s.UseSlotReferencedItemPacket; import com.refinedmods.refinedstorage.common.support.packet.s2c.AutocraftingPreviewResponsePacket; +import com.refinedmods.refinedstorage.common.support.packet.s2c.AutocraftingResponsePacket; import com.refinedmods.refinedstorage.common.support.packet.s2c.CrafterNameUpdatePacket; import com.refinedmods.refinedstorage.common.support.packet.s2c.EnergyInfoPacket; import com.refinedmods.refinedstorage.common.support.packet.s2c.GridActivePacket; @@ -449,6 +451,10 @@ private void registerServerToClientPackets() { AutocraftingPreviewResponsePacket.PACKET_TYPE, AutocraftingPreviewResponsePacket.STREAM_CODEC ); + PayloadTypeRegistry.playS2C().register( + AutocraftingResponsePacket.PACKET_TYPE, + AutocraftingResponsePacket.STREAM_CODEC + ); } private void registerClientToServerPackets() { @@ -540,6 +546,10 @@ private void registerClientToServerPackets() { AutocraftingPreviewRequestPacket.PACKET_TYPE, AutocraftingPreviewRequestPacket.STREAM_CODEC ); + PayloadTypeRegistry.playC2S().register( + AutocraftingRequestPacket.PACKET_TYPE, + AutocraftingRequestPacket.STREAM_CODEC + ); } private void registerPacketHandlers() { @@ -643,6 +653,10 @@ private void registerPacketHandlers() { AutocraftingPreviewRequestPacket.PACKET_TYPE, wrapHandler(AutocraftingPreviewRequestPacket::handle) ); + ServerPlayNetworking.registerGlobalReceiver( + AutocraftingRequestPacket.PACKET_TYPE, + wrapHandler(AutocraftingRequestPacket::handle) + ); } private static ServerPlayNetworking.PlayPayloadHandler wrapHandler( diff --git a/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/ModInitializer.java b/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/ModInitializer.java index 79c413015..a8b9ebd5a 100644 --- a/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/ModInitializer.java +++ b/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/ModInitializer.java @@ -30,6 +30,7 @@ import com.refinedmods.refinedstorage.common.support.AbstractBaseBlock; import com.refinedmods.refinedstorage.common.support.packet.PacketHandler; import com.refinedmods.refinedstorage.common.support.packet.c2s.AutocraftingPreviewRequestPacket; +import com.refinedmods.refinedstorage.common.support.packet.c2s.AutocraftingRequestPacket; import com.refinedmods.refinedstorage.common.support.packet.c2s.CrafterNameChangePacket; import com.refinedmods.refinedstorage.common.support.packet.c2s.CraftingGridClearPacket; import com.refinedmods.refinedstorage.common.support.packet.c2s.CraftingGridRecipeTransferPacket; @@ -55,6 +56,7 @@ import com.refinedmods.refinedstorage.common.support.packet.c2s.StorageInfoRequestPacket; import com.refinedmods.refinedstorage.common.support.packet.c2s.UseSlotReferencedItemPacket; import com.refinedmods.refinedstorage.common.support.packet.s2c.AutocraftingPreviewResponsePacket; +import com.refinedmods.refinedstorage.common.support.packet.s2c.AutocraftingResponsePacket; import com.refinedmods.refinedstorage.common.support.packet.s2c.CrafterNameUpdatePacket; import com.refinedmods.refinedstorage.common.support.packet.s2c.EnergyInfoPacket; import com.refinedmods.refinedstorage.common.support.packet.s2c.GridActivePacket; @@ -638,6 +640,11 @@ private static void registerServerToClientPackets(final PayloadRegistrar registr AutocraftingPreviewResponsePacket.STREAM_CODEC, wrapHandler((packet, ctx) -> AutocraftingPreviewResponsePacket.handle(packet)) ); + registrar.playToClient( + AutocraftingResponsePacket.PACKET_TYPE, + AutocraftingResponsePacket.STREAM_CODEC, + wrapHandler((packet, ctx) -> AutocraftingResponsePacket.handle(packet)) + ); } private static void registerClientToServerPackets(final PayloadRegistrar registrar) { @@ -766,6 +773,11 @@ private static void registerClientToServerPackets(final PayloadRegistrar registr AutocraftingPreviewRequestPacket.STREAM_CODEC, wrapHandler(AutocraftingPreviewRequestPacket::handle) ); + registrar.playToServer( + AutocraftingRequestPacket.PACKET_TYPE, + AutocraftingRequestPacket.STREAM_CODEC, + wrapHandler(AutocraftingRequestPacket::handle) + ); } private static IPayloadHandler wrapHandler(final PacketHandler handler) {