Everything posted by RatCommit
-
Inventory slot syncing
Hello guys : Im trying something else to sync my inventory data with the server so i wanted to use the PacketDistributor to achieve that : // ClientPayloadHandler.class public class ClientPayloadHandler { private static Logger LOGGER = LogUtils.getLogger(); public static void handleDataOnMain(final SplitData data, final IPayloadContext context) { LOGGER.debug("ClientPayloadHandler.handleDataOnMain data = {}", data); } } //ServerPayloadHandler public class ServerPayloadHandler { private static Logger LOGGER = LogUtils.getLogger(); public static void handleDataOnMain(final SplitData data, final IPayloadContext context) { LOGGER.debug("ServerPayloadHandler.handleDataOnMain data = {}", data); } } // My Custon Data.class public record SplitData(int splitSize, int remainingSize) implements CustomPacketPayload { public static final CustomPacketPayload.Type<SplitData> TYPE = new CustomPacketPayload.Type<>(ResourceLocation.fromNamespaceAndPath("perfect_stack_splitter", "split_data")); public static final StreamCodec<ByteBuf, SplitData> STREAM_CODEC = StreamCodec.composite(ByteBufCodecs.VAR_INT, SplitData::splitSize, ByteBufCodecs.VAR_INT, SplitData::remainingSize, SplitData::new); @Override public CustomPacketPayload.Type<? extends CustomPacketPayload> type() { return TYPE; } } //Register event @SubscribeEvent public static void register(final RegisterPayloadHandlersEvent event) { final PayloadRegistrar registrar = event.registrar("1"); registrar.playBidirectional( SplitData.TYPE, SplitData.STREAM_CODEC, new DirectionalPayloadHandler<>( ClientPayloadHandler::handleDataOnMain, ServerPayloadHandler::handleDataOnMain ) ); } when i shoot this : private void onConfirm() { int maxStackSize = stack.getMaxStackSize(); int carriedStackSize = Math.min(slider.getValueInt(), maxStackSize); int totalLeft = totalSize - carriedStackSize; ItemStack carriedStack = new ItemStack(stack.getItem(), carriedStackSize); carriedStack.setCount((int) slider.getValue()); player.containerMenu.setCarried(carriedStack); stack.setCount(totalSize - carriedStackSize); PacketDistributor.sendToServer(new SplitData(carriedStackSize, totalLeft)); this.minecraft.setScreen(previous); } im getting Payload perfect_stack_splitter:split_data may not be sent to the server! did i miss something ? my goal is i wanna persist the setCount ...etc im my inventory to the server
-
Inventory slot syncing
Hello everyone So my issue is here : private void onConfirm() { int maxStackSize = stack.getMaxStackSize(); int carriedStackSize = Math.min(slider.getValueInt(), maxStackSize); int totalLeft = totalSize - carriedStackSize; ItemStack carriedStack = new ItemStack(stack.getItem(), carriedStackSize); carriedStack.setCount((int) slider.getValue()); player.containerMenu.setCarried(carriedStack); stack.setCount(totalSize - carriedStackSize); // player.containerMenu.broadcastChanges(); with and without, same issue this.minecraft.setScreen(previous); } i have this block of logic, the thing is it does the trick "visually" but instantly when i click on a slot everything goes back as first, i tried also to use player.containerMenu.broadcastChanges(); but it didnt help too what should i use from AbstractContainer or something to be able the sync those values in server side thanks a lot in advance
-
[1.20.1] Adding Custom GUI with Slider on Top of Inventory GUI - Help with Implementation
Hi everyone, I'm working on a mod where I need to display a custom GUI on top of the inventory screen that includes a slider. The goal is to allow the player to select a number using the slider, and then confirm the action, which will split an item stack (similar to shift-clicking, but with a custom number). I've successfully created custom GUIs before using Screen, but I’m running into a couple of issues when trying to integrate a slider into the inventory screen (AbstractContainerScreen): I found the slider in the forge package (net.minecraftforge.client.gui.widget.Slider), but I couldn’t find any usages or examples on how to properly implement it or use it in this context. My Questions: How can I properly integrate a slider into the custom gui screen ? Is net.minecraftforge.client.gui.widget.Slider the right class to use for this? If yes, are there any examples or recommended usages of this Forge slider widget? If not, what would be a good alternative to create a custom slider (maybe extending AbstractSlider or another class)? How do I ensure proper interaction between the slider and the rest of the inventory screen? Any advice, code snippets, or examples would be greatly appreciated! Thanks in advance for your help!
IPS spam blocked by CleanTalk.