net.minecraftforge.common.util.Constants.NBT Java Examples

The following examples show how to use net.minecraftforge.common.util.Constants.NBT. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TileEntityPipeBase.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound compound) {
    super.readFromNBT(compound);
    if (compound.hasKey("PipeBlock", NBT.TAG_STRING)) {
        Block block = Block.REGISTRY.getObject(new ResourceLocation(compound.getString("PipeBlock")));
        //noinspection unchecked
        this.pipeBlock = block instanceof BlockPipe ? (BlockPipe<PipeType, NodeDataType, ?>) block : null;
    }
    this.pipeType = getPipeTypeClass().getEnumConstants()[compound.getInteger("PipeType")];
    NBTTagCompound blockedConnectionsTag = compound.getCompoundTag("BlockedConnectionsMap");
    this.blockedConnectionsMap.clear();
    for(String attachmentTypeKey : blockedConnectionsTag.getKeySet()) {
        int attachmentType = Integer.parseInt(attachmentTypeKey);
        int blockedConnections = blockedConnectionsTag.getInteger(attachmentTypeKey);
        this.blockedConnectionsMap.put(attachmentType, blockedConnections);
    }
    recomputeBlockedConnections();
    this.insulationColor = compound.getInteger("InsulationColor");
    this.coverableImplementation.readFromNBT(compound);
}
 
Example #2
Source File: SpaceObjectAsteroid.java    From AdvancedRocketry with MIT License 6 votes vote down vote up
@Override
public void readFromNbt(NBTTagCompound nbt) {
	super.readFromNbt(nbt);
	
	NBTTagList list = nbt.getTagList("composition", NBT.TAG_COMPOUND);
	compositionMapping.clear();
	for(int i = 0; i < list.tagCount(); i++) {
		NBTTagCompound tag = list.getCompoundTagAt(i);
		int blockId = tag.getInteger("id");
		int rarity = tag.getInteger("amt");
		compositionMapping.put(Block.getBlockById(blockId), rarity);
	}
	
	numberOfBlocks = nbt.getInteger("numBlocks");
	uuid = nbt.getLong("uuid");
	data.readFromNBT(nbt);
}
 
Example #3
Source File: StellarBody.java    From AdvancedRocketry with MIT License 6 votes vote down vote up
public void readFromNBT(NBTTagCompound nbt) {
	id = nbt.getInteger("id");
	temperature = nbt.getInteger("temperature");
	name = nbt.getString("name");
	posX = nbt.getShort("posX");
	posZ = nbt.getShort("posZ");
	
	if(nbt.hasKey("size"))
		size = nbt.getFloat("size");
	
	if(nbt.hasKey("seperation"))
		starSeperation = nbt.getFloat("seperation");
	
	subStars.clear();
	if(nbt.hasKey("subStars")) {
		NBTTagList list = nbt.getTagList("subStars", NBT.TAG_COMPOUND);
		
		for(int i = 0; i < list.tagCount(); i++) {
			StellarBody star = new StellarBody();
			star.readFromNBT(list.getCompoundTagAt(i));
			subStars.add(star);
		}
	}
}
 
Example #4
Source File: ItemSpaceArmor.java    From AdvancedRocketry with MIT License 6 votes vote down vote up
public ItemStack removeComponent(World world, ItemStack armor, int index) {
	NBTTagCompound nbt;
	NBTTagList componentList;

	if(armor.hasTagCompound()) {
		nbt = armor.getTagCompound();
		componentList = nbt.getTagList(componentNBTName, NBT.TAG_COMPOUND);
	}
	else {
		return ItemStack.EMPTY;
	}

	EmbeddedInventory inv = loadEmbeddedInventory(armor);
	ItemStack stack = inv.getStackInSlot(index);
	inv.setInventorySlotContents(index, ItemStack.EMPTY);

	if(!stack.isEmpty()) {
		IArmorComponent component = (IArmorComponent) stack.getItem();
		component.onComponentRemoved(world, armor);
		saveEmbeddedInventory(armor, inv);
	}



	return stack;
}
 
