More client/server cleanup.

This commit is contained in:
modmuss50 2022-03-02 14:20:34 +00:00
parent 14c237e4a4
commit 0296c59393
9 changed files with 83 additions and 41 deletions

View file

@ -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;

View file

@ -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);
}
}
}

View file

@ -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;

View file

@ -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())
)
);
}
}

View file

@ -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, Boolean> ITEM_ID = Maps.newHashMap();

View file

@ -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;

View file

@ -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<BuiltScreenHandler> {
@ -47,9 +50,17 @@ public class DataDrivenGui extends GuiBase<BuiltScreenHandler> {
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);

View file

@ -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<ItemStack> 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());
}
}

View file

@ -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<OreDepth> oreDepths) {
return NetworkManager.createClientBoundPacket(ORE_DEPTH, OreDepth.LIST_CODEC, oreDepths);
}
public static IdentifiedPacket createPacketOpenManual() {
return NetworkManager.createClientBoundPacket(OPEN_MANUAL, packetBuffer -> {
});
}
}