本文整理汇总了Java中net.minecraft.tileentity.TileEntity.readFromNBT方法的典型用法代码示例。如果您正苦于以下问题:Java TileEntity.readFromNBT方法的具体用法?Java TileEntity.readFromNBT怎么用?Java TileEntity.readFromNBT使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.tileentity.TileEntity
的用法示例。
在下文中一共展示了TileEntity.readFromNBT方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: update
import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
public boolean update(boolean force, boolean applyPhysics) {
Block block = getBlock();
if (block.getType() != getType()) {
if (force) {
block.setTypeId(getTypeId(), applyPhysics);
} else {
return false;
}
}
block.setData(getRawData(), applyPhysics);
world.getHandle().markBlockForUpdate(x, y, z);
// Cauldron start - restore TE data from snapshot
if (nbt != null)
{
TileEntity te = world.getHandle().getTileEntity(x, y, z);
if (te != null)
{
te.readFromNBT(nbt);
}
}
// Cauldron end
return true;
}
示例2: handleUpdateTileEntity
import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
/**
* Updates the NBTTagCompound metadata of instances of the following entitytypes: Mob spawners, command blocks,
* beacons, skulls, flowerpot
*/
public void handleUpdateTileEntity(S35PacketUpdateTileEntity packetIn)
{
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController);
if (this.gameController.theWorld.isBlockLoaded(packetIn.getPos()))
{
TileEntity tileentity = this.gameController.theWorld.getTileEntity(packetIn.getPos());
int i = packetIn.getTileEntityType();
if (i == 1 && tileentity instanceof TileEntityMobSpawner || i == 2 && tileentity instanceof TileEntityCommandBlock || i == 3 && tileentity instanceof TileEntityBeacon || i == 4 && tileentity instanceof TileEntitySkull || i == 5 && tileentity instanceof TileEntityFlowerPot || i == 6 && tileentity instanceof TileEntityBanner)
{
tileentity.readFromNBT(packetIn.getNbtCompound());
}
}
}
示例3: handleUpdateTileEntity
import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
/**
* Updates the NBTTagCompound metadata of instances of the following entitytypes: Mob spawners, command blocks,
* beacons, skulls, flowerpot
*/
public void handleUpdateTileEntity(SPacketUpdateTileEntity packetIn)
{
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController);
if (this.gameController.world.isBlockLoaded(packetIn.getPos()))
{
TileEntity tileentity = this.gameController.world.getTileEntity(packetIn.getPos());
int i = packetIn.getTileEntityType();
boolean flag = i == 2 && tileentity instanceof TileEntityCommandBlock;
if (i == 1 && tileentity instanceof TileEntityMobSpawner || flag || i == 3 && tileentity instanceof TileEntityBeacon || i == 4 && tileentity instanceof TileEntitySkull || i == 5 && tileentity instanceof TileEntityFlowerPot || i == 6 && tileentity instanceof TileEntityBanner || i == 7 && tileentity instanceof TileEntityStructure || i == 8 && tileentity instanceof TileEntityEndGateway || i == 9 && tileentity instanceof TileEntitySign || i == 10 && tileentity instanceof TileEntityShulkerBox)
{
tileentity.readFromNBT(packetIn.getNbtCompound());
}
if (flag && this.gameController.currentScreen instanceof GuiCommandBlock)
{
((GuiCommandBlock)this.gameController.currentScreen).updateGui();
}
}
}
示例4: onHackFinished
import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
@Override
public void onHackFinished(World world, BlockPos pos, EntityPlayer player) {
if (!world.isRemote) {
NBTTagCompound tag = new NBTTagCompound();
TileEntity te = world.getTileEntity(pos);
if (te != null) {
te.writeToNBT(tag);
tag.setShort("RequiredPlayerRange", (short) 0);
te.readFromNBT(tag);
IBlockState state = world.getBlockState(pos);
world.notifyBlockUpdate(pos, state, state, 3);
}
}
}
示例5: handleClientSide
import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
@Override
public void handleClientSide(PacketSendNBTPacket message, EntityPlayer player) {
TileEntity te = message.getTileEntity(player.getEntityWorld());
if (te != null) {
try {
te.readFromNBT(message.tag);
} catch (Throwable e) {
BlockTrackEntryInventory.addTileEntityToBlackList(te, e);
}
}
}
示例6: tryRecoverTileState
import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
@net.minecraftforge.fml.common.Optional.Method(modid = "ic2")
private static Tuple<IBlockState, TileEntity> tryRecoverTileState(IBlockState state, @Nonnull NBTTagCompound matchTag, BlockArray.TileInstantiateContext context) {
if(getTeClassIc2 == null || getITeBlockIc2 == null || getTeBlockState == null
|| getITEgetSupportedFacings == null || facingPropertyField == null) {
return null;
}
ResourceLocation ic2TileBlock = new ResourceLocation("ic2", "te");
if(ic2TileBlock.equals(state.getBlock().getRegistryName())) {
if(matchTag.hasKey("id")) {
ResourceLocation key = new ResourceLocation(matchTag.getString("id"));
if(key.getResourceDomain().equalsIgnoreCase("ic2")) {
String name = key.getResourcePath();
try {
Object o = getITeBlockIc2.invoke(null, name);
Object oClazz = getTeClassIc2.invoke(o);
if(oClazz instanceof Class) {
TileEntity te = (TileEntity) ((Class) oClazz).newInstance();
if(te != null) {
context.apply(te);
te.readFromNBT(matchTag);
IBlockState st = (IBlockState) getTeBlockState.invoke(te);
EnumFacing applicable = Iterables.getFirst((Collection<EnumFacing>) getITEgetSupportedFacings.invoke(o), EnumFacing.NORTH);
st = st.withProperty(facingPropertyField, applicable);
return new Tuple<>(st, te);
}
}
} catch (Throwable tr) {
tr.printStackTrace();
}
}
}
}
return null;
}
示例7: handleUpdateTileEntity
import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
/**
* Updates the NBTTagCompound metadata of instances of the following entitytypes: Mob spawners, command blocks,
* beacons, skulls, flowerpot
*/
public void handleUpdateTileEntity(SPacketUpdateTileEntity packetIn)
{
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController);
if (this.gameController.theWorld.isBlockLoaded(packetIn.getPos()))
{
TileEntity tileentity = this.gameController.theWorld.getTileEntity(packetIn.getPos());
int i = packetIn.getTileEntityType();
boolean flag = i == 2 && tileentity instanceof TileEntityCommandBlock;
if (i == 1 && tileentity instanceof TileEntityMobSpawner || flag || i == 3 && tileentity instanceof TileEntityBeacon || i == 4 && tileentity instanceof TileEntitySkull || i == 5 && tileentity instanceof TileEntityFlowerPot || i == 6 && tileentity instanceof TileEntityBanner || i == 7 && tileentity instanceof TileEntityStructure || i == 8 && tileentity instanceof TileEntityEndGateway || i == 9 && tileentity instanceof TileEntitySign)
{
tileentity.readFromNBT(packetIn.getNbtCompound());
}
else
{
if(tileentity == null)
{
LOGGER.error("Received invalid update packet for null tile entity at {} with data: {}", packetIn.getPos(), packetIn.getNbtCompound());
return;
}
tileentity.onDataPacket(netManager, packetIn);
}
if (flag && this.gameController.currentScreen instanceof GuiCommandBlock)
{
((GuiCommandBlock)this.gameController.currentScreen).updateGui();
}
}
}
示例8: handleChunkData
import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
/**
* Updates the specified chunk with the supplied data, marks it for re-rendering and lighting recalculation
*/
public void handleChunkData(SPacketChunkData packetIn)
{
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController);
if (packetIn.doChunkLoad())
{
this.clientWorldController.doPreChunk(packetIn.getChunkX(), packetIn.getChunkZ(), true);
}
this.clientWorldController.invalidateBlockReceiveRegion(packetIn.getChunkX() << 4, 0, packetIn.getChunkZ() << 4, (packetIn.getChunkX() << 4) + 15, 256, (packetIn.getChunkZ() << 4) + 15);
Chunk chunk = this.clientWorldController.getChunkFromChunkCoords(packetIn.getChunkX(), packetIn.getChunkZ());
chunk.fillChunk(packetIn.getReadBuffer(), packetIn.getExtractedSize(), packetIn.doChunkLoad());
this.clientWorldController.markBlockRangeForRenderUpdate(packetIn.getChunkX() << 4, 0, packetIn.getChunkZ() << 4, (packetIn.getChunkX() << 4) + 15, 256, (packetIn.getChunkZ() << 4) + 15);
if (!packetIn.doChunkLoad() || !(this.clientWorldController.provider instanceof WorldProviderSurface))
{
chunk.resetRelightChecks();
}
for (NBTTagCompound nbttagcompound : packetIn.getTileEntityTags())
{
BlockPos blockpos = new BlockPos(nbttagcompound.getInteger("x"), nbttagcompound.getInteger("y"), nbttagcompound.getInteger("z"));
TileEntity tileentity = this.clientWorldController.getTileEntity(blockpos);
if (tileentity != null)
{
tileentity.readFromNBT(nbttagcompound);
}
}
}
示例9: restoreToLocation
import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
public boolean restoreToLocation(World world, BlockPos pos, boolean force, boolean applyPhysics)
{
IBlockState current = getCurrentBlock();
IBlockState replaced = getReplacedBlock();
if (current.getBlock() != replaced.getBlock() || current.getBlock().getMetaFromState(current) != replaced.getBlock().getMetaFromState(replaced))
{
if (force)
{
world.setBlockState(pos, replaced, applyPhysics ? 3 : 2);
}
else
{
return false;
}
}
world.setBlockState(pos, replaced, applyPhysics ? 3 : 2);
world.notifyBlockUpdate(pos, current, replaced, applyPhysics ? 3 : 2);
TileEntity te = null;
if (getNbt() != null)
{
te = world.getTileEntity(pos);
if (te != null)
{
te.readFromNBT(getNbt());
te.markDirty();
}
}
if (DEBUG)
{
System.out.printf("Restored BlockSnapshot with data [World: %s ][Location: %d,%d,%d ][Meta: %d ][Block: %s ][TileEntity: %s ][force: %s ][applyPhysics: %s]", world.getWorldInfo().getWorldName(), pos.getX(), pos.getY(), pos.getZ(), replaced.getBlock().getMetaFromState(replaced), replaced.getBlock().delegate.name(), te, force, applyPhysics);
}
return true;
}
示例10: restore
import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
public boolean restore(boolean force, boolean applyPhysics)
{
IBlockState current = getCurrentBlock();
IBlockState replaced = getReplacedBlock();
if (current.getBlock() != replaced.getBlock() || current.getBlock().getMetaFromState(current) != replaced.getBlock().getMetaFromState(replaced))
{
if (force)
{
getWorld().setBlockState(getPos(), replaced, applyPhysics ? 3 : 2);
}
else
{
return false;
}
}
getWorld().setBlockState(getPos(), replaced, applyPhysics ? 3 : 2);
getWorld().notifyBlockUpdate(getPos(), current, replaced, applyPhysics ? 3 : 2);
TileEntity te = null;
if (getNbt() != null)
{
te = getWorld().getTileEntity(getPos());
if (te != null)
{
te.readFromNBT(getNbt());
te.markDirty();
}
}
if (DEBUG)
{
System.out.printf("Restored BlockSnapshot with data [World: %s ][Location: %d,%d,%d ][Meta: %d ][Block: %s ][TileEntity: %s ][force: %s ][applyPhysics: %s]", getWorld().getWorldInfo().getWorldName(), getPos().getX(), getPos().getY(), getPos().getZ(), replaced.getBlock().getMetaFromState(replaced), replaced.getBlock().delegate.name(), te, force, applyPhysics);
}
return true;
}
示例11: 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;
}
}
示例12: setTileEntityNBT
import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
public static boolean setTileEntityNBT(World worldIn, EntityPlayer pos, BlockPos stack, ItemStack p_179224_3_)
{
MinecraftServer minecraftserver = MinecraftServer.getServer();
if (minecraftserver == null)
{
return false;
}
else
{
if (p_179224_3_.hasTagCompound() && p_179224_3_.getTagCompound().hasKey("BlockEntityTag", 10))
{
TileEntity tileentity = worldIn.getTileEntity(stack);
if (tileentity != null)
{
if (!worldIn.isRemote && tileentity.func_183000_F() && !minecraftserver.getConfigurationManager().canSendCommands(pos.getGameProfile()))
{
return false;
}
NBTTagCompound nbttagcompound = new NBTTagCompound();
NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttagcompound.copy();
tileentity.writeToNBT(nbttagcompound);
NBTTagCompound nbttagcompound2 = (NBTTagCompound)p_179224_3_.getTagCompound().getTag("BlockEntityTag");
nbttagcompound.merge(nbttagcompound2);
nbttagcompound.setInteger("x", stack.getX());
nbttagcompound.setInteger("y", stack.getY());
nbttagcompound.setInteger("z", stack.getZ());
if (!nbttagcompound.equals(nbttagcompound1))
{
tileentity.readFromNBT(nbttagcompound);
tileentity.markDirty();
return true;
}
}
}
return false;
}
}
示例13: execute
import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
/**
* Callback for when the command is executed
*/
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
if (args.length < 4)
{
throw new WrongUsageException("commands.blockdata.usage", new Object[0]);
}
else
{
sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 0);
BlockPos blockpos = parseBlockPos(sender, args, 0, false);
World world = sender.getEntityWorld();
if (!world.isBlockLoaded(blockpos))
{
throw new CommandException("commands.blockdata.outOfWorld", new Object[0]);
}
else
{
IBlockState iblockstate = world.getBlockState(blockpos);
TileEntity tileentity = world.getTileEntity(blockpos);
if (tileentity == null)
{
throw new CommandException("commands.blockdata.notValid", new Object[0]);
}
else
{
NBTTagCompound nbttagcompound = tileentity.writeToNBT(new NBTTagCompound());
NBTTagCompound nbttagcompound1 = nbttagcompound.copy();
NBTTagCompound nbttagcompound2;
try
{
nbttagcompound2 = JsonToNBT.getTagFromJson(getChatComponentFromNthArg(sender, args, 3).getUnformattedText());
}
catch (NBTException nbtexception)
{
throw new CommandException("commands.blockdata.tagError", new Object[] {nbtexception.getMessage()});
}
nbttagcompound.merge(nbttagcompound2);
nbttagcompound.setInteger("x", blockpos.getX());
nbttagcompound.setInteger("y", blockpos.getY());
nbttagcompound.setInteger("z", blockpos.getZ());
if (nbttagcompound.equals(nbttagcompound1))
{
throw new CommandException("commands.blockdata.failed", new Object[] {nbttagcompound.toString()});
}
else
{
tileentity.readFromNBT(nbttagcompound);
tileentity.markDirty();
world.notifyBlockUpdate(blockpos, iblockstate, iblockstate, 3);
sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 1);
notifyCommandListener(sender, this, "commands.blockdata.success", new Object[] {nbttagcompound.toString()});
}
}
}
}
}
示例14: processCommand
import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
/**
* Callback when the command is invoked
*/
public void processCommand(ICommandSender sender, String[] args) throws CommandException
{
if (args.length < 4)
{
throw new WrongUsageException("commands.blockdata.usage", new Object[0]);
}
else
{
sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 0);
BlockPos blockpos = parseBlockPos(sender, args, 0, false);
World world = sender.getEntityWorld();
if (!world.isBlockLoaded(blockpos))
{
throw new CommandException("commands.blockdata.outOfWorld", new Object[0]);
}
else
{
TileEntity tileentity = world.getTileEntity(blockpos);
if (tileentity == null)
{
throw new CommandException("commands.blockdata.notValid", new Object[0]);
}
else
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
tileentity.writeToNBT(nbttagcompound);
NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttagcompound.copy();
NBTTagCompound nbttagcompound2;
try
{
nbttagcompound2 = JsonToNBT.getTagFromJson(getChatComponentFromNthArg(sender, args, 3).getUnformattedText());
}
catch (NBTException nbtexception)
{
throw new CommandException("commands.blockdata.tagError", new Object[] {nbtexception.getMessage()});
}
nbttagcompound.merge(nbttagcompound2);
nbttagcompound.setInteger("x", blockpos.getX());
nbttagcompound.setInteger("y", blockpos.getY());
nbttagcompound.setInteger("z", blockpos.getZ());
if (nbttagcompound.equals(nbttagcompound1))
{
throw new CommandException("commands.blockdata.failed", new Object[] {nbttagcompound.toString()});
}
else
{
tileentity.readFromNBT(nbttagcompound);
tileentity.markDirty();
world.markBlockForUpdate(blockpos);
sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 1);
notifyOperators(sender, this, "commands.blockdata.success", new Object[] {nbttagcompound.toString()});
}
}
}
}
}
示例15: tick
import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
@SubscribeEvent
public void tick(WorldTickEvent event) {
if (event.side != Side.SERVER || event.phase != Phase.END || isReplacing)
return;
if (replacements == null) {
replacements = new HashMap<Block, Block>();
if (EtFuturum.enableBrewingStands)
replacements.put(Blocks.brewing_stand, ModBlocks.brewing_stand);
if (EtFuturum.enableColourfulBeacons)
replacements.put(Blocks.beacon, ModBlocks.beacon);
if (EtFuturum.enableEnchants)
replacements.put(Blocks.enchanting_table, ModBlocks.enchantment_table);
if (EtFuturum.enableInvertedDaylightSensor)
replacements.put(Blocks.daylight_detector, ModBlocks.daylight_sensor);
}
if (replacements.isEmpty())
return;
isReplacing = true;
World world = event.world;
for (int i = 0; i < world.loadedTileEntityList.size(); i++) {
TileEntity tile = (TileEntity) world.loadedTileEntityList.get(i);
int x = tile.xCoord;
int y = tile.yCoord;
int z = tile.zCoord;
Block replacement = replacements.get(world.getBlock(x, y, z));
if (replacement != null && ((IConfigurable) replacement).isEnabled()) {
NBTTagCompound nbt = new NBTTagCompound();
tile.writeToNBT(nbt);
if (tile instanceof IInventory) {
IInventory invt = (IInventory) tile;
for (int j = 0; j < invt.getSizeInventory(); j++)
invt.setInventorySlotContents(j, null);
}
world.setBlock(x, y, z, replacement);
TileEntity newTile = world.getTileEntity(x, y, z);
newTile.readFromNBT(nbt);
break;
}
}
isReplacing = false;
}