Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

Edited by RatCommit
Forgot tags

  • Author

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.