Search in sources :

Example 76 with CompoundNBT

use of net.minecraft.nbt.CompoundNBT in project BluePower by Qmunity.

the class BPEventHandler method itemPickUp.

@SubscribeEvent
public void itemPickUp(EntityItemPickupEvent event) {
    PlayerEntity player = event.getPlayer();
    ItemStack pickUp = event.getItem().getItem();
    if (!(player.containerMenu instanceof ContainerSeedBag)) {
        for (ItemStack is : player.inventory.items) {
            if (!is.isEmpty() && is.getItem() instanceof ItemSeedBag) {
                ItemStack seedType = ItemSeedBag.getSeedType(is);
                if (!seedType.isEmpty() && seedType.sameItem(pickUp)) {
                    ItemStackHandler seedBagInvHandler = new ItemStackHandler(9);
                    // Get Items from the NBT Handler
                    if (is.hasTag())
                        seedBagInvHandler.deserializeNBT(is.getTag().getCompound("inv"));
                    // Attempt to insert items
                    for (int j = 0; j < 9 && !pickUp.isEmpty(); ++j) {
                        pickUp = seedBagInvHandler.insertItem(j, pickUp, false);
                    }
                    // Update items in the NBT
                    if (!is.hasTag())
                        is.setTag(new CompoundNBT());
                    if (is.getTag() != null) {
                        is.getTag().put("inv", seedBagInvHandler.serializeNBT());
                    }
                    // Pickup Leftovers
                    if (pickUp.isEmpty()) {
                        event.setResult(Event.Result.ALLOW);
                        event.getItem().remove();
                        return;
                    } else {
                        event.getItem().setItem(pickUp);
                    }
                }
            }
        }
    }
}
Also used : ItemStackHandler(net.minecraftforge.items.ItemStackHandler) CompoundNBT(net.minecraft.nbt.CompoundNBT) ItemStack(net.minecraft.item.ItemStack) ItemSeedBag(com.bluepowermod.item.ItemSeedBag) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ContainerSeedBag(com.bluepowermod.container.ContainerSeedBag) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 77 with CompoundNBT

use of net.minecraft.nbt.CompoundNBT in project BluePower by Qmunity.

the class BlockBPMicroblock method getDrops.

@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
    TileEntity tileentity = builder.getParameter(LootParameters.BLOCK_ENTITY);
    List<ItemStack> itemStacks = new ArrayList<>();
    if (tileentity instanceof TileBPMultipart) {
        tileentity = ((TileBPMultipart) tileentity).getTileForState(state);
    }
    if (tileentity instanceof TileBPMicroblock) {
        CompoundNBT nbt = new CompoundNBT();
        nbt.putString("block", ((TileBPMicroblock) tileentity).getBlock().getRegistryName().toString());
        ItemStack stack = new ItemStack(this);
        stack.setTag(nbt);
        stack.setHoverName(new TranslationTextComponent(((TileBPMicroblock) tileentity).getBlock().getDescriptionId()).append(new StringTextComponent(" ")).append(new TranslationTextComponent(this.getDescriptionId())));
        itemStacks.add(stack);
    }
    return itemStacks;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileBPMicroblock(com.bluepowermod.tile.TileBPMicroblock) CompoundNBT(net.minecraft.nbt.CompoundNBT) ArrayList(java.util.ArrayList) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) StringTextComponent(net.minecraft.util.text.StringTextComponent) TileBPMultipart(com.bluepowermod.tile.TileBPMultipart) ItemStack(net.minecraft.item.ItemStack)

Example 78 with CompoundNBT

use of net.minecraft.nbt.CompoundNBT in project BluePower by Qmunity.

the class BlockInsulatedAlloyWire method getDrops.

@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
    TileEntity tileentity = builder.getParameter(LootParameters.BLOCK_ENTITY);
    List<ItemStack> itemStacks = new ArrayList<>();
    if (tileentity instanceof TileBPMultipart) {
        tileentity = ((TileBPMultipart) tileentity).getTileForState(state);
    }
    if (tileentity instanceof TileInsulatedWire) {
        CompoundNBT nbt = new CompoundNBT();
        nbt.putString("color", ((TileInsulatedWire) tileentity).getColor().name());
        ItemStack stack = new ItemStack(this, 1, nbt);
        itemStacks.add(stack);
    }
    return itemStacks;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) CompoundNBT(net.minecraft.nbt.CompoundNBT) TileInsulatedWire(com.bluepowermod.tile.tier1.TileInsulatedWire) ArrayList(java.util.ArrayList) TileBPMultipart(com.bluepowermod.tile.TileBPMultipart) ItemStack(net.minecraft.item.ItemStack)

Example 79 with CompoundNBT

use of net.minecraft.nbt.CompoundNBT in project BluePower by Qmunity.

the class TileBPMicroblock method getUpdateTag.

@Override
public CompoundNBT getUpdateTag() {
    CompoundNBT updateTag = super.getUpdateTag();
    save(updateTag);
    return updateTag;
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT)

Example 80 with CompoundNBT

use of net.minecraft.nbt.CompoundNBT in project BluePower by Qmunity.

the class TileBPMicroblock method onDataPacket.

@Override
public void onDataPacket(NetworkManager networkManager, SUpdateTileEntityPacket packet) {
    Block oldblock = getBlock();
    CompoundNBT tagCompound = packet.getTag();
    super.onDataPacket(networkManager, packet);
    load(getBlockState(), tagCompound);
    if (level.isClientSide) {
        // Update if needed
        if (!getBlock().equals(oldblock)) {
            level.blockEntityChanged(getBlockPos(), this.getTileEntity());
        }
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) Block(net.minecraft.block.Block)

Aggregations

CompoundNBT (net.minecraft.nbt.CompoundNBT)119 ItemStack (net.minecraft.item.ItemStack)33 ListNBT (net.minecraft.nbt.ListNBT)15 Nonnull (javax.annotation.Nonnull)12 PlayerEntity (net.minecraft.entity.player.PlayerEntity)10 ResourceLocation (net.minecraft.util.ResourceLocation)8 BlockPos (net.minecraft.util.math.BlockPos)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 BlockState (net.minecraft.block.BlockState)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