本文整理汇总了Java中net.minecraftforge.common.util.Constants.NBT类的典型用法代码示例。如果您正苦于以下问题:Java NBT类的具体用法?Java NBT怎么用?Java NBT使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NBT类属于net.minecraftforge.common.util.Constants包,在下文中一共展示了NBT类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readFromNBT
import net.minecraftforge.common.util.Constants.NBT; //导入依赖的package包/类
@Override
public void readFromNBT(NBTTagCompound compound)
{
super.readFromNBT(compound);
CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.readNBT(mainHandler, null, compound.getTag(INV_TAG));
mode = Mode.valueOf(compound.getString(MODE));
NBTTagList ingredientList = compound.getTagList(PENDING_INGREDIENTS, NBT.TAG_COMPOUND);
pendingIngredients = new Stack<RecipeElement>();
for(int tag = 0; tag < ingredientList.tagCount(); tag++)
{
pendingIngredients.add(ElementRegistry.createElementFromNBT(ingredientList.getCompoundTagAt(tag)));
}
xpLevelsNeeded = compound.getInteger(LEVELS_NEEDED);
xpLevelsTaken = compound.getInteger(LEVELS_TAKEN);
healthTaken = compound.getFloat(HEALTH_TAKEN);
}
示例2: readFromNBT
import net.minecraftforge.common.util.Constants.NBT; //导入依赖的package包/类
@Override
public void readFromNBT(NBTTagCompound compound) {
if (compound.hasKey("RootUser")) {
this.rootUser = compound.getString("RootUser");
}
if (compound.hasKey("Rules")) {
NBTTagList rulesList = compound.getTagList("Rules", NBT.TAG_COMPOUND);
this.rules = new ArrayList<Rule>();
for (int i = 0, max = rulesList.tagCount(); i < max; ++i) {
NBTTagCompound ruleNBT = (NBTTagCompound)rulesList.get(i);
this.rules.add(new Rule(ruleNBT.getString("ID"), ruleNBT.getString("Name"), ruleNBT.getInteger("Mode")));
}
}
if (this.rules == null || this.rules.size() == 0) {
// Reset rules.
this.rules = new ArrayList<Rule>();
this.rules.add(new Rule("<machines>", Rule.MODE_OPEN));
this.rules.add(new Rule("<players>", Rule.MODE_RESTRICTED));
}
super.readFromNBT(compound);
}
示例3: readFromNBT
import net.minecraftforge.common.util.Constants.NBT; //导入依赖的package包/类
@Override
public void readFromNBT(NBTTagCompound compound) {
if (compound.hasKey("Machines")) {
NBTTagList machineList = compound.getTagList("Machines", NBT.TAG_COMPOUND);
this.connectedMachines = new ArrayList<BlockPos>();
for (int i = 0, max = machineList.tagCount(); i < max; ++i) {
NBTTagCompound machineNBT = (NBTTagCompound)machineList.get(i);
this.connectedMachines.add(new BlockPos(machineNBT.getInteger("X"), machineNBT.getInteger("Y"), machineNBT.getInteger("Z")));
}
} else {
this.connectedMachines = null;
}
super.readFromNBT(compound);
}
示例4: readDataNBT
import net.minecraftforge.common.util.Constants.NBT; //导入依赖的package包/类
@Override
protected void readDataNBT(NBTTagCompound tag) {
cooldown = tag.getInteger("cooldown");
if (tag.hasKey("ritual"))
ritual = Ritual.REGISTRY.getValue(new ResourceLocation(tag.getString("ritual")));
if (tag.hasKey("player"))
entityPlayer = UUID.fromString(tag.getString("player"));
if (tag.hasKey("data"))
ritualData = tag.getCompoundTag("data");
if (tag.hasKey("entityList")) {
entityList = new ArrayList<Tuple<String, String>>();
tag.getTagList("entityList", NBT.TAG_STRING).forEach(nbts -> {
String[] names = ((NBTTagString) nbts).getString().split("!");
if (names.length == 2)
entityList.add(new Tuple<String, String>(names[0], names[1]));
});
}
}
示例5: deserializeNBT
import net.minecraftforge.common.util.Constants.NBT; //导入依赖的package包/类
@Override
public void deserializeNBT(NBTTagCompound nbt)
{
this.growthRanges[0].deserializeNBT(nbt.getCompoundTag("tGrowthRangeMinimal"));
this.growthRanges[1].deserializeNBT(nbt.getCompoundTag("tGrowthRangeOptimal"));
this.growthRanges[2].deserializeNBT(nbt.getCompoundTag("tGrowthRangePerfect"));
this.humidityGrowthRange = Pair.of(nbt.getCompoundTag("hGrowthRange").getFloat("min"), nbt.getCompoundTag("hGrowthRange").getFloat("max"));
this.generation = nbt.getInteger("generation");
this.wild = nbt.getBoolean("wild");
this.type = EnumCrop.values()[nbt.getByte("type")];
this.plantedAt = new Calendar();
if (nbt.hasKey("plantedAt"))
{
this.plantedAt.deserializeNBT((NBTTagLong) nbt.getTag("plantedAt"));
}
this.health = nbt.getFloat("health");
this.growthRate = nbt.getFloat("growthRate");
this.waterConsumption = nbt.getFloat("waterConsumption");
this.growth = nbt.getFloat("growth");
this.nutrientConsumption.clear();
nbt.getTagList("nutrientConsumption", NBT.TAG_COMPOUND).forEach(tag -> this.nutrientConsumption.put(EnumPlantNutrient.values()[((NBTTagCompound)tag).getByte("nutrient")], ((NBTTagCompound)tag).getFloat("amount")));
}
示例6: handleStatusUpdate
import net.minecraftforge.common.util.Constants.NBT; //导入依赖的package包/类
@Patch.Exception
@Hook("net.minecraft.entity.item.EntityFireworkRocket#func_70103_a")
public static Hook.Result handleStatusUpdate(EntityFireworkRocket rocket, byte id) {
if (id == 17 && rocket.world.isRemote) {
ItemStack item = rocket.getDataManager().get(EntityFireworkRocket.FIREWORK_ITEM);
NBTTagCompound nbt = null;
if (item != null && item.hasTagCompound()) {
nbt = item.getTagCompound().getCompoundTag("Fireworks");
if (item.getTagCompound().hasKey("display", NBT.TAG_COMPOUND))
nbt.setTag("display", item.getTagCompound().getTag("display"));
}
rocket.world.makeFireworks(rocket.posX, rocket.posY, rocket.posZ, rocket.motionX, rocket.motionY, rocket.motionZ, nbt);
}
return Hook.Result.NULL;
}
示例7: deserializeNBT
import net.minecraftforge.common.util.Constants.NBT; //导入依赖的package包/类
@Override
public void deserializeNBT(NBTBase nbtb) {
if (nbtb instanceof NBTTagList) {
NBTTagList nbtl = (NBTTagList) nbtb;
for (int i = 0; i < nbtl.tagCount(); i++) {
NBTTagCompound nbt = nbtl.getCompoundTagAt(i);
boolean hasPos = false;
long l = 0;
if (nbt.hasKey("x", NBT.TAG_INT) && nbt.hasKey("y", NBT.TAG_INT) && nbt.hasKey("z", NBT.TAG_INT)) {
l = packLong(nbt.getInteger("x"), nbt.getInteger("y"), nbt.getInteger("z"));
hasPos = true;
} else if (nbt.hasKey("cp", NBT.TAG_LONG)) {
l = nbt.getLong("cp");
hasPos = true;
}
if (hasPos) {
if (nbt.hasKey("e")) {
Battery eb = new Battery(MCFluxConfig.WORLDCHUNK_CAP);
eb.deserializeNBT(nbt.getTag("e"));
eChunks.put(l, eb);
}
}
}
}
}
示例8: readFromNBT
import net.minecraftforge.common.util.Constants.NBT; //导入依赖的package包/类
@Override
public default void readFromNBT(NBTTagCompound compound)
{
setBurning(compound.getBoolean("burning"));
setBurningTicks(compound.getInteger("burningTicks"));
NBTTagList inventory = compound.getTagList("inventory", NBT.TAG_COMPOUND);
Collection<NBTTagCompound> out = new ArrayList<>();
for (int i = 0; i < inventory.tagCount(); i++)
out.add(inventory.getCompoundTagAt(i));
List<ItemStack> in = CollectionUtil.convert(out, (NBTTagCompound n) -> n.getBoolean("null") ? null : ItemStack
.loadItemStackFromNBT(n));
for (int i = 0; i < getInventory().length; i++)
getInventory()[i] = in.get(i);
}
示例9: readFromNBT
import net.minecraftforge.common.util.Constants.NBT; //导入依赖的package包/类
/**
* A custom method to read our inventory from an ItemStack's NBT compound
*/
public void readFromNBT(NBTTagCompound compound)
{
// Gets the custom taglist we wrote to this compound, if any
// 1.7.2+ change to compound.getTagList("ItemInventory", Constants.NBT.TAG_COMPOUND);
NBTTagList items = compound.getTagList("PailInventory", Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < items.tagCount(); ++i)
{
// 1.7.2+ change to items.getCompoundTagAt(i)
NBTTagCompound item = (NBTTagCompound) items.getCompoundTagAt(i);
int slot = item.getInteger("Slot");
// Just double-checking that the saved slot index is within our inventory array bounds
if (slot >= 0 && slot < getSizeInventory()) {
inventory[slot] = ItemStack.loadItemStackFromNBT(item);
}
}
}
示例10: iterate
import net.minecraftforge.common.util.Constants.NBT; //导入依赖的package包/类
private static final void iterate(NBTTagCompound parent, NBTTreeConsumer consumer, int depth) {
if(parent == null) return;
consumer.consume(depth+1, "<compound>", parent, null);
for(Object keyObject : parent.getKeySet()) {
String key = (String)keyObject;
NBTBase value = parent.getTag(key);
consumer.consume(depth+1, key, value, parent);
if(value instanceof NBTTagCompound) {
iterate((NBTTagCompound)value, consumer, depth+1);
}
if(value instanceof NBTTagList) {
NBTTagList list = (NBTTagList) value;
if(list.getTagType() == NBT.TAG_COMPOUND) {
for(int i = 0; i < list.tagCount(); i++) {
NBTTagCompound compound = list.getCompoundTagAt(i);
iterate(compound, consumer, depth+1);
}
}
}
}
consumer.consume(depth+1, "", null, parent);
}
示例11: asJson
import net.minecraftforge.common.util.Constants.NBT; //导入依赖的package包/类
private static void asJson(NBTBase tag, StringBuilder builder) {
switch(tag.getId()) {
case NBT.TAG_BYTE: builder.append(((NBTTagByte)tag).getByte()).append('b'); break;
case NBT.TAG_SHORT: builder.append(((NBTTagShort)tag).getByte()).append('b'); break;
case NBT.TAG_INT: builder.append(((NBTTagInt)tag).getInt()); break;
case NBT.TAG_LONG: builder.append(((NBTTagLong)tag).getByte()).append('l'); break;
case NBT.TAG_FLOAT: builder.append(((NBTTagFloat)tag).getFloat()).append('f'); break;
case NBT.TAG_DOUBLE: builder.append(((NBTTagDouble)tag).getDouble()).append('d'); break;
case NBT.TAG_STRING: builder.append('"').append(((NBTTagString)tag).getString()).append('"'); break;
case NBT.TAG_BYTE_ARRAY: builder.append(Arrays.toString(((NBTTagByteArray)tag).getByteArray())); break;
case NBT.TAG_INT_ARRAY: builder.append(Arrays.toString(((NBTTagIntArray)tag).getIntArray())); break;
case NBT.TAG_COMPOUND: asJson((NBTTagCompound) tag, builder); break;
case NBT.TAG_LIST: asJson((NBTTagList) tag, builder); break;
}
}
示例12: deserializeNBT
import net.minecraftforge.common.util.Constants.NBT; //导入依赖的package包/类
/**
* Reads the player's chat channels fron nbt and joins them
*/
@Override
public void deserializeNBT(NBTTagCompound settings) {
MoreCommands.getProxy().ensureChatChannelsLoaded();
NBTTagList chatChannels = settings.getTagList(NBT_CHATCHANNELS_IDENTIFIER, NBT.TAG_STRING);
if (chatChannels != null) {
for (int i = 0; i < chatChannels.tagCount(); i++) {
ChatChannel channel = ChatChannel.getChannel(chatChannels.getStringTagAt(i));
if (channel != null && !channel.isChannelMember(this.player)) channel.join(this.player);
}
}
if (this.chatChannels.isEmpty())
ChatChannel.getMasterChannel().join(this.player);
this.playerChannelsToSave.clear();
this.loggedOut = false;
}
示例13: removeEnchantment
import net.minecraftforge.common.util.Constants.NBT; //导入依赖的package包/类
/**
* removes an enchantment from the current item
*/
public static void removeEnchantment(EntityLivingBase entity, Enchantment enchantment) {
if (entity.getHeldItemMainhand() == ItemStack.EMPTY) return;
NBTTagCompound compound = entity.getHeldItemMainhand().getTagCompound();
if (compound == null) return;
NBTTagList enchantments = compound.hasKey("ench", NBT.TAG_LIST) ? compound.getTagList("ench", NBT.TAG_COMPOUND) : null;
if (enchantments == null) return;
int id = Enchantment.getEnchantmentID(enchantment);
NBTTagList newList = new NBTTagList();
for (int i = 0; i < enchantments.tagCount(); i++) {
if (enchantments.getCompoundTagAt(i).getShort("id") != id) {
newList.appendTag(enchantments.getCompoundTagAt(i));
}
}
if (newList.tagCount() == 0) compound.removeTag("ench");
else compound.setTag("ench", newList);
}
示例14: hasEnchantment
import net.minecraftforge.common.util.Constants.NBT; //导入依赖的package包/类
/**
* @return whether the player has this enchantment
*/
public static boolean hasEnchantment(EntityLivingBase entity, Enchantment enchantment) {
if (entity.getHeldItemMainhand() == ItemStack.EMPTY) return false;
NBTTagCompound compound = entity.getHeldItemMainhand().getTagCompound();
if (compound == null) return false;
NBTTagList enchantments = compound.hasKey("ench", NBT.TAG_LIST) ? compound.getTagList("ench", NBT.TAG_COMPOUND) : null;
if (enchantments == null) return false;
int id = Enchantment.getEnchantmentID(enchantment);
for (int i = 0; i < enchantments.tagCount(); i++) {
if (enchantments.getCompoundTagAt(i).getShort("id") == id) {
return true;
}
}
return false;
}
示例15: readFromNBT
import net.minecraftforge.common.util.Constants.NBT; //导入依赖的package包/类
@Override
public void readFromNBT(NBTTagCompound nbtTags)
{
super.readFromNBT(nbtTags);
if(nbtTags.hasKey("fluidTank"))
{
fluidTank.readFromNBT(nbtTags.getCompoundTag("fluidTank"));
}
if(nbtTags.hasKey("controlType"))
{
controlType = RedstoneControl.values()[nbtTags.getInteger("controlType")];
}
if(nbtTags.hasKey("recurringNodes"))
{
NBTTagList tagList = nbtTags.getTagList("recurringNodes", NBT.TAG_COMPOUND);
for(int i = 0; i < tagList.tagCount(); i++)
{
recurringNodes.add(Coord4D.read((NBTTagCompound)tagList.getCompoundTagAt(i)));
}
}
}