Skip to content

Commit

Permalink
Fix packets not sending client to server properly
Browse files Browse the repository at this point in the history
  • Loading branch information
KnightMiner committed Nov 23, 2019
1 parent fca4ad4 commit 4dbd471
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Expand Up @@ -15,7 +15,7 @@ public class InspirationsNetwork extends NetworkWrapper {
public static InspirationsNetwork instance = new InspirationsNetwork();

private InspirationsNetwork() {
super(Inspirations.modID);
super(Inspirations.modID+":"+"network");
}

public void setup() {
Expand Down
Expand Up @@ -9,13 +9,12 @@
import net.minecraftforge.client.model.ModelDataManager;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.network.NetworkEvent;

import slimeknights.mantle.network.AbstractPacketThreadsafe;
import slimeknights.mantle.network.AbstractPacket;
import slimeknights.mantle.tileentity.InventoryTileEntity;

import java.util.function.Supplier;

public class InventorySlotSyncPacket extends AbstractPacketThreadsafe {
public class InventorySlotSyncPacket extends AbstractPacket {

public ItemStack itemStack;
public int slot;
Expand All @@ -38,6 +37,7 @@ public void handle(Supplier<NetworkEvent.Context> context) {
case PLAY_TO_SERVER:
throw new UnsupportedOperationException("Clientside only");
}
context.get().setPacketHandled(true);

// Only ever sent to players in the same dimension as the position
// This should never be called on servers, but protect access to the clientside MC.
Expand All @@ -61,6 +61,7 @@ public static InventorySlotSyncPacket decode(PacketBuffer buf) {
return packet;
}

@Override
public void encode(PacketBuffer buf) {
writePos(pos, buf);
buf.writeShort(slot);
Expand Down
Expand Up @@ -8,11 +8,11 @@
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.network.NetworkEvent;
import slimeknights.mantle.network.AbstractPacketThreadsafe;
import slimeknights.mantle.network.AbstractPacket;

import java.util.function.Supplier;

public class MilkablePacket extends AbstractPacketThreadsafe {
public class MilkablePacket extends AbstractPacket {

private int entityID;
private boolean milkable;
Expand Down Expand Up @@ -45,6 +45,7 @@ public void handle(Supplier<NetworkEvent.Context> context) {
case PLAY_TO_SERVER:
throw new UnsupportedOperationException("Clientside only");
}
context.get().setPacketHandled(true);

// This should never be called on servers, but protect access to the clientside MC.
Entity entity = DistExecutor.callWhenOn(Dist.CLIENT, () -> () -> Minecraft.getInstance().world.getEntityByID(entityID));
Expand Down

0 comments on commit 4dbd471

Please sign in to comment.