Search in sources :

Example 56 with CompoundNBT

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;
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT)

Example 57 with CompoundNBT

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);
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) StringTextComponent(net.minecraft.util.text.StringTextComponent) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 58 with CompoundNBT

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);
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) Nonnull(javax.annotation.Nonnull)

Example 59 with CompoundNBT

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;
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) ITextComponent(net.minecraft.util.text.ITextComponent) ServerWorld(net.minecraft.world.server.ServerWorld) World(net.minecraft.world.World) ServerWorld(net.minecraft.world.server.ServerWorld) Item(net.minecraft.item.Item) BlockItem(net.minecraft.item.BlockItem) BlockState(net.minecraft.block.BlockState) IEnergyStorage(net.minecraftforge.energy.IEnergyStorage) BlockPos(net.minecraft.util.math.BlockPos) StringTextComponent(net.minecraft.util.text.StringTextComponent) ItemStack(net.minecraft.item.ItemStack)

Example 60 with CompoundNBT

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);
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) ResourceLocation(net.minecraft.util.ResourceLocation) StringTextComponent(net.minecraft.util.text.StringTextComponent) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Aggregations

CompoundNBT (net.minecraft.nbt.CompoundNBT)119 ItemStack (net.minecraft.item.ItemStack)33 ListNBT (net.minecraft.nbt.ListNBT)15 Nonnull (javax.annotation.Nonnull)12 PlayerEntity (net.minecraft.entity.player.PlayerEntity)10 ResourceLocation (net.minecraft.util.ResourceLocation)8 BlockPos (net.minecraft.util.math.BlockPos)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 BlockState (net.minecraft.block.BlockState)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