Example #5
Source File: TileGuidanceComputer.java    From AdvancedRocketry with MIT License 6 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound nbt) {
	super.readFromNBT(nbt);
	destinationId = nbt.getInteger("destDimId");

	landingPos.x = nbt.getFloat("landingx");
	landingPos.y = nbt.getFloat("landingy");
	landingPos.z = nbt.getFloat("landingz");

	NBTTagList stationList = nbt.getTagList("stationMapping", NBT.TAG_COMPOUND);

	for(int i = 0; i < stationList.tagCount(); i++) {
		NBTTagCompound tag = stationList.getCompoundTagAt(i);
		int pos[];
		pos = tag.getIntArray("pos");
		int id = tag.getInteger("id");
		landingLoc.put(id, new HashedBlockPosition(pos[0], pos[1], pos[2]));
	}
}
 
Example #6
Source File: MetaTileEntityPrimitiveBlastFurnace.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound data) {
    super.readFromNBT(data);
    this.isActive = data.getBoolean("Active");
    this.wasActiveAndNeedUpdate = data.getBoolean("WasActive");
    this.fuelUnitsLeft = data.getFloat("FuelUnitsLeft");
    this.maxProgressDuration = data.getInteger("MaxProgress");
    if (maxProgressDuration > 0) {
        this.currentProgress = data.getInteger("Progress");
        NBTTagList itemOutputs = data.getTagList("Outputs", NBT.TAG_COMPOUND);
        this.outputsList = NonNullList.create();
        for (int i = 0; i < itemOutputs.tagCount(); i++) {
            this.outputsList.add(new ItemStack(itemOutputs.getCompoundTagAt(i)));
        }
    }
}
 
Example #7
Source File: MetaTileEntityTank.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound data) {
    super.readFromNBT(data);
    if (data.hasKey("ControllerPos")) {
        this.controllerPos = NBTUtil.getPosFromTag(data.getCompoundTag("ControllerPos"));
    } else {
        NBTTagList connectedTanks = data.getTagList("ConnectedTanks", NBT.TAG_COMPOUND);
        connectedTanks.forEach(pos -> this.connectedTanks.add(NBTUtil.getPosFromTag((NBTTagCompound) pos)));
        recomputeTankSizeNow(true);
        this.multiblockFluidTank.readFromNBT(data.getCompoundTag("FluidInventory"));
        this.lastSentFluidStack = this.multiblockFluidTank.getFluid();
        if (data.hasKey("MultiblockSize")) {
            this.multiblockSize = NBTUtil.getPosFromTag(data.getCompoundTag("MultiblockSize"));
        }
    }
}
 
Example #8
Source File: InventoryPartUpgrades.java    From BetterChests with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound nbt) {
	super.readFromNBT(nbt);
	Arrays.fill(disabled, false);
	NBTTagList list = nbt.getTagList("disabled", NBT.TAG_INT);
	for (int i = 0; i < list.tagCount(); i++) {
		disabled[((NBTTagInt)list.get(i)).getInt()] = true;
	}
}
 
Example #9
Source File: PipeCoverableImplementation.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void readFromNBT(NBTTagCompound data) {
    NBTTagList coversList = data.getTagList("Covers", NBT.TAG_COMPOUND);
    for (int index = 0; index < coversList.tagCount(); index++) {
        NBTTagCompound tagCompound = coversList.getCompoundTagAt(index);
        if (tagCompound.hasKey("CoverId", NBT.TAG_STRING)) {
            EnumFacing coverSide = EnumFacing.VALUES[tagCompound.getByte("Side")];
            ResourceLocation coverId = new ResourceLocation(tagCompound.getString("CoverId"));
            CoverDefinition coverDefinition = CoverDefinition.getCoverById(coverId);
            CoverBehavior coverBehavior = coverDefinition.createCoverBehavior(this, coverSide);
            coverBehavior.readFromNBT(tagCompound);
            this.coverBehaviors[coverSide.getIndex()] = coverBehavior;
        }
    }
}
 
Example #10
Source File: ItemUpgradeDirectional.java    From BetterChests with GNU Lesser General Public License v3.0 5 votes vote down vote up
public EnumFacing getSide(ItemStack stack) {
	NBTTagCompound nbt = stack.getTagCompound();
	if (nbt == null || !nbt.hasKey("dir", NBT.TAG_INT)) {
		return null;
	}
	int val = nbt.getInteger("dir");
	if (val < 0 || val >= EnumFacing.VALUES.length) {
		return null;
	}
	return EnumFacing.VALUES[val];
}
 
