Skip to content

Commit

Permalink
Merge pull request #485 from refinedmods/fix/GH-484/sidebuttons
Browse files Browse the repository at this point in the history
fix: changing side buttons doesn't work on Forge
  • Loading branch information
raoulvdberge authored Mar 9, 2024
2 parents bdbbc6c + 23f9170 commit aacba0b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

- Fixed losing disk when using Wrench dismantling on the Portable Grid.
- Fixed losing energy when using Wrench dismantling on the Portable Grid and the Controller.
- Fixed changing side buttons not working on Forge.

## [2.0.0-milestone.3.3] - 2024-02-17

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ public T getValue() {
}

public void setValue(final T newValue) {
Platform.INSTANCE.getClientToServerCommunications().sendPropertyChange(
type,
newValue
);
Platform.INSTANCE.getClientToServerCommunications().sendPropertyChange(type, newValue);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
package com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s;

import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseContainerMenu;
import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds;

import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.neoforge.network.handling.PlayPayloadContext;

public record PropertyChangePacket(ResourceLocation id, int value) implements CustomPacketPayload {
public record PropertyChangePacket(ResourceLocation propertyId, int value) implements CustomPacketPayload {
public static PropertyChangePacket decode(final FriendlyByteBuf buf) {
return new PropertyChangePacket(buf.readResourceLocation(), buf.readInt());
}

public static void handle(final PropertyChangePacket packet, final PlayPayloadContext ctx) {
ctx.player().ifPresent(player -> ctx.workHandler().submitAsync(() -> {
if (player.containerMenu instanceof AbstractBaseContainerMenu menu) {
menu.receivePropertyChangeFromClient(packet.id, packet.value);
menu.receivePropertyChangeFromClient(packet.propertyId, packet.value);
}
}));
}

@Override
public void write(final FriendlyByteBuf buf) {
buf.writeResourceLocation(id);
buf.writeResourceLocation(propertyId);
buf.writeInt(value);
}

@Override
public ResourceLocation id() {
return PacketIds.PROPERTY_CHANGE;
}
}

0 comments on commit aacba0b

Please sign in to comment.