mirror of
https://github.com/GTNewHorizons/Baubles-Expanded.git
synced 2026-11-20 12:09:59 +00:00
fix item loss an packet sync issues
This commit is contained in:
1 parent
b78437bec8
commit
d55863ba2a
6 files changed
+23
-16
No files matched your search
@@ -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;
|
||||
|
||||
@@ -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<EntityItem> 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(); }
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user