Example #11
Source File: SpaceObjectManager.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
public void readFromNBT(NBTTagCompound nbt) {
	NBTTagList list = nbt.getTagList("spaceContents", NBT.TAG_COMPOUND);
	nextId = nbt.getInteger("nextInt");
	nextStationTransitionTick = nbt.getLong("nextStationTransitionTick");

	for(int i = 0; i < list.tagCount(); i++) {
		NBTTagCompound tag = list.getCompoundTagAt(i);
		try {
			ISpaceObject object = (ISpaceObject)nameToClass.get(tag.getString("type")).newInstance();
			object.readFromNbt(tag);
			
			
			if(tag.hasKey("expireTime")) {
				long expireTime = tag.getLong("expireTime");
				int numPlayers = tag.getInteger("numPlayers");
				if (DimensionManager.getWorld(Configuration.spaceDimId).getTotalWorldTime() >= expireTime && numPlayers == 0)
					continue;
				temporaryDimensions.put(object.getId(), expireTime);
				temporaryDimensionPlayerNumber.put(object.getId(), numPlayers);
			}
			
			registerSpaceObject(object, object.getOrbitingPlanetId(), object.getId() );

		} catch (Exception e) {
			System.out.println(tag.getString("type"));
			e.printStackTrace();
		}
	}
}
 
Example #12
Source File: NBTStorableListList.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
public void readFromNBT(NBTTagCompound nbt) {
	
	NBTTagList list = nbt.getTagList("list", NBT.TAG_COMPOUND);
	pos.clear();
	for(int i = 0; i < list.tagCount(); i++) {
		NBTTagCompound nbttag = list.getCompoundTagAt(i);
		int[] tag = nbttag.getIntArray("loc");
		int dimid = nbttag.getInteger("dim");
		
		pos.add(new DimensionBlockPosition(dimid, new HashedBlockPosition(tag[0], tag[1], tag[2])));
	}
}
 
Example #13
Source File: FacadeItem.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static ItemStack getFacadeStackUnsafe(ItemStack itemStack) {
    NBTTagCompound tagCompound = itemStack.getTagCompound();
    if (tagCompound == null || !tagCompound.hasKey("Facade", NBT.TAG_COMPOUND)) {
        return null;
    }
    ItemStack facadeStack = new ItemStack(tagCompound.getCompoundTag("Facade"));
    if (facadeStack.isEmpty() || !FacadeHelper.isValidFacade(facadeStack)) {
        return null;
    }
    return facadeStack;
}
 
Example #14
Source File: AbstractMaterialPartBehavior.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public int getPartDamage(ItemStack itemStack) {
    NBTTagCompound compound = getPartStatsTag(itemStack);
    if (compound == null || !compound.hasKey("Damage", NBT.TAG_ANY_NUMERIC)) {
        return 0;
    }
    return compound.getInteger("Damage");
}
 
Example #15
Source File: AbstractMaterialPartBehavior.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public IngotMaterial getPartMaterial(ItemStack itemStack) {
    NBTTagCompound compound = getPartStatsTag(itemStack);
    IngotMaterial defaultMaterial = Materials.Darmstadtium;
    if (compound == null || !compound.hasKey("Material", NBT.TAG_STRING)) {
        return defaultMaterial;
    }
    String materialName = compound.getString("Material");
    Material material = Material.MATERIAL_REGISTRY.getObject(materialName);
    if (!(material instanceof IngotMaterial)) {
        return defaultMaterial;
    }
    return (IngotMaterial) material;
}
 
Example #16
Source File: TileEntitySurfaceRock.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound compound) {
    super.readFromNBT(compound);
    Material material = Material.MATERIAL_REGISTRY.getObject(compound.getString("Material"));
    this.material = material == null ? Materials.Aluminium : material;

    for (NBTBase undergroundMaterialNBTBase : compound.getTagList("UndergroundMaterials", NBT.TAG_STRING)) {
        undergroundMaterials.add(Material.MATERIAL_REGISTRY.getObject(((NBTTagString) undergroundMaterialNBTBase).getString()));
    }
}
 
