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);
}
}
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;
}
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();
}
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;
}
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);
}
Aggregations