本文整理匯總了Java中net.minecraft.tileentity.TileEntity.onlyOpsCanSetNbt方法的典型用法代碼示例。如果您正苦於以下問題:Java TileEntity.onlyOpsCanSetNbt方法的具體用法?Java TileEntity.onlyOpsCanSetNbt怎麽用?Java TileEntity.onlyOpsCanSetNbt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.minecraft.tileentity.TileEntity
的用法示例。
在下文中一共展示了TileEntity.onlyOpsCanSetNbt方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setTileEntityNBT
import net.minecraft.tileentity.TileEntity; //導入方法依賴的package包/類
public static boolean setTileEntityNBT(World worldIn, @Nullable EntityPlayer player, BlockPos pos, ItemStack stackIn)
{
MinecraftServer minecraftserver = worldIn.getMinecraftServer();
if (minecraftserver == null)
{
return false;
}
else
{
NBTTagCompound nbttagcompound = stackIn.getSubCompound("BlockEntityTag");
if (nbttagcompound != null)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity != null)
{
if (!worldIn.isRemote && tileentity.onlyOpsCanSetNbt() && (player == null || !player.canUseCommandBlock()))
{
return false;
}
NBTTagCompound nbttagcompound1 = tileentity.writeToNBT(new NBTTagCompound());
NBTTagCompound nbttagcompound2 = nbttagcompound1.copy();
nbttagcompound1.merge(nbttagcompound);
nbttagcompound1.setInteger("x", pos.getX());
nbttagcompound1.setInteger("y", pos.getY());
nbttagcompound1.setInteger("z", pos.getZ());
if (!nbttagcompound1.equals(nbttagcompound2))
{
tileentity.readFromNBT(nbttagcompound1);
tileentity.markDirty();
return true;
}
}
}
return false;
}
}
示例2: setTileEntityNBT
import net.minecraft.tileentity.TileEntity; //導入方法依賴的package包/類
public static boolean setTileEntityNBT(World worldIn, @Nullable EntityPlayer player, BlockPos pos, ItemStack stackIn)
{
MinecraftServer minecraftserver = worldIn.getMinecraftServer();
if (minecraftserver == null)
{
return false;
}
else
{
if (stackIn.hasTagCompound() && stackIn.getTagCompound().hasKey("BlockEntityTag", 10))
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity != null)
{
if (!worldIn.isRemote && tileentity.onlyOpsCanSetNbt() && (player == null || !player.canUseCommandBlock()))
{
return false;
}
NBTTagCompound nbttagcompound = tileentity.writeToNBT(new NBTTagCompound());
NBTTagCompound nbttagcompound1 = nbttagcompound.copy();
NBTTagCompound nbttagcompound2 = (NBTTagCompound)stackIn.getTagCompound().getTag("BlockEntityTag");
nbttagcompound.merge(nbttagcompound2);
nbttagcompound.setInteger("x", pos.getX());
nbttagcompound.setInteger("y", pos.getY());
nbttagcompound.setInteger("z", pos.getZ());
if (!nbttagcompound.equals(nbttagcompound1))
{
tileentity.readFromNBT(nbttagcompound);
tileentity.markDirty();
return true;
}
}
}
return false;
}
}