Example #17
Source File: MetaTileEntityQuantumChest.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound data) {
    super.readFromNBT(data);
    if (data.hasKey("ItemStack", NBT.TAG_COMPOUND)) {
        this.itemStack = new ItemStack(data.getCompoundTag("ItemStack"));
        if (!itemStack.isEmpty()) {
            this.itemsStoredInside = data.getLong("ItemAmount");
        }
    }
}
 
Example #18
Source File: MetaTileEntityTank.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, @Nullable World player, List<String> tooltip, boolean advanced) {
    tooltip.add(I18n.format("gregtech.universal.tooltip.fluid_storage_capacity", tankSize));
    tooltip.add(I18n.format("gregtech.machine.fluid_tank.max_multiblock", maxSizeHorizontal, maxSizeVertical, maxSizeHorizontal));
    NBTTagCompound tagCompound = stack.getTagCompound();
    if (tagCompound != null && tagCompound.hasKey("Fluid", NBT.TAG_COMPOUND)) {
        FluidStack fluidStack = FluidStack.loadFluidStackFromNBT(tagCompound.getCompoundTag("Fluid"));
        if (fluidStack != null) {
            tooltip.add(I18n.format("gregtech.machine.fluid_tank.fluid", fluidStack.amount, fluidStack.getLocalizedName()));
        }
    }
}
 
Example #19
Source File: MetaTileEntityTank.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SideOnly(Side.CLIENT)
private FluidStack getFluidForRendering() {
    if (getWorld() == null && renderContextStack != null) {
        NBTTagCompound tagCompound = renderContextStack.getTagCompound();
        if (tagCompound != null && tagCompound.hasKey("Fluid", NBT.TAG_COMPOUND)) {
            return FluidStack.loadFluidStackFromNBT(tagCompound.getCompoundTag("Fluid"));
        }
        return null;
    }
    return getActualTankFluid();
}
 
Example #20
Source File: MetaTileEntityTank.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void initFromItemStackData(NBTTagCompound itemStack) {
    super.initFromItemStackData(itemStack);
    if (itemStack.hasKey(FluidHandlerItemStack.FLUID_NBT_KEY, NBT.TAG_COMPOUND)) {
        FluidStack fluidStack = FluidStack.loadFluidStackFromNBT(itemStack.getCompoundTag(FluidHandlerItemStack.FLUID_NBT_KEY));
        this.multiblockFluidTank.fill(fluidStack, true);
    }
}
 
Example #21
Source File: CraftingRecipeMemory.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void deserializeNBT(NBTTagCompound tagCompound) {
    NBTTagList resultList = tagCompound.getTagList("Memory", NBT.TAG_COMPOUND);
    for (int i = 0; i < resultList.tagCount(); i++) {
        NBTTagCompound entryComponent = resultList.getCompoundTagAt(i);
        int slotIndex = entryComponent.getInteger("Slot");
        MemorizedRecipe recipe = MemorizedRecipe.deserializeNBT(entryComponent.getCompoundTag("Recipe"));
        this.memorizedRecipes[slotIndex] = recipe;
    }
}
 
Example #22
Source File: MetaTileEntityLockedSafe.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void initFromItemStackData(NBTTagCompound itemStack) {
    super.initFromItemStackData(itemStack);
    if (itemStack.hasKey("ComponentTier", NBT.TAG_ANY_NUMERIC)) {
        this.unlockComponentTier = itemStack.getInteger("ComponentTier");
    }
}
 
Example #23
Source File: MetaTileEntityBatteryBuffer.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound data) {
    super.readFromNBT(data);
    if (data.hasKey("AllowEnergyOutput", NBT.TAG_ANY_NUMERIC)) {
        this.allowEnergyOutput = data.getBoolean("AllowEnergyOutput");
    }
}
 
Example #24
Source File: ElectricItem.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public long getMaxCharge() {
    NBTTagCompound tagCompound = itemStack.getTagCompound();
    if (tagCompound == null)
        return maxCharge;
    if (tagCompound.hasKey("MaxCharge", NBT.TAG_LONG))
        return tagCompound.getLong("MaxCharge");
    return maxCharge;
}
 
Example #25
Source File: FuelRecipeLogic.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void deserializeNBT(NBTTagCompound compound) {
    if (!compound.hasKey("WorkEnabled", NBT.TAG_BYTE)) {
        //change working mode only if there is a tag compound with it's value
        this.workingEnabled = compound.getBoolean("WorkEnabled");
    }
    this.recipeDurationLeft = compound.getInteger("RecipeDurationLeft");
    if (recipeDurationLeft > 0) {
        this.recipeOutputVoltage = compound.getLong("RecipeOutputVoltage");
    }
    this.isActive = recipeDurationLeft > 0;
}
 
