YZL314159265
1.12FORGE,出于一些限制有时需要在服务端往玩家背包里塞个物品(addItemStackToInventory)或者玩家掉落个物品(dropItem),这时应该需要往客户端发包是吧。。具体该怎么操作呢?托腮.PNG

清晨w
直接addItemStackToInventory
然后player.inventoryContainer.detectAndSendChanges()
Minecraft会自动同步的
可以参考net.minecraft.command.CommandGive

YZL314159265
清晨w 发表于 2020-1-20 18:22
直接addItemStackToInventory
然后player.inventoryContainer.detectAndSendChanges()
Minecraft会自动同步 ...

if((world.isRemote)&&(!player.capabilities.isCreativeMode)){
            player.inventory.addItemStackToInventory(new ItemStack(JAVELIN, 1, 0));
            player.inventoryContainer.detectAndSendChanges();
}

这样子和原来还是一样,游戏里获得的只是一个没有效果的虚假物体,一旦移动背包位置或者使用就会直接消失,

清晨w
为什么要判断world.isRemote呢
添加物品应该在服务端进行
world.isRemote == true是指客户端,当然没有效果
/**
     * True if the world is a 'slave' client; changes will not be saved or propagated from this world. For example,
     * server worlds have this set to false, client worlds have this set to true.
     */
public final boolean isRemote;

YZL314159265
清晨w 发表于 2020-1-20 22:21
为什么要判断world.isRemote呢
添加物品应该在服务端进行
world.isRemote == true是指客户端,当然没有效果

?,,,remote是远程的意思,所以我一直认为isRemete是服务端。。

第一页 上一页 下一页 最后一页