diff --git a/build.gradle b/build.gradle index d908f74..d041d1b 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ buildscript { apply plugin: 'forge' -version = "1.7.2-1.0.0.13" +version = "1.7.2-1.0.0.14" 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 cb8916d..da831f3 100644 --- a/src/main/java/baubles/common/Baubles.java +++ b/src/main/java/baubles/common/Baubles.java @@ -26,7 +26,7 @@ public class Baubles { public static final String MODID = "Baubles"; public static final String MODNAME = "Baubles"; - public static final String VERSION = "1.0.0.13"; + public static final String VERSION = "1.0.0.14"; @SidedProxy(clientSide = "baubles.client.ClientProxy", serverSide = "baubles.common.CommonProxy") public static CommonProxy proxy; diff --git a/src/main/java/baubles/common/container/InventoryBaubles.java b/src/main/java/baubles/common/container/InventoryBaubles.java index 3d6e9e5..def77df 100644 --- a/src/main/java/baubles/common/container/InventoryBaubles.java +++ b/src/main/java/baubles/common/container/InventoryBaubles.java @@ -1,14 +1,16 @@ package baubles.common.container; import java.lang.ref.WeakReference; +import java.util.ArrayList; +import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.MathHelper; import baubles.api.BaubleType; import baubles.api.IBauble; import baubles.common.Baubles; @@ -230,10 +232,17 @@ public class InventoryBaubles implements IInventory { } } - public void dropItems(EntityPlayer player) { + public void dropItems(ArrayList drops) { for (int i = 0; i < 4; ++i) { if (this.stackList[i] != null) { - player.dropPlayerItemWithRandomChoice(this.stackList[i], true); + EntityItem ei = new EntityItem(player.get().worldObj, player.get().posX,player.get().posY+player.get().eyeHeight,player.get().posZ,this.stackList[i].copy()); + ei.delayBeforeCanPickup = 40; + float f1 = player.get().worldObj.rand.nextFloat() * 0.5F; + float f2 = player.get().worldObj.rand.nextFloat() * (float)Math.PI * 2.0F; + ei.motionX = (double)(-MathHelper.sin(f2) * f1); + ei.motionZ = (double)(MathHelper.cos(f2) * f1); + ei.motionY = 0.20000000298023224D; + drops.add(ei); this.stackList[i] = null; syncSlotToClients(i); } @@ -242,8 +251,9 @@ public class InventoryBaubles implements IInventory { public void syncSlotToClients(int slot) { try { - if (Baubles.proxy.getClientWorld()==null) + if (Baubles.proxy.getClientWorld()==null) { Baubles.packetPipeline.sendToAll(new PacketSyncBauble(player.get(),slot)); + } } catch (Exception e) { e.printStackTrace(); } } } diff --git a/src/main/java/baubles/common/event/EventHandlerEntity.java b/src/main/java/baubles/common/event/EventHandlerEntity.java index 44ae5cb..c84cd71 100644 --- a/src/main/java/baubles/common/event/EventHandlerEntity.java +++ b/src/main/java/baubles/common/event/EventHandlerEntity.java @@ -31,9 +31,9 @@ public class EventHandlerEntity { @SubscribeEvent public void playerDeath(PlayerDropsEvent event) { if (event.entity instanceof EntityPlayer && !event.entity.worldObj.isRemote && !event.entity.worldObj.getGameRules().getGameRuleBooleanValue("keepInventory")) { - EntityPlayer player = (EntityPlayer)event.entity; - PlayerHandler.getPlayerBaubles(player).dropItems(player); + PlayerHandler.getPlayerBaubles(event.entityPlayer).dropItems(event.drops); } + } diff --git a/src/main/java/baubles/common/network/PacketSyncBauble.java b/src/main/java/baubles/common/network/PacketSyncBauble.java index dcf906e..27258de 100644 --- a/src/main/java/baubles/common/network/PacketSyncBauble.java +++ b/src/main/java/baubles/common/network/PacketSyncBauble.java @@ -10,13 +10,12 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.network.PacketBuffer; import net.minecraft.world.World; -import net.minecraftforge.common.DimensionManager; import baubles.common.lib.PlayerHandler; public class PacketSyncBauble extends AbstractPacket { int slot; - int dim, playerId; + int playerId; ItemStack bauble=null; public PacketSyncBauble() {} @@ -25,14 +24,12 @@ public class PacketSyncBauble extends AbstractPacket { this.slot = slot; this.bauble = PlayerHandler.getPlayerBaubles(player).getStackInSlot(slot); this.playerId = player.getEntityId(); - this.dim = player.dimension; } @Override public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) { buffer.writeByte(slot); buffer.writeInt(playerId); - buffer.writeInt(dim); PacketBuffer pb = new PacketBuffer(buffer); try { pb.writeItemStackToBuffer(bauble); } catch (IOException e) {} } @@ -42,18 +39,15 @@ public class PacketSyncBauble extends AbstractPacket { { slot = buffer.readByte(); playerId = buffer.readInt(); - dim = buffer.readInt(); PacketBuffer pb = new PacketBuffer(buffer); try { bauble = pb.readItemStackFromBuffer(); } catch (IOException e) {} } @Override public void handleClientSide(EntityPlayer player) { - World world = DimensionManager.getWorld(dim); + World world = player.worldObj; if (world==null) return; - Entity p = world.getEntityByID(playerId); - if (p !=null && p instanceof EntityPlayer) { PlayerHandler.getPlayerBaubles((EntityPlayer) p).stackList[slot]=bauble; } diff --git a/src/main/resources/changelog.txt b/src/main/resources/changelog.txt index 59aff10..a533b8c 100644 --- a/src/main/resources/changelog.txt +++ b/src/main/resources/changelog.txt @@ -1,3 +1,6 @@ +1.0.0.14 +- prevent loss of non-baubles items on death + 1.0.0.13 - properly clear player baubles inventory before he enters the world and reset file pointers - only attempt to load or save baubles server-side