Example #26
Source File: MetaTileEntity.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void readFromNBT(NBTTagCompound data) {
    this.frontFacing = EnumFacing.VALUES[data.getInteger("FrontFacing")];
    this.paintingColor = data.getInteger("PaintingColor");
    this.cachedLightValue = data.getInteger("CachedLightValue");

    if (shouldSerializeInventories()) {
        GTUtility.readItems(importItems, "ImportInventory", data);
        GTUtility.readItems(exportItems, "ExportInventory", data);

        importFluids.deserializeNBT(data.getCompoundTag("ImportFluidInventory"));
        exportFluids.deserializeNBT(data.getCompoundTag("ExportFluidInventory"));
    }

    for (MTETrait mteTrait : this.mteTraits) {
        NBTTagCompound traitCompound = data.getCompoundTag(mteTrait.getName());
        mteTrait.deserializeNBT(traitCompound);
    }

    NBTTagList coversList = data.getTagList("Covers", NBT.TAG_COMPOUND);
    for (int index = 0; index < coversList.tagCount(); index++) {
        NBTTagCompound tagCompound = coversList.getCompoundTagAt(index);
        if (tagCompound.hasKey("CoverId", NBT.TAG_STRING)) {
            EnumFacing coverSide = EnumFacing.VALUES[tagCompound.getByte("Side")];
            ResourceLocation coverId = new ResourceLocation(tagCompound.getString("CoverId"));
            CoverDefinition coverDefinition = CoverDefinition.getCoverById(coverId);
            CoverBehavior coverBehavior = coverDefinition.createCoverBehavior(this, coverSide);
            coverBehavior.readFromNBT(tagCompound);
            this.coverBehaviors[coverSide.getIndex()] = coverBehavior;
        }
    }

    this.isFragile = data.getBoolean("Fragile");
}
 
Example #27
Source File: MetaTileEntity.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Called from ItemBlock to initialize this MTE with data contained in ItemStack
 *
 * @param itemStack itemstack of itemblock
 */
public void initFromItemStackData(NBTTagCompound itemStack) {
    if (itemStack.hasKey("PaintingColor", NBT.TAG_INT)) {
        setPaintingColor(itemStack.getInteger("PaintingColor"));
    }
    if (itemStack.hasKey("Fragile")) {
        setFragile(itemStack.getBoolean("Fragile"));
    }
}
 
Example #28
Source File: MetaTileEntity.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SideOnly(Side.CLIENT)
public int getPaintingColorForRendering() {
    if (getWorld() == null && renderContextStack != null) {
        NBTTagCompound tagCompound = renderContextStack.getTagCompound();
        if (tagCompound != null && tagCompound.hasKey("PaintingColor", NBT.TAG_INT)) {
            return tagCompound.getInteger("PaintingColor");
        }
    }
    return paintingColor;
}
 
Example #29
Source File: SyncedTileEntityBase.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
    NBTTagCompound updateTag = pkt.getNbtCompound();
    NBTTagList tagList = updateTag.getTagList("d", NBT.TAG_COMPOUND);
    for (int i = 0; i < tagList.tagCount(); i++) {
        NBTTagCompound entryTag = tagList.getCompoundTagAt(i);
        int discriminator = entryTag.getInteger("i");
        byte[] updateData = entryTag.getByteArray("d");
        ByteBuf backedBuffer = Unpooled.copiedBuffer(updateData);
        receiveCustomData(discriminator, new PacketBuffer(backedBuffer));
    }
}
 
Example #30
Source File: WorldPipeNet.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound nbt) {
    this.pipeNets = new ArrayList<>();
    NBTTagList allEnergyNets = nbt.getTagList("PipeNets", NBT.TAG_COMPOUND);
    for (int i = 0; i < allEnergyNets.tagCount(); i++) {
        NBTTagCompound pNetTag = allEnergyNets.getCompoundTagAt(i);
        T pipeNet = createNetInstance();
        pipeNet.deserializeNBT(pNetTag);
        addPipeNetSilently(pipeNet);
    }
}