Search in sources :

Example 11 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 12 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)

Example 13 with CompoundNBT

use of net.minecraft.nbt.CompoundNBT in project Overloaded by CJ-MC-Mods.

the class PlayerInterfaceRenderer method render.

@Override
public void render(@Nonnull TilePlayerInterface te, float v, @Nonnull MatrixStack matrixStack, @Nonnull IRenderTypeBuffer iRenderTypeBuffer, int combinedLightIn, int combinedOverlayIn) {
    UUID uuid = te.getPlacer();
    if (uuid == null)
        return;
    PlayerEntity player = te.getLevel().getPlayerByUUID(uuid);
    if (player == null) {
        if (!uuid.equals(uuidCache)) {
            uuidCache = uuid;
            CompoundNBT tag = new CompoundNBT();
            tag.putString("SkullOwner", uuid.toString());
            stackCache = new ItemStack(Items.PLAYER_HEAD, 1, tag);
        }
        renderItem(te, stackCache, matrixStack, iRenderTypeBuffer);
        return;
    }
    renderPlayer(te, player, matrixStack, iRenderTypeBuffer, combinedLightIn);
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) UUID(java.util.UUID) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 14 with CompoundNBT

use of net.minecraft.nbt.CompoundNBT in project Overloaded by CJ-MC-Mods.

the class EnergyInventoryBasedRecipeProcessor method serializeNBT.

@Override
public CompoundNBT serializeNBT() {
    CompoundNBT storage = new CompoundNBT();
    storage.put("Input", NBTHelper.serializeItems(input));
    storage.put("Output", NBTHelper.serializeItems(output));
    storage.putInt("Energy", currentEnergy);
    return storage;
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT)

Example 15 with CompoundNBT

use of net.minecraft.nbt.CompoundNBT in project Overloaded by CJ-MC-Mods.

the class BigIntEnergyStorage method serializeNBT.

@Override
public CompoundNBT serializeNBT() {
    CompoundNBT compound = new CompoundNBT();
    compound.putByteArray("Count", energy.amount.toByteArray());
    return compound;
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT)

Aggregations

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