Search in sources :

Example 21 with CompoundNBT

use of net.minecraft.nbt.CompoundNBT in project Overloaded by CJ-MC-Mods.

the class GenericDataStorage method readNBT.

@Override
public void readNBT(Capability<IGenericDataStorage> capability, IGenericDataStorage instance, Direction side, INBT nbt) {
    if (!(nbt instanceof CompoundNBT))
        return;
    CompoundNBT tagCompound = ((CompoundNBT) nbt);
    Map<String, Integer> integers = instance.getIntegerMap();
    Map<String, Boolean> booleans = instance.getBooleanMap();
    Map<String, Float> floats = instance.getFloatMap();
    Map<String, Double> doubles = instance.getDoubleMap();
    for (String key : tagCompound.getAllKeys()) {
        switch(tagCompound.getTagType(key)) {
            case Constants.NBT.TAG_INT:
                integers.put(key, tagCompound.getInt(key));
                break;
            case Constants.NBT.TAG_BYTE:
                booleans.put(key, tagCompound.getBoolean(key));
                break;
            case Constants.NBT.TAG_FLOAT:
                floats.put(key, tagCompound.getFloat(key));
                break;
            case Constants.NBT.TAG_DOUBLE:
                doubles.put(key, tagCompound.getDouble(key));
                break;
        }
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT)

Example 22 with CompoundNBT

use of net.minecraft.nbt.CompoundNBT in project Overloaded by CJ-MC-Mods.

the class GenericDataStorage method writeNBT.

@Nullable
@Override
public CompoundNBT writeNBT(Capability<IGenericDataStorage> capability, IGenericDataStorage instance, Direction side) {
    CompoundNBT tagCompound = new CompoundNBT();
    Map<String, Integer> integers = instance.getIntegerMap();
    Map<String, Boolean> booleans = instance.getBooleanMap();
    Map<String, Float> floats = instance.getFloatMap();
    Map<String, Double> doubles = instance.getDoubleMap();
    for (String key : integers.keySet()) {
        tagCompound.putInt(key, integers.get(key));
    }
    for (String key : booleans.keySet()) {
        tagCompound.putBoolean(key, booleans.get(key));
    }
    for (String key : floats.keySet()) {
        tagCompound.putFloat(key, floats.get(key));
    }
    for (String key : doubles.keySet()) {
        tagCompound.putDouble(key, doubles.get(key));
    }
    return tagCompound;
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) Nullable(javax.annotation.Nullable)

Example 23 with CompoundNBT

use of net.minecraft.nbt.CompoundNBT in project Overloaded by CJ-MC-Mods.

the class IntEnergyWrapper method getStorage.

@Nonnull
private EnergyStorage getStorage() {
    if (stack.getTag() == null) {
        Overloaded.logger.error((CharSequence) "Something has changed private internal state in an invalid way. Resetting State.", new IllegalStateException("private internal state changed. Stack's Tag Compound is null"));
        stack.setTag(new CompoundNBT());
    }
    int energy = stack.getTag().getInt("IntEnergyStorage");
    return new EnergyStorage(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, energy);
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) IEnergyStorage(net.minecraftforge.energy.IEnergyStorage) EnergyStorage(net.minecraftforge.energy.EnergyStorage) Nonnull(javax.annotation.Nonnull)

Example 24 with CompoundNBT

use of net.minecraft.nbt.CompoundNBT in project Overloaded by CJ-MC-Mods.

the class ProcessingItemStorage method serializeNBT.

@Override
public CompoundNBT serializeNBT() {
    CompoundNBT storage = new CompoundNBT();
    CompoundNBT inputNBT = new CompoundNBT();
    CompoundNBT outputNBT = new CompoundNBT();
    ItemStackHelper.saveAllItems(inputNBT, input);
    ItemStackHelper.saveAllItems(outputNBT, output);
    storage.put("Input", inputNBT);
    storage.put("Output", outputNBT);
    return storage;
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT)

Example 25 with CompoundNBT

use of net.minecraft.nbt.CompoundNBT in project Overloaded by CJ-MC-Mods.

the class TilePlayerInterface method getUpdatePacket.

@Nullable
@Override
public SUpdateTileEntityPacket getUpdatePacket() {
    CompoundNBT tag = new CompoundNBT();
    save(tag);
    return new SUpdateTileEntityPacket(getBlockPos(), 1, tag);
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) SUpdateTileEntityPacket(net.minecraft.network.play.server.SUpdateTileEntityPacket) Nullable(javax.annotation.Nullable)

Aggregations

CompoundNBT (net.minecraft.nbt.CompoundNBT)127 ItemStack (net.minecraft.item.ItemStack)33 ListNBT (net.minecraft.nbt.ListNBT)19 Nonnull (javax.annotation.Nonnull)12 PlayerEntity (net.minecraft.entity.player.PlayerEntity)10 BlockPos (net.minecraft.util.math.BlockPos)10 ResourceLocation (net.minecraft.util.ResourceLocation)9 BlockState (net.minecraft.block.BlockState)8 TileEntity (net.minecraft.tileentity.TileEntity)7 StringTextComponent (net.minecraft.util.text.StringTextComponent)7 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)6 DimensionType (net.minecraft.world.dimension.DimensionType)6 TileBPMultipart (com.bluepowermod.tile.TileBPMultipart)5 Block (net.minecraft.block.Block)5 ArrayList (java.util.ArrayList)4 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)4 SUpdateTileEntityPacket (net.minecraft.network.play.server.SUpdateTileEntityPacket)4 LongItemStack (com.cjm721.overloaded.storage.stacks.intint.LongItemStack)3 Nullable (javax.annotation.Nullable)3 IItemProvider (net.minecraft.util.IItemProvider)3