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