Search in sources :

Example 36 with CompoundNBT

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

the class BPEventHandler method dropHeads.

private void dropHeads(LivingDeathEvent event) {
    if (event.getEntityLiving() instanceof CreeperEntity) {
        event.getEntityLiving().spawnAtLocation(new ItemStack(Items.CREEPER_HEAD, 1), 0.0F);
    }
    if (event.getEntityLiving() instanceof PlayerEntity) {
        ItemStack drop = new ItemStack(Items.PLAYER_HEAD, 1);
        drop.setTag(new CompoundNBT());
        drop.getTag().putString("SkullOwner", event.getEntityLiving().getDisplayName().getString());
        event.getEntityLiving().spawnAtLocation(drop, 0.0F);
    }
    if (event.getEntityLiving() instanceof AbstractSkeletonEntity) {
        AbstractSkeletonEntity sk = (AbstractSkeletonEntity) event.getEntityLiving();
        if (sk instanceof SkeletonEntity) {
            event.getEntityLiving().spawnAtLocation(new ItemStack(Items.SKELETON_SKULL, 1), 0.0F);
        } else {
            event.getEntityLiving().spawnAtLocation(new ItemStack(Items.WITHER_SKELETON_SKULL, 1), 0.0F);
        }
    }
    if (event.getEntityLiving() instanceof ZombieEntity) {
        event.getEntityLiving().spawnAtLocation(new ItemStack(Items.ZOMBIE_HEAD, 1), 0.0F);
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 37 with CompoundNBT

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

the class ItemSeedBag method useOn.

@Override
public ActionResultType useOn(ItemUseContext context) {
    PlayerEntity player = context.getPlayer();
    World worldIn = context.getLevel();
    Hand hand = context.getHand();
    BlockPos pos = context.getClickedPos();
    if (player.isCrouching()) {
        return ActionResultType.PASS;
    }
    ItemStackHandler seedBagInvHandler = new ItemStackHandler(9);
    // Get Active hand
    Hand activeHand = Hand.MAIN_HAND;
    ItemStack seedBag = player.getItemInHand(activeHand);
    if (!(seedBag.getItem() instanceof ItemSeedBag)) {
        seedBag = player.getOffhandItem();
        activeHand = Hand.OFF_HAND;
    }
    // Get Items from the NBT Handler
    if (seedBag.hasTag())
        seedBagInvHandler.deserializeNBT(seedBag.getTag().getCompound("inv"));
    ItemStack seed = getSeedType(player.getItemInHand(hand));
    Block block = Block.byItem(seed.getItem());
    if (!seed.isEmpty() && block instanceof IPlantable) {
        IPlantable plant = (IPlantable) block;
        BlockState b = worldIn.getBlockState(pos);
        if (b.getBlock().canSustainPlant(b, worldIn, pos, Direction.UP, plant) && worldIn.isEmptyBlock(pos.relative(Direction.UP))) {
            for (int i = 0; i < 9; i++) {
                ItemStack is = seedBagInvHandler.getStackInSlot(i);
                if (!is.isEmpty()) {
                    worldIn.setBlock(pos.relative(Direction.UP), block.defaultBlockState(), 0);
                    seedBagInvHandler.extractItem(i, 1, false);
                    break;
                }
            }
            // Update items in the NBT
            if (!seedBag.hasTag())
                seedBag.setTag(new CompoundNBT());
            if (seedBag.getTag() != null) {
                seedBag.getTag().put("inv", seedBagInvHandler.serializeNBT());
            }
            return ActionResultType.SUCCESS;
        }
    }
    return ActionResultType.PASS;
}
Also used : ItemStackHandler(net.minecraftforge.items.ItemStackHandler) BlockState(net.minecraft.block.BlockState) CompoundNBT(net.minecraft.nbt.CompoundNBT) IPlantable(net.minecraftforge.common.IPlantable) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) Hand(net.minecraft.util.Hand) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity)

Example 38 with CompoundNBT

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

the class PacketHelper method readNBT.

public static CompoundNBT readNBT(DataInput in) throws IOException {
    ByteBuf buf = Unpooled.buffer();
    buf.writeBytes(readBytes(in));
    // CompoundNBT t = ByteBufUtils.read(buf);
    return new CompoundNBT();
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) ByteBuf(io.netty.buffer.ByteBuf)

Example 39 with CompoundNBT

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

the class InventoryItem method readFromNBT.

protected void readFromNBT() {
    reading = true;
    ListNBT itemList = (ListNBT) ((CompoundNBT) item.getTag().get("Inventory")).get("Items");
    for (int i = 0; i < itemList.size(); i++) {
        CompoundNBT slotEntry = itemList.getCompound(i);
        int j = slotEntry.getByte("Slot") & 0xff;
        if (j >= 0 && j < getContainerSize()) {
            setItem(j, ItemStack.of(slotEntry));
        }
    }
    reading = false;
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) CompoundNBT(net.minecraft.nbt.CompoundNBT)

Example 40 with CompoundNBT

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

the class ContainerCanvasBag method removed.

@Override
public void removed(PlayerEntity playerIn) {
    // Update items in the NBT
    ItemStack canvasBag = playerIn.getItemInHand(activeHand);
    if (!canvasBag.hasTag())
        canvasBag.setTag(new CompoundNBT());
    if (canvasBag.getTag() != null) {
        canvasBag.getTag().put("inv", canvasBagInvHandler.serializeNBT());
    }
    super.removed(playerIn);
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) ItemStack(net.minecraft.item.ItemStack)

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