Skip to content

Commit

Permalink
made baubles packets a bit more thread safe
Browse files Browse the repository at this point in the history
  • Loading branch information
Azanor committed Sep 21, 2016
1 parent 4434829 commit fb709f0
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/baubles/common/Baubles.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/baubles/common/container/SlotBauble.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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());
}
}

Expand Down
1 change: 0 additions & 1 deletion src/main/java/baubles/common/network/PacketHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -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<PacketOpenBaublesInventory, IMessage> {

Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}




}
3 changes: 3 additions & 0 deletions src/main/resources/changelog.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit fb709f0

Please sign in to comment.