use of net.minecraft.nbt.CompoundNBT in project Overloaded by CJ-MC-Mods.
the class ProcessingItemStorage method serializeNBT.
@Override
public CompoundNBT serializeNBT() {
CompoundNBT storage = new CompoundNBT();
CompoundNBT inputNBT = new CompoundNBT();
CompoundNBT outputNBT = new CompoundNBT();
ItemStackHelper.saveAllItems(inputNBT, input);
ItemStackHelper.saveAllItems(outputNBT, output);
storage.put("Input", inputNBT);
storage.put("Output", outputNBT);
return storage;
}
use of net.minecraft.nbt.CompoundNBT in project Overloaded by CJ-MC-Mods.
the class ItemLinkingCard method appendHoverText.
@OnlyIn(Dist.CLIENT)
@Override
public void appendHoverText(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
CompoundNBT tag = stack.getTag();
if (tag != null && tag.contains("TYPE")) {
String type = tag.getString("TYPE");
int x = tag.getInt("X");
int y = tag.getInt("Y");
int z = tag.getInt("Z");
String worldID = tag.getString("WORLD");
tooltip.add(new StringTextComponent(String.format("Bound to %s at %s: %d,%d,%d", type, worldID, x, y, z)));
}
super.appendHoverText(stack, worldIn, tooltip, flagIn);
}
use of net.minecraft.nbt.CompoundNBT in project Overloaded by CJ-MC-Mods.
the class ItemMultiTool method getSelectedBlockItemStack.
@Nonnull
public ItemStack getSelectedBlockItemStack(ItemStack multiTool) {
CompoundNBT tagCompound = multiTool.getTag();
if (tagCompound == null || !tagCompound.contains("Item")) {
return ItemStack.EMPTY;
}
CompoundNBT itemTag = tagCompound.getCompound("Item");
return ItemStack.of(itemTag);
}
use of net.minecraft.nbt.CompoundNBT in project Overloaded by CJ-MC-Mods.
the class ItemMultiTool method leftClickOnBlockServer.
public static void leftClickOnBlockServer(@Nonnull ServerPlayerEntity player, LeftClickBlockMessage message) {
BlockPos pos = message.getPos();
ServerWorld world = player.getLevel();
ItemStack itemStack = player.getItemInHand(Hand.MAIN_HAND);
if (itemStack.getItem() != ModItems.multiTool || world.isEmptyBlock(pos)) {
return;
}
player.startUsingItem(Hand.MAIN_HAND);
if (player.isShiftKeyDown()) {
CompoundNBT tag = itemStack.getTag();
if (tag == null) {
tag = new CompoundNBT();
}
BlockState state = world.getBlockState(pos);
Item item = Item.byBlock(state.getBlock());
ItemStack stackToPlace = new ItemStack(() -> item, 1);
CompoundNBT blockTag = new CompoundNBT();
stackToPlace.save(blockTag);
tag.put("Item", blockTag);
itemStack.setTag(tag);
ITextComponent component = stackToPlace.getDisplayName();
player.displayClientMessage(new StringTextComponent("Bound tool to ").append(component), true);
} else {
LazyOptional<IEnergyStorage> opEnergy = itemStack.getCapability(ENERGY);
if (!opEnergy.isPresent()) {
Overloaded.logger.warn("MultiTool has no Energy Capability? NBT: " + itemStack.getTag());
return;
}
// Used to catch item spawn to teleport
RegistryKey<World> worldId = world.dimension();
CommonSideEvents.enabled = true;
CommonSideEvents.world = worldId;
CommonSideEvents.pos = pos;
CommonSideEvents.uuid = player.getUUID();
IEnergyStorage energy = opEnergy.orElseThrow(() -> new RuntimeException("Impossible Error"));
int efficiency = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.BLOCK_EFFICIENCY, itemStack);
int unbreaking = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.UNBREAKING, itemStack);
switch(breakAndUseEnergy(world, pos, energy, player, efficiency, unbreaking)) {
case FAIL_REMOVE:
player.displayClientMessage(new StringTextComponent("Unable to break block, reason unknown"), true);
break;
case FAIL_ENERGY:
player.displayClientMessage(new StringTextComponent("Unable to break block, not enough energy"), true);
break;
case FAIL_UNBREAKABLE:
player.displayClientMessage(new StringTextComponent("Block is unbreakable"), true);
break;
case FAIL_RANGE:
player.displayClientMessage(new StringTextComponent("Block is out of range."), true);
break;
case SUCCESS:
break;
}
CommonSideEvents.enabled = false;
}
}
use of net.minecraft.nbt.CompoundNBT in project Overloaded by CJ-MC-Mods.
the class AbstractBlockHyperReceiver method use.
@Override
@Nonnull
public ActionResultType use(@Nonnull BlockState state, @Nonnull World world, @Nonnull BlockPos pos, PlayerEntity player, @Nonnull Hand hand, @Nonnull BlockRayTraceResult rayTraceResult) {
ItemStack heldItem = player.getItemInHand(hand);
if (heldItem.getItem().equals(ModItems.linkingCard)) {
CompoundNBT tag = heldItem.getTag();
if (tag == null) {
tag = new CompoundNBT();
}
ResourceLocation worldId = world.dimension().location();
writeNodeData(tag, worldId, pos);
heldItem.setTag(tag);
if (world.isClientSide) {
player.displayClientMessage(new StringTextComponent(String.format("Recorded: World: %s Position: %s", worldId, pos.toShortString())), false);
}
return ActionResultType.CONSUME;
} else {
return super.use(state, world, pos, player, hand, rayTraceResult);
}
}
Aggregations