From fb709f06ec16fe70214f35bcb1df31b727eb3586 Mon Sep 17 00:00:00 2001 From: Azanor Date: Wed, 21 Sep 2016 15:46:32 +0200 Subject: [PATCH] made baubles packets a bit more thread safe --- build.gradle | 2 +- src/main/java/baubles/common/Baubles.java | 2 +- .../java/baubles/common/container/SlotBauble.java | 2 -- .../java/baubles/common/network/PacketHandler.java | 1 - .../common/network/PacketOpenBaublesInventory.java | 9 +++++++-- .../common/network/PacketOpenNormalInventory.java | 12 +++++++++--- src/main/resources/changelog.txt | 3 +++ 7 files changed, 21 insertions(+), 10 deletions(-) diff --git a/build.gradle b/build.gradle index a5d392db..e3ddf2e2 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,7 @@ buildscript { apply plugin: 'net.minecraftforge.gradle.forge' -version = "1.10.2-1.3.BETA1" +version = "1.10.2-1.3.BETA2" group= "com.azanor.baubles" archivesBaseName = "Baubles" diff --git a/src/main/java/baubles/common/Baubles.java b/src/main/java/baubles/common/Baubles.java index 450f1593..550e98d9 100644 --- a/src/main/java/baubles/common/Baubles.java +++ b/src/main/java/baubles/common/Baubles.java @@ -30,7 +30,7 @@ public class Baubles { public static final String MODID = "Baubles"; public static final String MODNAME = "Baubles"; - public static final String VERSION = "1.3.BETA1"; + public static final String VERSION = "1.3.BETA2"; @SidedProxy(clientSide = "baubles.client.ClientProxy", serverSide = "baubles.common.CommonProxy") public static CommonProxy proxy; diff --git a/src/main/java/baubles/common/container/SlotBauble.java b/src/main/java/baubles/common/container/SlotBauble.java index 3e019bc0..8381f6a8 100644 --- a/src/main/java/baubles/common/container/SlotBauble.java +++ b/src/main/java/baubles/common/container/SlotBauble.java @@ -42,7 +42,6 @@ public boolean canTakeStack(EntityPlayer player) { public void onPickupFromSlot(EntityPlayer playerIn, ItemStack stack) { if (!this.getHasStack() && !((IBaublesItemHandler)this.getItemHandler()).isEventBlocked()) { ((IBauble)stack.getItem()).onUnequipped(this.getStack(), playerIn); - System.out.println("onUnequipped "+playerIn.getEntityWorld()); } super.onPickupFromSlot(playerIn, stack); } @@ -52,7 +51,6 @@ public void putStack(ItemStack stack) { super.putStack(stack); if (this.getHasStack() && !((IBaublesItemHandler)this.getItemHandler()).isEventBlocked()) { ((IBauble)this.getStack().getItem()).onEquipped(this.getStack(), player); - System.out.println("onEquipped "+player.getEntityWorld()); } } diff --git a/src/main/java/baubles/common/network/PacketHandler.java b/src/main/java/baubles/common/network/PacketHandler.java index 1b2a7105..734739a4 100644 --- a/src/main/java/baubles/common/network/PacketHandler.java +++ b/src/main/java/baubles/common/network/PacketHandler.java @@ -13,7 +13,6 @@ public static void init() { INSTANCE.registerMessage(PacketOpenBaublesInventory.class, PacketOpenBaublesInventory.class, 0, Side.SERVER); INSTANCE.registerMessage(PacketOpenNormalInventory.class, PacketOpenNormalInventory.class, 1, Side.SERVER); -// INSTANCE.registerMessage(PacketSyncBauble.class, PacketSyncBauble.class, 2, Side.CLIENT); } diff --git a/src/main/java/baubles/common/network/PacketOpenBaublesInventory.java b/src/main/java/baubles/common/network/PacketOpenBaublesInventory.java index 34b5b106..fc89aed2 100644 --- a/src/main/java/baubles/common/network/PacketOpenBaublesInventory.java +++ b/src/main/java/baubles/common/network/PacketOpenBaublesInventory.java @@ -1,11 +1,13 @@ package baubles.common.network; +import baubles.common.Baubles; import io.netty.buffer.ByteBuf; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.IThreadListener; +import net.minecraft.world.WorldServer; import net.minecraftforge.fml.common.network.simpleimpl.IMessage; import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; -import baubles.common.Baubles; public class PacketOpenBaublesInventory implements IMessage, IMessageHandler { @@ -21,7 +23,10 @@ public void fromBytes(ByteBuf buffer) {} @Override public IMessage onMessage(PacketOpenBaublesInventory message, MessageContext ctx) { - ctx.getServerHandler().playerEntity.openGui(Baubles.instance, Baubles.GUI, ctx.getServerHandler().playerEntity.worldObj, (int)ctx.getServerHandler().playerEntity.posX, (int)ctx.getServerHandler().playerEntity.posY, (int)ctx.getServerHandler().playerEntity.posZ); + IThreadListener mainThread = (WorldServer) ctx.getServerHandler().playerEntity.worldObj; + mainThread.addScheduledTask(new Runnable(){ public void run() { + ctx.getServerHandler().playerEntity.openGui(Baubles.instance, Baubles.GUI, ctx.getServerHandler().playerEntity.worldObj, (int)ctx.getServerHandler().playerEntity.posX, (int)ctx.getServerHandler().playerEntity.posY, (int)ctx.getServerHandler().playerEntity.posZ); + }}); return null; } diff --git a/src/main/java/baubles/common/network/PacketOpenNormalInventory.java b/src/main/java/baubles/common/network/PacketOpenNormalInventory.java index 0872e909..ce99a21b 100644 --- a/src/main/java/baubles/common/network/PacketOpenNormalInventory.java +++ b/src/main/java/baubles/common/network/PacketOpenNormalInventory.java @@ -2,6 +2,8 @@ import io.netty.buffer.ByteBuf; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.IThreadListener; +import net.minecraft.world.WorldServer; import net.minecraftforge.fml.common.network.simpleimpl.IMessage; import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; @@ -20,10 +22,14 @@ public void fromBytes(ByteBuf buffer) {} @Override public IMessage onMessage(PacketOpenNormalInventory message, MessageContext ctx) { - ctx.getServerHandler().playerEntity.openContainer.onContainerClosed(ctx.getServerHandler().playerEntity); - ctx.getServerHandler().playerEntity.openContainer = ctx.getServerHandler().playerEntity.inventoryContainer; + IThreadListener mainThread = (WorldServer) ctx.getServerHandler().playerEntity.worldObj; + mainThread.addScheduledTask(new Runnable(){ public void run() { + ctx.getServerHandler().playerEntity.openContainer.onContainerClosed(ctx.getServerHandler().playerEntity); + ctx.getServerHandler().playerEntity.openContainer = ctx.getServerHandler().playerEntity.inventoryContainer; + }}); return null; } - + + } diff --git a/src/main/resources/changelog.txt b/src/main/resources/changelog.txt index 381b70be..eb05ba0d 100644 --- a/src/main/resources/changelog.txt +++ b/src/main/resources/changelog.txt @@ -1,3 +1,6 @@ +1.3.BETA2 +- made baubles packets a bit more thread safe + 1.3.BETA1 - note that this is an alpha version - testing is required - update to MC 1.10.2 and Java 1.8