use of net.minecraft.nbt.CompoundNBT in project BluePower by Qmunity.
the class ItemStackDatabase method saveItemStack.
public void saveItemStack(ItemStack stack) {
new File(saveLocation).mkdirs();
File targetRegistryName = new File(saveLocation + stack.getDisplayName() + FILE_EXTENSION);
CompoundNBT tag = new CompoundNBT();
stack.save(tag);
ResourceLocation ui = stack.getItem().getRegistryName();
tag.putString("owner", ui.getNamespace());
tag.putString("name", ui.getPath());
try {
FileOutputStream fos = new FileOutputStream(targetRegistryName);
DataOutputStream dos = new DataOutputStream(fos);
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
CompressedStreamTools.writeCompressed(tag, byteStream);
byte[] abyte = byteStream.toByteArray();
dos.writeShort((short) abyte.length);
dos.write(abyte);
dos.close();
} catch (IOException e) {
BluePower.log.error("IOException when trying to save an ItemStack in the database: " + e);
}
cache = null;
}
use of net.minecraft.nbt.CompoundNBT in project BluePower by Qmunity.
the class TubeStack method copy.
public TubeStack copy() {
CompoundNBT tag = new CompoundNBT();
writeToNBT(tag);
return loadFromNBT(tag);
}
use of net.minecraft.nbt.CompoundNBT in project BluePower by Qmunity.
the class ItemBPPart method place.
@Override
public ActionResultType place(BlockItemUseContext context) {
BlockState state = context.getLevel().getBlockState(context.getClickedPos());
BlockState thisState = getBlock().getStateForPlacement(context);
if (state.getBlock() instanceof IBPPartBlock && thisState != null && !AABBUtils.testOcclusion(((IBPPartBlock) thisState.getBlock()).getOcclusionShape(thisState), state.getShape(context.getLevel(), context.getClickedPos()))) {
// Save the Tile Entity Data
CompoundNBT nbt = new CompoundNBT();
TileEntity tileEntity = context.getLevel().getBlockEntity(context.getClickedPos());
if (tileEntity != null) {
nbt = tileEntity.save(nbt);
}
// Replace with Multipart
context.getLevel().setBlockAndUpdate(context.getClickedPos(), BPBlocks.multipart.defaultBlockState());
tileEntity = context.getLevel().getBlockEntity(context.getClickedPos());
if (tileEntity instanceof TileBPMultipart) {
// Add the original State to the Multipart
((TileBPMultipart) tileEntity).addState(state);
// Restore the Tile Entity Data
TileEntity tile = ((TileBPMultipart) tileEntity).getTileForState(state);
if (tile != null)
tile.load(state, nbt);
// Add the new State
((TileBPMultipart) tileEntity).addState(thisState);
thisState.getBlock().setPlacedBy(context.getLevel(), context.getClickedPos(), thisState, context.getPlayer(), context.getItemInHand());
}
// Update Self
state.neighborChanged(context.getLevel(), context.getClickedPos(), state.getBlock(), context.getClickedPos(), false);
context.getItemInHand().shrink(1);
// Place Sound
context.getLevel().playSound(null, context.getClickedPos(), SoundEvents.STONE_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F);
return ActionResultType.SUCCESS;
} else if (state.getBlock() instanceof BlockBPMultipart && thisState != null && !AABBUtils.testOcclusion(((IBPPartBlock) thisState.getBlock()).getOcclusionShape(thisState), state.getShape(context.getLevel(), context.getClickedPos()))) {
// Add to the Existing Multipart
TileEntity tileEntity = context.getLevel().getBlockEntity(context.getClickedPos());
if (tileEntity instanceof TileBPMultipart) {
((TileBPMultipart) tileEntity).addState(thisState);
thisState.getBlock().setPlacedBy(context.getLevel(), context.getClickedPos(), thisState, context.getPlayer(), context.getItemInHand());
// Update Neighbors
for (Direction dir : Direction.values()) {
context.getLevel().getBlockState(context.getClickedPos().relative(dir)).neighborChanged(context.getLevel(), context.getClickedPos().relative(dir), state.getBlock(), context.getClickedPos(), false);
}
// Update Self
state.neighborChanged(context.getLevel(), context.getClickedPos(), state.getBlock(), context.getClickedPos(), false);
context.getItemInHand().shrink(1);
// Place Sound
context.getLevel().playSound(null, context.getClickedPos(), SoundEvents.STONE_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F);
return ActionResultType.SUCCESS;
}
}
return super.place(context);
}
use of net.minecraft.nbt.CompoundNBT in project BluePower by Qmunity.
the class ItemDamageableColorableOverlay method setUsesUsed.
public static void setUsesUsed(ItemStack stack, int newUses) {
CompoundNBT tag = stack.getTag();
if (tag == null) {
tag = new CompoundNBT();
stack.setTag(tag);
}
tag.putInt("usesUsed", newUses);
}
use of net.minecraft.nbt.CompoundNBT in project BluePower by Qmunity.
the class TileKinectGenerator method save.
/**
* This function gets called whenever the world/chunk is saved
*/
@Override
public CompoundNBT save(CompoundNBT tCompound) {
super.save(tCompound);
for (int i = 0; i < 1; i++) {
if (!allInventories.get(i).isEmpty()) {
CompoundNBT tc = new CompoundNBT();
allInventories.get(i).save(tc);
tCompound.put("inventory" + i, tc);
}
}
return tCompound;
}
Aggregations