下面列出了org.bukkit.block.banner.Pattern#net.minecraft.nbt.NBTTagCompound 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public String getName() {
Player player = getPlayer();
if (player != null) {
return player.getName();
}
// This might not match lastKnownName but if not it should be more correct
if (profile.getName() != null) {
return profile.getName();
}
NBTTagCompound data = getBukkitData();
if (data != null) {
if (data.hasKey("lastKnownName")) {
return data.getString("lastKnownName");
}
}
return null;
}
@Override
public void readFromNBT(NBTTagCompound tag) {
super.readFromNBT(tag);
// Rotation
if(tag.hasKey("facing")) {
facing = Math.max(0, Math.min(5, tag.getInteger("facing")));
}
else {
facing = 2;
}
// Exposure settings
if(tag.hasKey("exposures")) {
int[] tagExposures = tag.getIntArray("exposures");
assert(tagExposures.length == exposures.length);
System.arraycopy(tagExposures, 0, exposures, 0, exposures.length);
}
}
@Override
public void setWorld(World world) {
net.minecraft.world.World oldWorld = (net.minecraft.world.World) WorldConverter.instance().toNative(this.world);
net.minecraft.world.World newWorld = (net.minecraft.world.World) WorldConverter.instance().toNative(world);
Optional<TileEntity> tileEntity = Optional.ofNullable(oldWorld.getTileEntity((int) position.getX(), (int) position.getY(), (int) position.getZ()));
Optional<NBTTagCompound> nbt = Optional.empty();
if (tileEntity.isPresent()) {
NBTTagCompound compound = new NBTTagCompound();
tileEntity.get().writeToNBT(compound);
nbt = Optional.of(compound);
}
newWorld.setBlock((int) position.getX(), (int) position.getY(), (int) position.getZ(), block.mcBlock, block.getMetadata(), 3);
oldWorld.removeTileEntity((int) position.getX(), (int) position.getY(), (int) position.getZ());
oldWorld.setBlockToAir((int) position.getX(), (int) position.getY(), (int) position.getZ());
Optional<TileEntity> newTileEntity = Optional.ofNullable(newWorld.getTileEntity((int) position.getX(), (int) position.getY(), (int) position.getZ()));
if (newTileEntity.isPresent() && nbt.isPresent()) {
newTileEntity.get().readFromNBT(nbt.get());
}
this.world = world;
}
/**
* returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
*/
@SideOnly(Side.CLIENT)
@Override
public void getSubItems(@Nonnull Item item, @Nonnull CreativeTabs creativeTabs, @Nonnull List<ItemStack> list) {
super.getSubItems(item, creativeTabs, list);
ItemStack itemStack;
NBTTagCompound nbt;
itemStack = PLBlocks.evsu.copy();
nbt = StackUtil.getOrCreateNbtData(itemStack);
nbt.setInteger("energy", (int) 1E8);
list.add(itemStack);
itemStack = PLBlocks.cseu.copy();
nbt = StackUtil.getOrCreateNbtData(itemStack);
nbt.setInteger("energy", (int) 720E3);
list.add(itemStack);
itemStack = PLBlocks.parallelSpaceSU.copy();
nbt = StackUtil.getOrCreateNbtData(itemStack);
nbt.setInteger("energy", (int) 2E8);
list.add(itemStack);
}
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List infoList, boolean par4){
super.addInformation(stack, player, infoList, par4);
NBTTagCompound compound = stack.stackTagCompound;
if(compound != null) {
int x = compound.getInteger("x");
int y = compound.getInteger("y");
int z = compound.getInteger("z");
if(x != 0 || y != 0 || z != 0) {
infoList.add("\u00a72Set to " + x + ", " + y + ", " + z);
}
String varName = getVariable(stack);
if(!varName.equals("")) {
infoList.add(I18n.format("gui.tooltip.gpsTool.variable", varName));
}
}
}
@SubscribeEvent
public void startTrackingEvent(StartTracking event)
{
EntityPlayer tracker = event.getEntityPlayer();
Entity target = event.getTarget();
if (!target.worldObj.isRemote)
{
if (CyberwareAPI.hasCapability(target))
{
if (target instanceof EntityPlayer)
{
//System.out.println("Sent data for player " + ((EntityPlayer) target).getName() + " to player " + tracker.getName());
}
NBTTagCompound nbt = CyberwareAPI.getCapability(target).serializeNBT();
CyberwarePacketHandler.INSTANCE.sendTo(new CyberwareSyncPacket(nbt, target.getEntityId()), (EntityPlayerMP) tracker);
}
}
}
public NBTTagCompound writeToNBT() {
NBTTagCompound tag = new NBTTagCompound();
Triple<Double, Double, Double> pos = getPosition();
tag.setDouble("posX", pos.getFirst());
tag.setDouble("posY", pos.getSecnd());
tag.setDouble("posZ", pos.getThird());
tag.setInteger("heading", heading.ordinal());
tag.setUniqueId("UID", this.ID);
tag.setTag("inventory", stack.serializeNBT());
tag.setInteger("ticks", this.ticks);
NBTTagList routeList = new NBTTagList();
for(EnumFacing node : route) {
NBTTagCompound nodeTag = new NBTTagCompound();
//nodeTag.setUniqueId("UID", node.getKey());
nodeTag.setInteger("heading", node.ordinal());
routeList.appendTag(nodeTag);
}
tag.setTag("route", routeList);
return tag;
}
@Override
public void readEntityFromNBT(NBTTagCompound nbttagcompound)
{
super.readEntityFromNBT(nbttagcompound);
setRideable(nbttagcompound.getBoolean("Saddle"));
setIsChested(nbttagcompound.getBoolean("Chested"));
setArmorType(nbttagcompound.getByte("ArmorType"));
setSitting(nbttagcompound.getBoolean("isSitting"));
if (getIsChested())
{
NBTTagList nbttaglist = nbttagcompound.getTagList("Items");
localchest = new MoCAnimalChest("WyvernChest", 14);
for (int i = 0; i < nbttaglist.tagCount(); i++)
{
NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.tagAt(i);
int j = nbttagcompound1.getByte("Slot") & 0xff;
if ((j >= 0) && j < localchest.getSizeInventory())
{
localchest.setInventorySlotContents(j, ItemStack.loadItemStackFromNBT(nbttagcompound1));
}
}
}
}
@Override
public Object getMeta(Item target, ItemStack stack) {
Map<String, Object> result = Maps.newHashMap();
String type = safariNets.get(target.getUnlocalizedName());
result.put("type", Objects.firstNonNull(type, "unknown"));
NBTTagCompound tag = stack.getTagCompound();
if (tag != null) {
if (tag.getBoolean("hide")) {
result.put("captured", "?");
} else if (tag.hasKey("id", Constants.NBT.TAG_STRING)) {
result.put("captured", tag.getString("id"));
}
}
return result;
}
@Override
public NBTTagCompound serializeNBT() {
NBTTagCompound compound = new NBTTagCompound();
compound.setTag("spell_object_manager", spellObjectManager.manager.toNbt());
NBTTagList driveNBT = new NBTTagList();
for (Map.Entry<BlockPos, NemezTracker> entry : blockNemezDrives.entrySet()) {
if (entry == null) continue;
NBTTagCompound compound1 = new NBTTagCompound();
compound1.setLong("pos", entry.getKey().toLong());
compound1.setTag("drive", entry.getValue().serializeNBT());
driveNBT.appendTag(compound1);
}
compound.setTag("drives", driveNBT);
return compound;
}
@Override
public void readFromNBT(NBTTagCompound compound) {
super.readFromNBT(compound);
if (compound.hasKey("type")) {
type = compound.getInteger("type");
}
if (compound.hasKey("facing")) {
facing = EnumFacing.byName(compound.getString("facing"));
}
if (compound.hasKey("open")) {
open = compound.getBoolean("open");
}
if (compound.hasKey("animation")) {
animation = compound.getInteger("animation");
}
}
@Override
public void writeToNBT(NBTTagCompound tag){
super.writeToNBT(tag);
tag.setString("offeringPlayerId", offeringPlayerId);
tag.setString("offeringPlayerName", offeringPlayerName);
tag.setInteger("inStock", inStock);
tag.setInteger("maxTrades", maxTrades);
tag.setInteger("pendingPayments", pendingPayments);
if(providingPosition != null) {
tag.setInteger("providingDimensionId", providingDimensionId);
tag.setInteger("providingX", providingPosition.chunkPosX);
tag.setInteger("providingY", providingPosition.chunkPosY);
tag.setInteger("providingZ", providingPosition.chunkPosZ);
}
if(returningPosition != null) {
tag.setInteger("returningDimensionId", returningDimensionId);
tag.setInteger("returningX", returningPosition.chunkPosX);
tag.setInteger("returningY", returningPosition.chunkPosY);
tag.setInteger("returningZ", returningPosition.chunkPosZ);
}
}
@Override
public void readFromNBT(NBTTagCompound compound) {
super.readFromNBT(compound);
if (compound.hasKey("inputFacing")) {
this.inputFacing = EnumFacing.values()[compound.getByte("inputFacing")];
}
if (compound.hasKey("hasOutput")) {
if (compound.getBoolean("hasOutput")) {
if (compound.hasKey("outputRatio")) {
this.outputRatio = Optional.of(compound.getDouble("outpuRatio"));
}
}
}
}
@Override
public void useNetworkData(EntityPlayer player, Side side, byte id,
NBTTagCompound nbt) {
super.useNetworkData(player, side, id, nbt);
onInventoryButtonPressed(id - 100);
}
@Override
public void readFromNBT(NBTTagCompound compound)
{
super.readFromNBT(compound);
slots.deserializeNBT(compound.getCompoundTag("inv"));
if (compound.hasKey("CustomName", 8))
{
customName = compound.getString("CustomName");
}
this.time = compound.getInteger("time");
lastPlayerArchive = new HashMap<String, BlockPos>();
NBTTagList list = (NBTTagList) compound.getTag("playerArchive");
for (int i = 0; i < list.tagCount(); i++)
{
NBTTagCompound comp = list.getCompoundTagAt(i);
String name = comp.getString("name");
int x = comp.getInteger("x");
int y = comp.getInteger("y");
int z = comp.getInteger("z");
BlockPos pos = new BlockPos(x, y, z);
lastPlayerArchive.put(name, pos);
}
}
@Override
public void writeToNBT(NBTTagCompound tag){
super.writeToNBT(tag);
energy.writeToNBT(tag);
writeInventoryToNBT(tag, inventory);
tag.setInteger("redstoneMode", redstoneMode);
tag.setBoolean("isEnabled", isEnabled);
}
/***********************************************************************************
* 3. NBT Methods
***********************************************************************************/
@Override
public void readSyncableNBT(NBTTagCompound nbt)
{
NBTTagList invList = nbt.getTagList("inventory", 10);
inventory = Helper.readStackArrayFromNBTList(invList, getSizeInventory());
rotation = EnumFacing.Axis.values()[nbt.getInteger("axis")];
}
private void setSelectedFixedBlockType(ItemStack stack, EntityPlayer player, World world, BlockPos pos, boolean secondary)
{
int sel = this.getSelectionIndex(stack, secondary);
if (sel < 0)
{
return;
}
String tagName = secondary ? TAG_NAME_BLOCKS + "2" : TAG_NAME_BLOCKS;
NBTTagCompound blocksTag = NBTUtils.getCompoundTag(stack, WRAPPER_TAG_NAME, tagName, true);
NBTTagCompound tag = NBTUtils.getCompoundTag(blocksTag, TAG_NAME_BLOCK_PRE + sel, true);
this.setSelectedFixedBlockType(tag, player, world, pos);
}
public NBTTagCompound writeToNBT(NBTTagCompound tag)
{
tag.setString("item", Item.REGISTRY.getNameForObject(item).toString());
tag.setInteger("meta", meta);
return tag;
}
/**
* @param stack
* @return Vector3F containing the takeoff coords or null if there is none
*/
public Vector3F<Float> getTakeoffCoords(ItemStack stack, int dimid) {
if(stack.hasTagCompound()) {
NBTTagCompound nbt = stack.getTagCompound();
if(nbt.hasKey("dimid" + dimid)) {
nbt = nbt.getCompoundTag("dimid" + dimid);
return new Vector3F<Float>(nbt.getFloat("x"), nbt.getFloat("y"),nbt.getFloat("z"));
}
}
return null;
}
@Override
public void readFromNBT(NBTTagCompound compound) {
super.readFromNBT(compound);
this.itemHandler.deserializeNBT(compound.getCompoundTag("Inventory"));
this.setWater(compound.getInteger("GuiWater"));
this.setEnergy(compound.getInteger("GuiEnergy"));
this.setProgress(compound.getInteger("GuiProgress"));
this.fluidHandler.readFromNBT(compound);
this.energyHandler.readFromNBT(compound);
}
@Override
public void writeToNBT(NBTTagCompound tag){
super.writeToNBT(tag);
for(int i = 0; i < 6; i++) {
tag.setBoolean(ForgeDirection.getOrientation(i).name(), accessingSides[i]);
}
tag.setBoolean("useCount", useCount);
tag.setInteger("count", count);
}
public void read() throws IOException{
if (file.exists() && file.canRead()){
NBTTagCompound root = CompressedStreamTools.read(file);
for (int i =0; i < 7; ++i){
String name = "slot" + (i+1);
if (root.hasKey(name))
tags[i].tag = root.getCompoundTag(name);
if (root.hasKey(name+"Name"))
tags[i].name = root.getString(name+"Name");
}
}
}
public FluidTank readFromNBT(NBTTagCompound nbt)
{
if (!nbt.hasKey("Empty"))
{
FluidStack fluid = FluidStack.loadFluidStackFromNBT(nbt);
setFluid(fluid);
} else
{
setFluid(null);
}
return this;
}
public void writeToNBT(NBTTagCompound nbttagcompound, String label)
{
NBTTagList tlist = new NBTTagList();
nbttagcompound.setTag(label, tlist);
for (Aspect aspect : getAspects())
if (aspect != null) {
NBTTagCompound f = new NBTTagCompound();
f.setString("key", aspect.getTag());
f.setInteger("amount", getAmount(aspect));
tlist.appendTag(f);
}
}
public static BlockInfo readFromNBT(NBTTagCompound tag)
{
Block item_ = Block.REGISTRY.getObject(new ResourceLocation(tag.getString("block")));
int meta_ = tag.getInteger("meta");
return new BlockInfo(item_, meta_);
}
/**
* Cycle a byte value in the given ItemStack's NBT in a tag <b>tagName</b>. If <b>containerTagName</b>
* is not null, then the value is stored inside a compound tag by that name.
* The low end of the range is 0.
*/
public static void cycleByteValue(@Nonnull ItemStack stack, @Nullable String containerTagName,
@Nonnull String tagName, int maxValue, boolean reverse)
{
NBTTagCompound nbt = getCompoundTag(stack, containerTagName, true);
cycleByteValue(nbt, tagName, 0, maxValue, reverse);
}
@Override
public void readFromNBT(NBTTagCompound compound) {
super.readFromNBT(compound);
this.energyHandler.readFromNBT(compound);
this.setEnergy(compound.getInteger("GuiEnergy"));
}
/**
* (abstract) Helper method to write subclass data to NBT
*/
protected void writeStructureToNBT(NBTTagCompound tagCompound) {
super.writeStructureToNBT(tagCompound);
NBTTagList nbttaglist = new NBTTagList();
for (StructureBoundingBox structureboundingbox : this.connectedRooms) {
nbttaglist.appendTag(structureboundingbox.toNBTTagIntArray());
}
tagCompound.setTag("Entrances", nbttaglist);
}
/**
* Writes a tile entity to NBT.
* @return
*/
@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt)
{
NBTTagCompound compound = super.writeToNBT(nbt);
nbt.setLong("buildseed", this.buildseed);
return compound;
}