diff --git a/gradle.properties b/gradle.properties index d77ada458..a1b566f8c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,4 +5,3 @@ org.gradle.configureondemand=true org.gradle.caching=true org.gradle.configuration-cache=true org.gradle.configuration-cache.problems=warn -org.gradle.vfs.watch=false diff --git a/refinedstorage-autocrafting-api/src/test/java/com/refinedmods/refinedstorage/api/autocrafting/ResourceFixtures.java b/refinedstorage-autocrafting-api/src/test/java/com/refinedmods/refinedstorage/api/autocrafting/ResourceFixtures.java index 6ecf50222..715577458 100644 --- a/refinedstorage-autocrafting-api/src/test/java/com/refinedmods/refinedstorage/api/autocrafting/ResourceFixtures.java +++ b/refinedstorage-autocrafting-api/src/test/java/com/refinedmods/refinedstorage/api/autocrafting/ResourceFixtures.java @@ -2,7 +2,7 @@ import com.refinedmods.refinedstorage.api.resource.ResourceKey; -enum ResourceFixtures implements ResourceKey { +public enum ResourceFixtures implements ResourceKey { A, B, C diff --git a/refinedstorage-autocrafting-api/src/test/java/com/refinedmods/refinedstorage/api/autocrafting/status/TaskStatusTest.java b/refinedstorage-autocrafting-api/src/test/java/com/refinedmods/refinedstorage/api/autocrafting/status/TaskStatusTest.java new file mode 100644 index 000000000..a19282a9e --- /dev/null +++ b/refinedstorage-autocrafting-api/src/test/java/com/refinedmods/refinedstorage/api/autocrafting/status/TaskStatusTest.java @@ -0,0 +1,35 @@ +package com.refinedmods.refinedstorage.api.autocrafting.status; + +import com.refinedmods.refinedstorage.api.autocrafting.ResourceFixtures; +import com.refinedmods.refinedstorage.api.autocrafting.TaskId; + +import java.util.List; +import java.util.UUID; + +import org.junit.jupiter.api.Test; + +public class TaskStatusTest { + @Test + void dummyTest() { + new TaskStatus( + new TaskStatus.TaskInfo( + new TaskId(UUID.randomUUID()), + ResourceFixtures.A, + 0, + 0 + ), + 0.69F, + List.of( + new TaskStatus.Item( + TaskStatus.ItemType.NORMAL, + ResourceFixtures.A, + 0, + 0, + 0, + 0, + 0 + ) + ) + ); + } +} diff --git a/refinedstorage-autocrafting-api/src/test/java/com/refinedmods/refinedstorage/api/autocrafting/status/package-info.java b/refinedstorage-autocrafting-api/src/test/java/com/refinedmods/refinedstorage/api/autocrafting/status/package-info.java new file mode 100644 index 000000000..d15a12e18 --- /dev/null +++ b/refinedstorage-autocrafting-api/src/test/java/com/refinedmods/refinedstorage/api/autocrafting/status/package-info.java @@ -0,0 +1,7 @@ +@ParametersAreNonnullByDefault +@FieldsAndMethodsAreNonnullByDefault +package com.refinedmods.refinedstorage.api.autocrafting.status; + +import com.refinedmods.refinedstorage.api.core.FieldsAndMethodsAreNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AbstractAutocraftingMonitorContainerMenu.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AbstractAutocraftingMonitorContainerMenu.java new file mode 100644 index 000000000..cf639c9d5 --- /dev/null +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AbstractAutocraftingMonitorContainerMenu.java @@ -0,0 +1,192 @@ +package com.refinedmods.refinedstorage.common.autocrafting.monitor; + +import com.refinedmods.refinedstorage.api.autocrafting.TaskId; +import com.refinedmods.refinedstorage.api.autocrafting.status.TaskStatus; +import com.refinedmods.refinedstorage.api.autocrafting.status.TaskStatusListener; +import com.refinedmods.refinedstorage.api.autocrafting.status.TaskStatusProvider; +import com.refinedmods.refinedstorage.common.support.AbstractBaseContainerMenu; +import com.refinedmods.refinedstorage.common.support.packet.c2s.C2SPackets; +import com.refinedmods.refinedstorage.common.support.packet.s2c.S2CPackets; + +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import javax.annotation.Nullable; + +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.MenuType; + +public abstract class AbstractAutocraftingMonitorContainerMenu extends AbstractBaseContainerMenu + implements TaskStatusListener, AutocraftingMonitorWatcher { + private final Map statusByTaskId; + private final List tasks; + private final List tasksView; + @Nullable + private final TaskStatusProvider taskStatusProvider; + private final Player player; + + @Nullable + private AutocraftingMonitorListener listener; + @Nullable + private TaskId currentTaskId; + private boolean active; + + protected AbstractAutocraftingMonitorContainerMenu(final MenuType menuType, + final int syncId, + final Inventory playerInventory, + final AutocraftingMonitorData data) { + super(menuType, syncId); + this.statusByTaskId = data.statuses().stream().collect(Collectors.toMap( + s -> s.info().id(), + s -> s + )); + this.tasks = data.statuses().stream().map(TaskStatus::info).collect(Collectors.toList()); + this.tasksView = Collections.unmodifiableList(tasks); + this.currentTaskId = data.statuses().isEmpty() ? null : data.statuses().getFirst().info().id(); + this.taskStatusProvider = null; + this.active = data.active(); + this.player = playerInventory.player; + } + + protected AbstractAutocraftingMonitorContainerMenu(final MenuType menuType, + final int syncId, + final Player player, + final TaskStatusProvider taskStatusProvider) { + super(menuType, syncId); + this.statusByTaskId = Collections.emptyMap(); + this.tasks = Collections.emptyList(); + this.tasksView = Collections.emptyList(); + this.currentTaskId = null; + this.taskStatusProvider = taskStatusProvider; + this.player = player; + taskStatusProvider.addListener(this); + } + + @Override + public void removed(final Player removedPlayer) { + super.removed(removedPlayer); + if (taskStatusProvider != null) { + taskStatusProvider.removeListener(this); + } + } + + @Override + public void broadcastChanges() { + super.broadcastChanges(); + if (taskStatusProvider instanceof TaskStatusProviderImpl taskStatusProviderImpl) { + taskStatusProviderImpl.testTick(); + } + } + + void setListener(@Nullable final AutocraftingMonitorListener listener) { + this.listener = listener; + } + + List getCurrentItems() { + final TaskStatus status = statusByTaskId.get(currentTaskId); + if (status == null) { + return Collections.emptyList(); + } + return status.items(); + } + + List getTasksView() { + return tasksView; + } + + float getPercentageCompleted(final TaskId taskId) { + final TaskStatus status = statusByTaskId.get(taskId); + return status == null ? 0 : status.percentageCompleted(); + } + + void setCurrentTaskId(@Nullable final TaskId taskId) { + this.currentTaskId = taskId; + loadCurrentTask(); + } + + void loadCurrentTask() { + if (listener != null) { + listener.currentTaskChanged(currentTaskId == null ? null : statusByTaskId.get(currentTaskId)); + } + } + + @Override + public void taskStatusChanged(final TaskStatus status) { + if (taskStatusProvider != null && player instanceof ServerPlayer serverPlayer) { + S2CPackets.sendAutocraftingMonitorTaskStatusChanged(serverPlayer, status); + return; + } + statusByTaskId.put(status.info().id(), status); + } + + @Override + public void taskRemoved(final TaskId id) { + if (taskStatusProvider != null && player instanceof ServerPlayer serverPlayer) { + S2CPackets.sendAutocraftingMonitorTaskRemoved(serverPlayer, id); + return; + } + statusByTaskId.remove(id); + tasks.removeIf(task -> task.id().equals(id)); + if (listener != null) { + listener.taskRemoved(id); + } + if (id.equals(currentTaskId)) { + this.currentTaskId = tasks.isEmpty() ? null : tasks.getFirst().id(); + loadCurrentTask(); + } + } + + @Override + public void taskAdded(final TaskStatus status) { + if (taskStatusProvider != null && player instanceof ServerPlayer serverPlayer) { + S2CPackets.sendAutocraftingMonitorTaskAdded(serverPlayer, status); + return; + } + statusByTaskId.put(status.info().id(), status); + tasks.add(status.info()); + if (listener != null) { + listener.taskAdded(status); + } + if (currentTaskId == null) { + this.currentTaskId = status.info().id(); + loadCurrentTask(); + } + } + + public void cancelTask(final TaskId taskId) { + if (taskStatusProvider != null) { + taskStatusProvider.cancel(taskId); + } + } + + void cancelCurrentTask() { + if (currentTaskId != null) { + C2SPackets.sendAutocraftingMonitorCancel(currentTaskId); + } + } + + public void cancelAllTasks() { + if (taskStatusProvider != null) { + taskStatusProvider.cancelAll(); + } else { + C2SPackets.sendAutocraftingMonitorCancelAll(); + } + } + + @Override + public void activeChanged(final boolean newActive) { + if (player instanceof ServerPlayer serverPlayer) { + S2CPackets.sendAutocraftingMonitorActive(serverPlayer, newActive); + } else { + this.active = newActive; + loadCurrentTask(); + } + } + + boolean isActive() { + return active; + } +} diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AutocraftingMonitorBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AutocraftingMonitorBlockEntity.java index 4a7273adb..b9759b6f6 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AutocraftingMonitorBlockEntity.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AutocraftingMonitorBlockEntity.java @@ -8,6 +8,9 @@ import com.refinedmods.refinedstorage.common.support.containermenu.NetworkNodeExtendedMenuProvider; import com.refinedmods.refinedstorage.common.support.network.AbstractBaseNetworkNodeContainerBlockEntity; +import java.util.HashSet; +import java.util.Set; + import net.minecraft.core.BlockPos; import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.chat.Component; @@ -19,12 +22,28 @@ public class AutocraftingMonitorBlockEntity extends AbstractBaseNetworkNodeContainerBlockEntity implements NetworkNodeExtendedMenuProvider { + private final Set watchers = new HashSet<>(); + public AutocraftingMonitorBlockEntity(final BlockPos pos, final BlockState state) { super(BlockEntities.INSTANCE.getAutocraftingMonitor(), pos, state, new SimpleNetworkNode( Platform.INSTANCE.getConfig().getAutocraftingMonitor().getEnergyUsage() )); } + void addWatcher(final AutocraftingMonitorWatcher watcher) { + watchers.add(watcher); + } + + void removeWatcher(final AutocraftingMonitorWatcher watcher) { + watchers.remove(watcher); + } + + @Override + protected void activenessChanged(final boolean newActive) { + super.activenessChanged(newActive); + watchers.forEach(watcher -> watcher.activeChanged(newActive)); + } + @Override public Component getName() { return overrideName(ContentNames.AUTOCRAFTING_MONITOR); @@ -38,7 +57,7 @@ protected boolean doesBlockStateChangeWarrantNetworkNodeUpdate(final BlockState @Override public AutocraftingMonitorData getMenuData() { - return new AutocraftingMonitorData(new TaskStatusProviderImpl().getStatuses()); + return new AutocraftingMonitorData(new TaskStatusProviderImpl().getStatuses(), mainNetworkNode.isActive()); } @Override @@ -48,6 +67,6 @@ public StreamEncoder getMenuCo @Override public AbstractContainerMenu createMenu(final int syncId, final Inventory inventory, final Player player) { - return new AutocraftingMonitorContainerMenu(syncId, player, new TaskStatusProviderImpl()); + return new AutocraftingMonitorContainerMenu(syncId, player, new TaskStatusProviderImpl(), this); } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AutocraftingMonitorContainerMenu.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AutocraftingMonitorContainerMenu.java index 15cc28f8d..e6d29160f 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AutocraftingMonitorContainerMenu.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AutocraftingMonitorContainerMenu.java @@ -1,174 +1,48 @@ package com.refinedmods.refinedstorage.common.autocrafting.monitor; -import com.refinedmods.refinedstorage.api.autocrafting.TaskId; -import com.refinedmods.refinedstorage.api.autocrafting.status.TaskStatus; -import com.refinedmods.refinedstorage.api.autocrafting.status.TaskStatusListener; import com.refinedmods.refinedstorage.api.autocrafting.status.TaskStatusProvider; import com.refinedmods.refinedstorage.common.content.Menus; -import com.refinedmods.refinedstorage.common.support.AbstractBaseContainerMenu; -import com.refinedmods.refinedstorage.common.support.packet.c2s.C2SPackets; -import com.refinedmods.refinedstorage.common.support.packet.s2c.S2CPackets; +import com.refinedmods.refinedstorage.common.support.RedstoneMode; +import com.refinedmods.refinedstorage.common.support.containermenu.ClientProperty; +import com.refinedmods.refinedstorage.common.support.containermenu.PropertyTypes; +import com.refinedmods.refinedstorage.common.support.containermenu.ServerProperty; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; import javax.annotation.Nullable; -import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; -public class AutocraftingMonitorContainerMenu extends AbstractBaseContainerMenu implements TaskStatusListener { - private final Map statusByTaskId; - private final List tasks; - private final List tasksView; +public class AutocraftingMonitorContainerMenu extends AbstractAutocraftingMonitorContainerMenu { @Nullable - private final TaskStatusProvider taskStatusProvider; - private final Player player; - - @Nullable - private AutocraftingMonitorListener listener; - - @Nullable - private TaskId currentTaskId; + private final AutocraftingMonitorBlockEntity autocraftingMonitor; public AutocraftingMonitorContainerMenu(final int syncId, final Inventory playerInventory, final AutocraftingMonitorData data) { - super(Menus.INSTANCE.getAutocraftingMonitor(), syncId); - this.statusByTaskId = data.statuses().stream().collect(Collectors.toMap( - s -> s.info().id(), - s -> s - )); - this.tasks = data.statuses().stream().map(TaskStatus::info).collect(Collectors.toList()); - this.tasksView = Collections.unmodifiableList(tasks); - this.currentTaskId = data.statuses().isEmpty() ? null : data.statuses().getFirst().info().id(); - this.taskStatusProvider = null; - this.player = playerInventory.player; + super(Menus.INSTANCE.getAutocraftingMonitor(), syncId, playerInventory, data); + registerProperty(new ClientProperty<>(PropertyTypes.REDSTONE_MODE, RedstoneMode.IGNORE)); + this.autocraftingMonitor = null; } AutocraftingMonitorContainerMenu(final int syncId, final Player player, - final TaskStatusProvider taskStatusProvider) { - super(Menus.INSTANCE.getAutocraftingMonitor(), syncId); - this.statusByTaskId = Collections.emptyMap(); - this.tasks = Collections.emptyList(); - this.tasksView = Collections.emptyList(); - this.currentTaskId = null; - this.taskStatusProvider = taskStatusProvider; - this.player = player; - taskStatusProvider.addListener(this); + final TaskStatusProvider taskStatusProvider, + final AutocraftingMonitorBlockEntity autocraftingMonitor) { + super(Menus.INSTANCE.getAutocraftingMonitor(), syncId, player, taskStatusProvider); + registerProperty(new ServerProperty<>( + PropertyTypes.REDSTONE_MODE, + autocraftingMonitor::getRedstoneMode, + autocraftingMonitor::setRedstoneMode + )); + this.autocraftingMonitor = autocraftingMonitor; + autocraftingMonitor.addWatcher(this); } @Override public void removed(final Player removedPlayer) { super.removed(removedPlayer); - if (taskStatusProvider != null) { - taskStatusProvider.removeListener(this); - } - } - - @Override - public void broadcastChanges() { - super.broadcastChanges(); - if (taskStatusProvider instanceof TaskStatusProviderImpl taskStatusProviderImpl) { - taskStatusProviderImpl.testTick(); - } - } - - void setListener(@Nullable final AutocraftingMonitorListener listener) { - this.listener = listener; - } - - List getCurrentItems() { - final TaskStatus status = statusByTaskId.get(currentTaskId); - if (status == null) { - return Collections.emptyList(); - } - return status.items(); - } - - List getTasks() { - return tasksView; - } - - float getPercentageCompleted(final TaskId taskId) { - final TaskStatus status = statusByTaskId.get(taskId); - return status == null ? 0 : status.percentageCompleted(); - } - - void setCurrentTaskId(@Nullable final TaskId taskId) { - this.currentTaskId = taskId; - loadCurrentTask(); - } - - void loadCurrentTask() { - if (listener != null) { - listener.currentTaskChanged(currentTaskId == null ? null : statusByTaskId.get(currentTaskId)); - } - } - - @Override - public void taskStatusChanged(final TaskStatus status) { - if (taskStatusProvider != null && player instanceof ServerPlayer serverPlayer) { - S2CPackets.sendAutocraftingMonitorTaskStatusChanged(serverPlayer, status); - return; - } - statusByTaskId.put(status.info().id(), status); - } - - @Override - public void taskRemoved(final TaskId id) { - if (taskStatusProvider != null && player instanceof ServerPlayer serverPlayer) { - S2CPackets.sendAutocraftingMonitorTaskRemoved(serverPlayer, id); - return; - } - statusByTaskId.remove(id); - tasks.removeIf(task -> task.id().equals(id)); - if (listener != null) { - listener.taskRemoved(id); - } - if (id.equals(currentTaskId)) { - currentTaskId = tasks.isEmpty() ? null : tasks.getFirst().id(); - loadCurrentTask(); - } - } - - @Override - public void taskAdded(final TaskStatus status) { - if (taskStatusProvider != null && player instanceof ServerPlayer serverPlayer) { - S2CPackets.sendAutocraftingMonitorTaskAdded(serverPlayer, status); - return; - } - statusByTaskId.put(status.info().id(), status); - tasks.add(status.info()); - if (listener != null) { - listener.taskAdded(status); - } - if (currentTaskId == null) { - currentTaskId = status.info().id(); - loadCurrentTask(); - } - } - - public void cancelTask(final TaskId taskId) { - if (taskStatusProvider != null) { - taskStatusProvider.cancel(taskId); - } - } - - void cancelCurrentTask() { - if (currentTaskId != null) { - C2SPackets.sendAutocraftingMonitorCancel(currentTaskId); - } - } - - public void cancelAllTasks() { - if (taskStatusProvider != null) { - taskStatusProvider.cancelAll(); - } else { - C2SPackets.sendAutocraftingMonitorCancelAll(); + if (autocraftingMonitor != null) { + autocraftingMonitor.removeWatcher(this); } } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AutocraftingMonitorData.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AutocraftingMonitorData.java index 24df0d6a0..9d5b8c9b6 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AutocraftingMonitorData.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AutocraftingMonitorData.java @@ -9,11 +9,12 @@ import net.minecraft.network.codec.ByteBufCodecs; import net.minecraft.network.codec.StreamCodec; -public record AutocraftingMonitorData(List statuses) { +public record AutocraftingMonitorData(List statuses, boolean active) { public static final StreamCodec STREAM_CODEC = StreamCodec.composite( ByteBufCodecs.collection(ArrayList::new, AutocraftingMonitorStreamCodecs.STATUS_STREAM_CODEC), AutocraftingMonitorData::statuses, + ByteBufCodecs.BOOL, AutocraftingMonitorData::active, AutocraftingMonitorData::new ); } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AutocraftingMonitorScreen.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AutocraftingMonitorScreen.java index 5af4f1cb5..d7341a5cc 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AutocraftingMonitorScreen.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AutocraftingMonitorScreen.java @@ -5,7 +5,9 @@ import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; import com.refinedmods.refinedstorage.common.api.support.resource.ResourceRendering; import com.refinedmods.refinedstorage.common.support.AbstractBaseScreen; +import com.refinedmods.refinedstorage.common.support.containermenu.PropertyTypes; import com.refinedmods.refinedstorage.common.support.tooltip.SmallText; +import com.refinedmods.refinedstorage.common.support.widget.RedstoneModeSideButtonWidget; import com.refinedmods.refinedstorage.common.support.widget.ScrollbarWidget; import java.util.ArrayList; @@ -28,7 +30,7 @@ import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createIdentifier; import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createTranslation; -public class AutocraftingMonitorScreen extends AbstractBaseScreen +public class AutocraftingMonitorScreen extends AbstractBaseScreen implements AutocraftingMonitorListener { static final int TASK_BUTTON_HEIGHT = 168 / 7; static final int TASK_BUTTON_WIDTH = 64; @@ -83,7 +85,7 @@ public class AutocraftingMonitorScreen extends AbstractBaseScreen taskButtons = new ArrayList<>(); - public AutocraftingMonitorScreen(final AutocraftingMonitorContainerMenu menu, + public AutocraftingMonitorScreen(final AbstractAutocraftingMonitorContainerMenu menu, final Inventory playerInventory, final Component title) { super(menu, playerInventory, title); @@ -119,6 +121,14 @@ protected void init() { .size(font.width(CANCEL_ALL) + 14, 20).build()); cancelAllButton.active = false; getMenu().loadCurrentTask(); + if (getMenu().hasProperty(PropertyTypes.REDSTONE_MODE)) { + addSideButton(new RedstoneModeSideButtonWidget(getMenu().getProperty(PropertyTypes.REDSTONE_MODE))); + } + } + + @Override + protected int getSideButtonX() { + return leftPos + imageWidth + 2; } private void initTaskButtons() { @@ -141,8 +151,8 @@ private void initTaskButtons() { } }); updateTaskButtonsScrollbar(); - for (int i = 0; i < getMenu().getTasks().size(); ++i) { - final TaskStatus.TaskInfo taskId = getMenu().getTasks().get(i); + for (int i = 0; i < getMenu().getTasksView().size(); ++i) { + final TaskStatus.TaskInfo taskId = getMenu().getTasksView().get(i); final int buttonY = getTaskButtonY(i); final AutocraftingTaskButton button = new AutocraftingTaskButton( getTaskButtonsInnerX(), @@ -157,6 +167,9 @@ private void initTaskButtons() { } private boolean isTaskButtonVisible(final int y) { + if (!getMenu().isActive()) { + return false; + } final int innerY = getTaskButtonsInnerY(); return y >= innerY - TASK_BUTTON_HEIGHT && y <= innerY + TASKS_INNER_HEIGHT; } @@ -174,19 +187,6 @@ public void render(final GuiGraphics graphics, final int mouseX, final int mouse if (taskButtonsScrollbar != null) { taskButtonsScrollbar.render(graphics, mouseX, mouseY, partialTicks); } - - final int tasksInnerX = getTaskButtonsInnerX(); - final int tasksInnerY = getTaskButtonsInnerY(); - graphics.enableScissor( - tasksInnerX, - tasksInnerY, - tasksInnerX + TASKS_INNER_WIDTH, - tasksInnerY + TASKS_INNER_HEIGHT - ); - for (final AutocraftingTaskButton taskButton : taskButtons) { - taskButton.render(graphics, mouseX, mouseY, partialTicks); - } - graphics.disableScissor(); } @Override @@ -194,7 +194,7 @@ protected void renderBg(final GuiGraphics graphics, final float delta, final int super.renderBg(graphics, delta, mouseX, mouseY); graphics.blitSprite(TASKS, leftPos - TASKS_WIDTH + 4, topPos, TASKS_WIDTH, TASKS_HEIGHT); final List items = getMenu().getCurrentItems(); - if (items.isEmpty() || taskItemsScrollbar == null) { + if (items.isEmpty() || taskItemsScrollbar == null || !getMenu().isActive()) { return; } final int x = leftPos + 8; @@ -209,6 +209,19 @@ protected void renderBg(final GuiGraphics graphics, final float delta, final int renderRow(graphics, x, yy, i, items, mouseX, mouseY); } graphics.disableScissor(); + + final int tasksInnerX = getTaskButtonsInnerX(); + final int tasksInnerY = getTaskButtonsInnerY(); + graphics.enableScissor( + tasksInnerX, + tasksInnerY, + tasksInnerX + TASKS_INNER_WIDTH, + tasksInnerY + TASKS_INNER_HEIGHT + ); + for (final AutocraftingTaskButton taskButton : taskButtons) { + taskButton.render(graphics, mouseX, mouseY, delta); + } + graphics.disableScissor(); } private void renderRow(final GuiGraphics graphics, @@ -415,18 +428,6 @@ private int getTaskButtonsInnerX() { return leftPos - 83 + 4; } - private void updateTaskButtonsScrollbar() { - if (taskButtonsScrollbar == null) { - return; - } - final int totalTaskButtons = getMenu().getTasks().size() - TASKS_VISIBLE; - final int maxOffset = taskButtonsScrollbar.isSmoothScrolling() - ? totalTaskButtons * TASK_BUTTON_HEIGHT - : totalTaskButtons; - taskButtonsScrollbar.setEnabled(maxOffset > 0); - taskButtonsScrollbar.setMaxOffset(maxOffset); - } - @Override public void renderLabels(final GuiGraphics graphics, final int mouseX, final int mouseY) { graphics.drawString(font, title, titleLabelX, titleLabelY, 4210752, false); @@ -439,19 +440,38 @@ protected ResourceLocation getTexture() { @Override public void currentTaskChanged(@Nullable final TaskStatus taskStatus) { + updateTaskItemsScrollbar(taskStatus); + updateTaskButtonsScrollbar(); if (cancelButton != null) { - cancelButton.active = taskStatus != null; + cancelButton.active = getMenu().isActive() && taskStatus != null; } if (cancelAllButton != null) { - cancelAllButton.active = !menu.getTasks().isEmpty(); + cancelAllButton.active = getMenu().isActive() && !menu.getTasksView().isEmpty(); } for (final AutocraftingTaskButton taskButton : taskButtons) { - taskButton.active = taskStatus == null || !taskButton.getTaskId().equals(taskStatus.info().id()); + taskButton.active = taskStatus == null + || !taskButton.getTaskId().equals(taskStatus.info().id()); + taskButton.visible = getMenu().isActive(); } + } + + private void updateTaskButtonsScrollbar() { + if (taskButtonsScrollbar == null) { + return; + } + final int totalTaskButtons = getMenu().isActive() ? getMenu().getTasksView().size() - TASKS_VISIBLE : 0; + final int maxOffset = taskButtonsScrollbar.isSmoothScrolling() + ? totalTaskButtons * TASK_BUTTON_HEIGHT + : totalTaskButtons; + taskButtonsScrollbar.setEnabled(maxOffset > 0); + taskButtonsScrollbar.setMaxOffset(maxOffset); + } + + private void updateTaskItemsScrollbar(@Nullable final TaskStatus taskStatus) { if (taskItemsScrollbar == null) { return; } - if (taskStatus == null) { + if (taskStatus == null || !getMenu().isActive()) { taskItemsScrollbar.setEnabled(false); taskItemsScrollbar.setMaxOffset(0); return; @@ -465,7 +485,7 @@ public void currentTaskChanged(@Nullable final TaskStatus taskStatus) { @Override public void taskAdded(final TaskStatus taskStatus) { updateTaskButtonsScrollbar(); - final int buttonY = getTaskButtonY(getMenu().getTasks().size() - 1); + final int buttonY = getTaskButtonY(getMenu().getTasksView().size() - 1); final AutocraftingTaskButton button = new AutocraftingTaskButton( getTaskButtonsInnerX(), buttonY, diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AutocraftingMonitorWatcher.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AutocraftingMonitorWatcher.java new file mode 100644 index 000000000..7ee80632c --- /dev/null +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AutocraftingMonitorWatcher.java @@ -0,0 +1,6 @@ +package com.refinedmods.refinedstorage.common.autocrafting.monitor; + +@FunctionalInterface +interface AutocraftingMonitorWatcher { + void activeChanged(boolean active); +} 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 2f9c52dfa..4c1316862 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 @@ -1,10 +1,10 @@ package com.refinedmods.refinedstorage.common.grid; -import com.refinedmods.refinedstorage.api.autocrafting.preview.Preview; -import com.refinedmods.refinedstorage.api.autocrafting.preview.PreviewProvider; import com.refinedmods.refinedstorage.api.autocrafting.Pattern; import com.refinedmods.refinedstorage.api.autocrafting.PatternRepository; import com.refinedmods.refinedstorage.api.autocrafting.PatternRepositoryImpl; +import com.refinedmods.refinedstorage.api.autocrafting.preview.Preview; +import com.refinedmods.refinedstorage.api.autocrafting.preview.PreviewProvider; import com.refinedmods.refinedstorage.api.grid.operations.GridExtractMode; import com.refinedmods.refinedstorage.api.grid.operations.GridInsertMode; import com.refinedmods.refinedstorage.api.grid.query.GridQueryParserException; diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/AbstractBaseScreen.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/AbstractBaseScreen.java index 57ef1c420..72e200b35 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/AbstractBaseScreen.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/AbstractBaseScreen.java @@ -84,6 +84,10 @@ protected int getSideButtonY() { return 6; } + protected int getSideButtonX() { + return leftPos - AbstractSideButtonWidget.SIZE - 2; + } + @Override protected void init() { clearWidgets(); @@ -144,7 +148,7 @@ protected void renderResourceSlots(final GuiGraphics graphics) { } public void addSideButton(final AbstractSideButtonWidget button) { - button.setX(leftPos - button.getWidth() - 2); + button.setX(getSideButtonX()); button.setY(topPos + sideButtonY); exclusionZones.add(new Rect2i(button.getX(), button.getY(), button.getWidth(), button.getHeight())); sideButtonY += button.getHeight() + 2; diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/c2s/AutocraftingMonitorCancelAllPacket.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/c2s/AutocraftingMonitorCancelAllPacket.java index 94b07741e..891a7c38d 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/c2s/AutocraftingMonitorCancelAllPacket.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/c2s/AutocraftingMonitorCancelAllPacket.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage.common.support.packet.c2s; -import com.refinedmods.refinedstorage.common.autocrafting.monitor.AutocraftingMonitorContainerMenu; +import com.refinedmods.refinedstorage.common.autocrafting.monitor.AbstractAutocraftingMonitorContainerMenu; import com.refinedmods.refinedstorage.common.support.packet.PacketContext; import net.minecraft.network.RegistryFriendlyByteBuf; @@ -18,7 +18,7 @@ public record AutocraftingMonitorCancelAllPacket() implements CustomPacketPayloa StreamCodec.unit(INSTANCE); public static void handle(final PacketContext ctx) { - if (ctx.getPlayer().containerMenu instanceof AutocraftingMonitorContainerMenu containerMenu) { + if (ctx.getPlayer().containerMenu instanceof AbstractAutocraftingMonitorContainerMenu containerMenu) { containerMenu.cancelAllTasks(); } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/c2s/AutocraftingMonitorCancelPacket.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/c2s/AutocraftingMonitorCancelPacket.java index 27f5dd090..c7ffa45b6 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/c2s/AutocraftingMonitorCancelPacket.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/c2s/AutocraftingMonitorCancelPacket.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage.common.support.packet.c2s; import com.refinedmods.refinedstorage.api.autocrafting.TaskId; -import com.refinedmods.refinedstorage.common.autocrafting.monitor.AutocraftingMonitorContainerMenu; +import com.refinedmods.refinedstorage.common.autocrafting.monitor.AbstractAutocraftingMonitorContainerMenu; import com.refinedmods.refinedstorage.common.autocrafting.monitor.AutocraftingMonitorStreamCodecs; import com.refinedmods.refinedstorage.common.support.packet.PacketContext; @@ -22,7 +22,7 @@ public record AutocraftingMonitorCancelPacket(TaskId taskId) implements CustomPa ); public static void handle(final AutocraftingMonitorCancelPacket packet, final PacketContext ctx) { - if (ctx.getPlayer().containerMenu instanceof AutocraftingMonitorContainerMenu containerMenu) { + if (ctx.getPlayer().containerMenu instanceof AbstractAutocraftingMonitorContainerMenu containerMenu) { containerMenu.cancelTask(packet.taskId()); } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/s2c/AutocraftingMonitorActivePacket.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/s2c/AutocraftingMonitorActivePacket.java new file mode 100644 index 000000000..10a3cfe2a --- /dev/null +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/s2c/AutocraftingMonitorActivePacket.java @@ -0,0 +1,35 @@ +package com.refinedmods.refinedstorage.common.support.packet.s2c; + +import com.refinedmods.refinedstorage.common.autocrafting.monitor.AbstractAutocraftingMonitorContainerMenu; +import com.refinedmods.refinedstorage.common.support.packet.PacketContext; + +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.world.inventory.AbstractContainerMenu; + +import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createIdentifier; + +public record AutocraftingMonitorActivePacket(boolean active) implements CustomPacketPayload { + public static final Type PACKET_TYPE = new Type<>( + createIdentifier("autocrafting_monitor") + ); + public static final StreamCodec STREAM_CODEC = + StreamCodec.composite( + ByteBufCodecs.BOOL, AutocraftingMonitorActivePacket::active, + AutocraftingMonitorActivePacket::new + ); + + public static void handle(final AutocraftingMonitorActivePacket packet, final PacketContext ctx) { + final AbstractContainerMenu menu = ctx.getPlayer().containerMenu; + if (menu instanceof AbstractAutocraftingMonitorContainerMenu containerMenu) { + containerMenu.activeChanged(packet.active); + } + } + + @Override + public Type type() { + return PACKET_TYPE; + } +} diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/s2c/AutocraftingMonitorTaskAddedPacket.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/s2c/AutocraftingMonitorTaskAddedPacket.java index 508538305..5c09872ee 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/s2c/AutocraftingMonitorTaskAddedPacket.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/s2c/AutocraftingMonitorTaskAddedPacket.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage.common.support.packet.s2c; import com.refinedmods.refinedstorage.api.autocrafting.status.TaskStatus; -import com.refinedmods.refinedstorage.common.autocrafting.monitor.AutocraftingMonitorContainerMenu; +import com.refinedmods.refinedstorage.common.autocrafting.monitor.AbstractAutocraftingMonitorContainerMenu; import com.refinedmods.refinedstorage.common.autocrafting.monitor.AutocraftingMonitorStreamCodecs; import com.refinedmods.refinedstorage.common.support.packet.PacketContext; @@ -23,7 +23,7 @@ public record AutocraftingMonitorTaskAddedPacket(TaskStatus taskStatus) implemen ); public static void handle(final AutocraftingMonitorTaskAddedPacket packet, final PacketContext ctx) { - if (ctx.getPlayer().containerMenu instanceof AutocraftingMonitorContainerMenu containerMenu) { + if (ctx.getPlayer().containerMenu instanceof AbstractAutocraftingMonitorContainerMenu containerMenu) { containerMenu.taskAdded(packet.taskStatus()); } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/s2c/AutocraftingMonitorTaskRemovedPacket.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/s2c/AutocraftingMonitorTaskRemovedPacket.java index 2363eecea..b7f6f220d 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/s2c/AutocraftingMonitorTaskRemovedPacket.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/s2c/AutocraftingMonitorTaskRemovedPacket.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage.common.support.packet.s2c; import com.refinedmods.refinedstorage.api.autocrafting.TaskId; -import com.refinedmods.refinedstorage.common.autocrafting.monitor.AutocraftingMonitorContainerMenu; +import com.refinedmods.refinedstorage.common.autocrafting.monitor.AbstractAutocraftingMonitorContainerMenu; import com.refinedmods.refinedstorage.common.autocrafting.monitor.AutocraftingMonitorStreamCodecs; import com.refinedmods.refinedstorage.common.support.packet.PacketContext; @@ -23,7 +23,7 @@ public record AutocraftingMonitorTaskRemovedPacket(TaskId taskId) implements Cus ); public static void handle(final AutocraftingMonitorTaskRemovedPacket packet, final PacketContext ctx) { - if (ctx.getPlayer().containerMenu instanceof AutocraftingMonitorContainerMenu containerMenu) { + if (ctx.getPlayer().containerMenu instanceof AbstractAutocraftingMonitorContainerMenu containerMenu) { containerMenu.taskRemoved(packet.taskId()); } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/s2c/AutocraftingMonitorTaskStatusChangedPacket.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/s2c/AutocraftingMonitorTaskStatusChangedPacket.java index 90e6684b3..bae8a82a6 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/s2c/AutocraftingMonitorTaskStatusChangedPacket.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/packet/s2c/AutocraftingMonitorTaskStatusChangedPacket.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage.common.support.packet.s2c; import com.refinedmods.refinedstorage.api.autocrafting.status.TaskStatus; -import com.refinedmods.refinedstorage.common.autocrafting.monitor.AutocraftingMonitorContainerMenu; +import com.refinedmods.refinedstorage.common.autocrafting.monitor.AbstractAutocraftingMonitorContainerMenu; import com.refinedmods.refinedstorage.common.autocrafting.monitor.AutocraftingMonitorStreamCodecs; import com.refinedmods.refinedstorage.common.support.packet.PacketContext; @@ -23,7 +23,7 @@ public record AutocraftingMonitorTaskStatusChangedPacket(TaskStatus taskStatus) ); public static void handle(final AutocraftingMonitorTaskStatusChangedPacket packet, final PacketContext ctx) { - if (ctx.getPlayer().containerMenu instanceof AutocraftingMonitorContainerMenu containerMenu) { + if (ctx.getPlayer().containerMenu instanceof AbstractAutocraftingMonitorContainerMenu containerMenu) { containerMenu.taskStatusChanged(packet.taskStatus()); } } 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 cc985ac1d..d114b3a9c 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 @@ -117,4 +117,8 @@ public static void sendAutocraftingMonitorTaskStatusChanged(final ServerPlayer p final TaskStatus taskStatus) { Platform.INSTANCE.sendPacketToClient(player, new AutocraftingMonitorTaskStatusChangedPacket(taskStatus)); } + + public static void sendAutocraftingMonitorActive(final ServerPlayer player, final boolean active) { + Platform.INSTANCE.sendPacketToClient(player, new AutocraftingMonitorActivePacket(active)); + } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/AbstractSideButtonWidget.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/AbstractSideButtonWidget.java index 55b159c29..0a5630782 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/AbstractSideButtonWidget.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/AbstractSideButtonWidget.java @@ -25,11 +25,12 @@ import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createIdentifier; public abstract class AbstractSideButtonWidget extends Button { + public static final int SIZE = 18; + private static final ResourceLocation SPRITE = createIdentifier("widget/side_button/base"); private static final ResourceLocation HOVERED_SPRITE = createIdentifier("widget/side_button/hovered"); private static final ResourceLocation HOVER_OVERLAY_SPRITE = createIdentifier("widget/side_button/hover_overlay"); - private static final int SIZE = 18; private static final int ICON_SIZE = 16; @Nullable 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 0eb7ab4c9..68df1c279 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 @@ -21,6 +21,7 @@ import com.refinedmods.refinedstorage.common.support.packet.PacketHandler; import com.refinedmods.refinedstorage.common.support.packet.s2c.AutocrafterManagerActivePacket; import com.refinedmods.refinedstorage.common.support.packet.s2c.AutocrafterNameUpdatePacket; +import com.refinedmods.refinedstorage.common.support.packet.s2c.AutocraftingMonitorActivePacket; import com.refinedmods.refinedstorage.common.support.packet.s2c.AutocraftingMonitorTaskAddedPacket; import com.refinedmods.refinedstorage.common.support.packet.s2c.AutocraftingMonitorTaskRemovedPacket; import com.refinedmods.refinedstorage.common.support.packet.s2c.AutocraftingMonitorTaskStatusChangedPacket; @@ -324,6 +325,10 @@ private void registerPacketHandlers() { AutocraftingMonitorTaskStatusChangedPacket.PACKET_TYPE, wrapHandler(AutocraftingMonitorTaskStatusChangedPacket::handle) ); + ClientPlayNetworking.registerGlobalReceiver( + AutocraftingMonitorActivePacket.PACKET_TYPE, + wrapHandler(AutocraftingMonitorActivePacket::handle) + ); } 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 d085b482f..35763ef00 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 @@ -59,6 +59,7 @@ import com.refinedmods.refinedstorage.common.support.packet.c2s.UseSlotReferencedItemPacket; import com.refinedmods.refinedstorage.common.support.packet.s2c.AutocrafterManagerActivePacket; import com.refinedmods.refinedstorage.common.support.packet.s2c.AutocrafterNameUpdatePacket; +import com.refinedmods.refinedstorage.common.support.packet.s2c.AutocraftingMonitorActivePacket; import com.refinedmods.refinedstorage.common.support.packet.s2c.AutocraftingMonitorTaskAddedPacket; import com.refinedmods.refinedstorage.common.support.packet.s2c.AutocraftingMonitorTaskRemovedPacket; import com.refinedmods.refinedstorage.common.support.packet.s2c.AutocraftingMonitorTaskStatusChangedPacket; @@ -477,6 +478,10 @@ private void registerServerToClientPackets() { AutocraftingMonitorTaskStatusChangedPacket.PACKET_TYPE, AutocraftingMonitorTaskStatusChangedPacket.STREAM_CODEC ); + PayloadTypeRegistry.playS2C().register( + AutocraftingMonitorActivePacket.PACKET_TYPE, + AutocraftingMonitorActivePacket.STREAM_CODEC + ); } private void registerClientToServerPackets() { 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 ac3431d8e..785edbcc4 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 @@ -59,6 +59,7 @@ import com.refinedmods.refinedstorage.common.support.packet.c2s.UseSlotReferencedItemPacket; import com.refinedmods.refinedstorage.common.support.packet.s2c.AutocrafterManagerActivePacket; import com.refinedmods.refinedstorage.common.support.packet.s2c.AutocrafterNameUpdatePacket; +import com.refinedmods.refinedstorage.common.support.packet.s2c.AutocraftingMonitorActivePacket; import com.refinedmods.refinedstorage.common.support.packet.s2c.AutocraftingMonitorTaskAddedPacket; import com.refinedmods.refinedstorage.common.support.packet.s2c.AutocraftingMonitorTaskRemovedPacket; import com.refinedmods.refinedstorage.common.support.packet.s2c.AutocraftingMonitorTaskStatusChangedPacket; @@ -673,6 +674,11 @@ private static void registerServerToClientPackets(final PayloadRegistrar registr AutocraftingMonitorTaskStatusChangedPacket.STREAM_CODEC, wrapHandler(AutocraftingMonitorTaskStatusChangedPacket::handle) ); + registrar.playToClient( + AutocraftingMonitorActivePacket.PACKET_TYPE, + AutocraftingMonitorActivePacket.STREAM_CODEC, + wrapHandler(AutocraftingMonitorActivePacket::handle) + ); } private static void registerClientToServerPackets(final PayloadRegistrar registrar) { diff --git a/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/autocrafting/AutocraftingNetworkComponentImpl.java b/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/autocrafting/AutocraftingNetworkComponentImpl.java index c52adb449..e3407c8f3 100644 --- a/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/autocrafting/AutocraftingNetworkComponentImpl.java +++ b/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/autocrafting/AutocraftingNetworkComponentImpl.java @@ -5,7 +5,6 @@ import com.refinedmods.refinedstorage.api.autocrafting.preview.Preview; import com.refinedmods.refinedstorage.api.autocrafting.preview.PreviewItem; import com.refinedmods.refinedstorage.api.autocrafting.preview.PreviewType; -import com.refinedmods.refinedstorage.api.autocrafting.status.TaskStatus; import com.refinedmods.refinedstorage.api.network.autocrafting.AutocraftingNetworkComponent; import com.refinedmods.refinedstorage.api.network.autocrafting.ParentContainer; import com.refinedmods.refinedstorage.api.network.autocrafting.PatternListener;