diff --git a/src/main/java/techreborn/TechRebornClient.java b/src/main/java/techreborn/TechRebornClient.java index 77f7f9552..68dd3f71e 100644 --- a/src/main/java/techreborn/TechRebornClient.java +++ b/src/main/java/techreborn/TechRebornClient.java @@ -56,12 +56,13 @@ import reborncore.common.util.ItemUtils; import reborncore.mixin.client.AccessorModelPredicateProviderRegistry; import team.reborn.energy.api.base.SimpleBatteryItem; import techreborn.client.ClientGuiType; +import techreborn.client.ClientboundPacketHandlers; import techreborn.client.render.DynamicBucketBakedModel; import techreborn.client.render.DynamicCellBakedModel; import techreborn.client.render.entitys.CableCoverRenderer; import techreborn.client.render.entitys.StorageUnitRenderer; import techreborn.client.render.entitys.TurbineRenderer; -import techreborn.events.StackToolTipHandler; +import techreborn.client.events.StackToolTipHandler; import techreborn.init.ModFluids; import techreborn.init.TRBlockEntities; import techreborn.init.TRContent; @@ -148,7 +149,7 @@ public class TechRebornClient implements ClientModInitializer { }); StackToolTipHandler.setup(); - ClientboundPackets.init(); + ClientboundPacketHandlers.init(); GuiBase.wrenchStack = new ItemStack(TRContent.WRENCH); GuiBase.fluidCellProvider = DynamicCellItem::getCellWithFluid; diff --git a/src/main/java/techreborn/blockentity/data/DataDrivenSlot.java b/src/main/java/techreborn/blockentity/data/DataDrivenSlot.java index 769f14805..4299811cf 100644 --- a/src/main/java/techreborn/blockentity/data/DataDrivenSlot.java +++ b/src/main/java/techreborn/blockentity/data/DataDrivenSlot.java @@ -26,12 +26,8 @@ package techreborn.blockentity.data; import com.google.gson.JsonArray; import com.google.gson.JsonElement; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.JsonHelper; import org.jetbrains.annotations.NotNull; -import reborncore.client.gui.builder.GuiBase; import reborncore.client.screen.builder.BlockEntityScreenHandlerBuilder; import reborncore.common.util.serialization.SerializationUtil; @@ -52,14 +48,4 @@ public record DataDrivenSlot(int id, int x, int y, @NotNull SlotType type) { public void add(BlockEntityScreenHandlerBuilder inventoryBuilder) { type.getSlotBiConsumer().accept(inventoryBuilder, this); } - - @Environment(EnvType.CLIENT) - public void draw(MatrixStack matrixStack, GuiBase guiBase, GuiBase.Layer layer) { - // TODO find a better way to do this - if (type() == SlotType.OUTPUT) { - guiBase.drawOutputSlot(matrixStack, x(), y(), layer); - } else { - guiBase.drawSlot(matrixStack, x(), y(), layer); - } - } } diff --git a/src/main/java/techreborn/client/ClientGuiType.java b/src/main/java/techreborn/client/ClientGuiType.java index da7b5e855..ae26d0a28 100644 --- a/src/main/java/techreborn/client/ClientGuiType.java +++ b/src/main/java/techreborn/client/ClientGuiType.java @@ -31,7 +31,7 @@ import net.minecraft.block.entity.BlockEntity; import net.minecraft.util.Identifier; import techreborn.blockentity.GuiType; import techreborn.blockentity.data.DataDrivenBEProvider; -import techreborn.blockentity.data.DataDrivenGui; +import techreborn.client.gui.DataDrivenGui; import techreborn.blockentity.generator.PlasmaGeneratorBlockEntity; import techreborn.blockentity.generator.SolarPanelBlockEntity; import techreborn.blockentity.generator.advanced.DieselGeneratorBlockEntity; diff --git a/src/main/java/techreborn/client/ClientboundPacketHandlers.java b/src/main/java/techreborn/client/ClientboundPacketHandlers.java new file mode 100644 index 000000000..a55cea02f --- /dev/null +++ b/src/main/java/techreborn/client/ClientboundPacketHandlers.java @@ -0,0 +1,46 @@ +/* + * This file is part of TechReborn, licensed under the MIT License (MIT). + * + * Copyright (c) 2020 TechReborn + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package techreborn.client; + +import net.minecraft.client.MinecraftClient; +import reborncore.common.network.NetworkManager; +import techreborn.client.gui.GuiManual; +import techreborn.events.OreDepthSyncHandler; +import techreborn.world.OreDepth; + +import static techreborn.packets.ClientboundPackets.OPEN_MANUAL; +import static techreborn.packets.ClientboundPackets.ORE_DEPTH; + +public class ClientboundPacketHandlers { + public static void init() { + NetworkManager.registerClientBoundHandler(ORE_DEPTH, OreDepth.LIST_CODEC, OreDepthSyncHandler::updateDepths); + + NetworkManager.registerClientBoundHandler(OPEN_MANUAL, (client, handler, buf, responseSender) -> + client.execute(() -> + MinecraftClient.getInstance().setScreen(new GuiManual()) + ) + ); + } +} diff --git a/src/main/java/techreborn/events/StackToolTipHandler.java b/src/main/java/techreborn/client/events/StackToolTipHandler.java similarity index 96% rename from src/main/java/techreborn/events/StackToolTipHandler.java rename to src/main/java/techreborn/client/events/StackToolTipHandler.java index 21fe0fddd..7f3f56b5d 100644 --- a/src/main/java/techreborn/events/StackToolTipHandler.java +++ b/src/main/java/techreborn/client/events/StackToolTipHandler.java @@ -22,10 +22,12 @@ * SOFTWARE. */ -package techreborn.events; +package techreborn.client.events; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback; import net.minecraft.block.Block; import net.minecraft.client.MinecraftClient; @@ -42,10 +44,10 @@ import net.minecraft.text.TranslatableText; import net.minecraft.util.Formatting; import net.minecraft.util.registry.Registry; import reborncore.common.BaseBlockEntityProvider; +import techreborn.events.OreDepthSyncHandler; import techreborn.init.TRContent; import techreborn.items.DynamicCellItem; import techreborn.items.UpgradeItem; -import techreborn.utils.ToolTipAssistUtils; import techreborn.world.OreDepth; import techreborn.world.TargetDimension; @@ -53,6 +55,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; +@Environment(EnvType.CLIENT) public class StackToolTipHandler implements ItemTooltipCallback { public static final Map ITEM_ID = Maps.newHashMap(); diff --git a/src/main/java/techreborn/utils/ToolTipAssistUtils.java b/src/main/java/techreborn/client/events/ToolTipAssistUtils.java similarity index 99% rename from src/main/java/techreborn/utils/ToolTipAssistUtils.java rename to src/main/java/techreborn/client/events/ToolTipAssistUtils.java index 5faae055c..704df0aca 100644 --- a/src/main/java/techreborn/utils/ToolTipAssistUtils.java +++ b/src/main/java/techreborn/client/events/ToolTipAssistUtils.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package techreborn.utils; +package techreborn.client.events; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.resource.language.I18n; diff --git a/src/main/java/techreborn/blockentity/data/DataDrivenGui.java b/src/main/java/techreborn/client/gui/DataDrivenGui.java similarity index 83% rename from src/main/java/techreborn/blockentity/data/DataDrivenGui.java rename to src/main/java/techreborn/client/gui/DataDrivenGui.java index 0909116b3..81d87e2d0 100644 --- a/src/main/java/techreborn/blockentity/data/DataDrivenGui.java +++ b/src/main/java/techreborn/client/gui/DataDrivenGui.java @@ -22,13 +22,16 @@ * SOFTWARE. */ -package techreborn.blockentity.data; +package techreborn.client.gui; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.player.PlayerEntity; import reborncore.client.gui.builder.GuiBase; import reborncore.client.gui.guibuilder.GuiBuilder; import reborncore.common.screen.BuiltScreenHandler; +import techreborn.blockentity.data.DataDrivenBEProvider; +import techreborn.blockentity.data.DataDrivenSlot; +import techreborn.blockentity.data.SlotType; public class DataDrivenGui extends GuiBase { @@ -47,9 +50,17 @@ public class DataDrivenGui extends GuiBase { final GuiBase.Layer layer = GuiBase.Layer.BACKGROUND; final DataDrivenGui gui = this; - provider.getSlots().forEach(slot -> slot.draw(matrixStack, gui, layer)); + provider.getSlots().forEach(slot -> draw(matrixStack, gui, layer, slot)); } + + public void draw(MatrixStack matrixStack, GuiBase guiBase, GuiBase.Layer layer, DataDrivenSlot slot) { + if (slot.type() == SlotType.OUTPUT) { + guiBase.drawOutputSlot(matrixStack, slot.x(), slot.y(), layer); + } else { + guiBase.drawSlot(matrixStack, slot.x(), slot.y(), layer); + } + } @Override protected void drawForeground(MatrixStack matrixStack, final int mouseX, final int mouseY) { super.drawForeground(matrixStack, mouseX, mouseY); diff --git a/src/main/java/techreborn/items/ManualItem.java b/src/main/java/techreborn/items/ManualItem.java index 51bcf7a19..be87c74a8 100644 --- a/src/main/java/techreborn/items/ManualItem.java +++ b/src/main/java/techreborn/items/ManualItem.java @@ -24,18 +24,17 @@ package techreborn.items; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.MinecraftClient; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.util.TypedActionResult; import net.minecraft.world.World; +import reborncore.common.network.NetworkManager; import techreborn.TechReborn; -import techreborn.client.gui.GuiManual; +import techreborn.packets.ClientboundPackets; public class ManualItem extends Item { @@ -45,12 +44,10 @@ public class ManualItem extends Item { @Override public TypedActionResult use(final World world, final PlayerEntity player, final Hand hand) { - if (world.isClient) { openGui(); } + if (player instanceof ServerPlayerEntity serverPlayerEntity) { + NetworkManager.sendToPlayer(ClientboundPackets.createPacketOpenManual(), serverPlayerEntity); + } + return new TypedActionResult<>(ActionResult.SUCCESS, player.getStackInHand(hand)); } - - @Environment(EnvType.CLIENT) - private void openGui() { - MinecraftClient.getInstance().setScreen(new GuiManual()); - } } diff --git a/src/main/java/techreborn/packets/ClientboundPackets.java b/src/main/java/techreborn/packets/ClientboundPackets.java index 3875fbee3..4bb9a8a18 100644 --- a/src/main/java/techreborn/packets/ClientboundPackets.java +++ b/src/main/java/techreborn/packets/ClientboundPackets.java @@ -24,28 +24,26 @@ package techreborn.packets; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; import net.minecraft.util.Identifier; +import reborncore.common.network.ExtendedPacketBuffer; import reborncore.common.network.IdentifiedPacket; import reborncore.common.network.NetworkManager; import techreborn.TechReborn; -import techreborn.events.OreDepthSyncHandler; import techreborn.world.OreDepth; import java.util.List; +import java.util.function.Consumer; public class ClientboundPackets { public static final Identifier ORE_DEPTH = new Identifier(TechReborn.MOD_ID, "ore_depth"); - - // TODO move to own class - @Environment(EnvType.CLIENT) - public static void init() { - NetworkManager.registerClientBoundHandler(ORE_DEPTH, OreDepth.LIST_CODEC, OreDepthSyncHandler::updateDepths); - } + public static final Identifier OPEN_MANUAL = new Identifier(TechReborn.MOD_ID, "open_manual"); public static IdentifiedPacket createPacketSyncOreDepth(List oreDepths) { return NetworkManager.createClientBoundPacket(ORE_DEPTH, OreDepth.LIST_CODEC, oreDepths); } + public static IdentifiedPacket createPacketOpenManual() { + return NetworkManager.createClientBoundPacket(OPEN_MANUAL, packetBuffer -> { + }); + } }