Search in sources :

Example 1 with BlockItem

use of net.minecraft.item.BlockItem in project Overloaded by CJ-MC-Mods.

the class RenderMultiToolAssist method renderWorldLastEvent.

@SubscribeEvent
public static void renderWorldLastEvent(RenderWorldLastEvent event) {
    float partialTick = Minecraft.getInstance().getFrameTime();
    PlayerEntity player = Minecraft.getInstance().player;
    if (player.getMainHandItem().getItem() != ModItems.multiTool)
        return;
    RayTraceResult resultPick = player.pick(OverloadedConfig.INSTANCE.multiToolConfig.reach, partialTick, false);
    if (resultPick.getType() == RayTraceResult.Type.MISS || !(resultPick instanceof BlockRayTraceResult)) {
        return;
    }
    BlockRayTraceResult result = ((BlockRayTraceResult) resultPick);
    ItemStack stack = ModItems.multiTool.getSelectedBlockItemStack(player.getMainHandItem());
    BlockState state;
    if (stack.getItem() instanceof BlockItem) {
        state = ((BlockItem) stack.getItem()).getBlock().defaultBlockState();
        state = state.getStateAtViewpoint(player.getCommandSenderWorld(), result.getBlockPos(), player.getEyePosition(partialTick));
        state = state.getBlock().getStateForPlacement(new BlockItemUseContextPublic(player.getCommandSenderWorld(), player, Hand.MAIN_HAND, stack, result));
    } else {
        state = Blocks.COBBLESTONE.defaultBlockState();
    }
    switch(getAssistMode()) {
        case PLACE_PREVIEW:
            if (!stack.isEmpty() && state != null)
                renderBlockPreview(event, result, state);
            break;
        case REMOVE_PREVIEW:
            renderRemovePreview(event, result);
            break;
        case BOTH_PREVIEW:
            renderRemovePreview(event, result);
            if (!stack.isEmpty() && state != null)
                renderBlockPreview(event, result, state);
    }
}
Also used : BlockState(net.minecraft.block.BlockState) RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) ItemStack(net.minecraft.item.ItemStack) BlockItem(net.minecraft.item.BlockItem) BlockItemUseContextPublic(com.cjm721.overloaded.util.BlockItemUseContextPublic) ClientPlayerEntity(net.minecraft.client.entity.player.ClientPlayerEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 2 with BlockItem

use of net.minecraft.item.BlockItem in project BluePower by Qmunity.

the class MicroblockRecipe method assemble.

@Override
public ItemStack assemble(CraftingInventory inv) {
    for (int i = 0; i < inv.getContainerSize(); ++i) {
        ItemStack stack = inv.getItem(i);
        if (!stack.isEmpty() && stack.getItem() instanceof BlockItem) {
            if (Block.byItem(stack.getItem()).defaultBlockState().getShape(null, null) == VoxelShapes.block()) {
                CompoundNBT nbt = new CompoundNBT();
                nbt.putString("block", stack.getItem().getRegistryName().toString());
                ItemStack outStack = new ItemStack(BPBlocks.half_block, 2);
                outStack.setTag(nbt);
                outStack.setHoverName(new TranslationTextComponent(stack.getItem().getDescriptionId()).append(" ").append(new TranslationTextComponent(BPBlocks.half_block.getDescriptionId())));
                return outStack;
            } else if (Block.byItem(stack.getItem()) == BPBlocks.half_block) {
                CompoundNBT nbt = new CompoundNBT();
                nbt.putString("block", stack.getTag().getString("block"));
                ItemStack outStack = new ItemStack(BPBlocks.panel, 2);
                outStack.setTag(nbt);
                Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(nbt.getString("block")));
                outStack.setHoverName(new TranslationTextComponent(block.getDescriptionId()).append(" ").append(new TranslationTextComponent(BPBlocks.panel.getDescriptionId())));
                return outStack;
            } else if (Block.byItem(stack.getItem()) == BPBlocks.panel) {
                CompoundNBT nbt = new CompoundNBT();
                nbt.putString("block", stack.getTag().getString("block"));
                ItemStack outStack = new ItemStack(BPBlocks.cover, 2);
                outStack.setTag(nbt);
                Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(nbt.getString("block")));
                outStack.setHoverName(new TranslationTextComponent(block.getDescriptionId()).append(" ").append(new TranslationTextComponent(BPBlocks.cover.getDescriptionId())));
                return outStack;
            }
        }
    }
    return ItemStack.EMPTY;
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) ResourceLocation(net.minecraft.util.ResourceLocation) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) BlockItem(net.minecraft.item.BlockItem)

Example 3 with BlockItem

use of net.minecraft.item.BlockItem in project BluePower by Qmunity.

the class MicroblockRecipe method matches.

@Override
public boolean matches(CraftingInventory inv, World worldIn) {
    int blockCount = 0;
    int saw = 0;
    for (int i = 0; i < inv.getContainerSize(); ++i) {
        ItemStack stack = inv.getItem(i);
        if (!stack.isEmpty()) {
            if (stack.getItem() instanceof BlockItem && (Block.byItem(stack.getItem()) instanceof BlockBPMicroblock || !Block.byItem(stack.getItem()).hasTileEntity(Block.byItem(stack.getItem()).defaultBlockState()))) {
                VoxelShape shape = null;
                try {
                    shape = Block.byItem(stack.getItem()).defaultBlockState().getShape(null, null);
                } catch (NullPointerException ignored) {
                // Shulker Boxes try to query the Tile Entity
                }
                if (shape == VoxelShapes.block() || Block.byItem(stack.getItem()) == BPBlocks.half_block || Block.byItem(stack.getItem()) == BPBlocks.panel) {
                    blockCount++;
                }
            } else if (stack.getItem() instanceof ItemSaw) {
                saw++;
            } else {
                return false;
            }
        }
    }
    return blockCount == 1 && saw == 1;
}
Also used : VoxelShape(net.minecraft.util.math.shapes.VoxelShape) ItemStack(net.minecraft.item.ItemStack) BlockItem(net.minecraft.item.BlockItem) ItemSaw(com.bluepowermod.item.ItemSaw) BlockBPMicroblock(com.bluepowermod.block.BlockBPMicroblock)

Example 4 with BlockItem

use of net.minecraft.item.BlockItem in project Bookshelf by Darkhax-Minecraft.

the class RegistryHelper method generateBlockItem.

private void generateBlockItem(ForgeRegistryHelper<Block> registry, Block block) {
    final Item.Properties itemProps = block instanceof IBookshelfBlock ? ((IBookshelfBlock) block).getItemBlockProperties() : new Item.Properties();
    if (itemProps != null) {
        final Item item = new BlockItem(block, itemProps);
        item.setRegistryName(block.getRegistryName());
        this.items.register(item);
    }
}
Also used : Item(net.minecraft.item.Item) BlockItem(net.minecraft.item.BlockItem) IBookshelfBlock(net.darkhax.bookshelf.block.IBookshelfBlock) BlockItem(net.minecraft.item.BlockItem)

Example 5 with BlockItem

use of net.minecraft.item.BlockItem in project BluePower by Qmunity.

the class GuiAnimatedStat method render.

@Override
public void render(MatrixStack matrixStack, FontRenderer fontRenderer, float zLevel, float partialTicks) {
    int renderBaseX = (int) (oldBaseX + (baseX - oldBaseX) * partialTicks);
    int renderAffectedY = (int) (oldAffectedY + (affectedY - oldAffectedY) * partialTicks);
    int renderWidth = (int) (oldWidth + (width - oldWidth) * partialTicks);
    int renderHeight = (int) (oldHeight + (height - oldHeight) * partialTicks);
    if (leftSided)
        renderWidth *= -1;
    AbstractGui.fill(matrixStack, renderBaseX, renderAffectedY, /* + 1 */
    renderBaseX + renderWidth, /*- 1*/
    renderAffectedY + renderHeight, backGroundColor);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glLineWidth(3.0F);
    GL11.glColor4d(0, 0, 0, 1);
    Tessellator tess = Tessellator.getInstance();
    BufferBuilder buff = tess.getBuilder();
    buff.begin(GL11.GL_LINE_LOOP, DefaultVertexFormats.POSITION_TEX);
    buff.vertex(renderBaseX, renderAffectedY, zLevel);
    buff.vertex(renderBaseX + renderWidth, renderAffectedY, zLevel);
    buff.vertex(renderBaseX + renderWidth, renderAffectedY + renderHeight, zLevel);
    buff.vertex(renderBaseX, renderAffectedY + renderHeight, zLevel);
    tess.end();
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    if (leftSided)
        renderWidth *= -1;
    // if done expanding, draw the information
    if (doneExpanding) {
        GL11.glPushMatrix();
        GL11.glTranslated(renderBaseX + (leftSided ? -renderWidth : 16), renderAffectedY, 0);
        GL11.glScaled(textSize, textSize, textSize);
        GL11.glTranslated(-renderBaseX - (leftSided ? -renderWidth : 16), -renderAffectedY, 0);
        fontRenderer.drawShadow(matrixStack, title, renderBaseX + (leftSided ? -renderWidth + 2 : 18), renderAffectedY + 2, 0xFFFF00);
        for (int i = 0; i < textList.size(); i++) {
            if (textList.get(i).contains("\u00a70") || textList.get(i).contains(TextFormatting.DARK_RED.toString())) {
                fontRenderer.draw(matrixStack, textList.get(i), renderBaseX + (leftSided ? -renderWidth + 2 : 18), renderAffectedY + i * 10 + 12, 0xFFFFFF);
            } else {
                fontRenderer.drawShadow(matrixStack, textList.get(i), renderBaseX + (leftSided ? -renderWidth + 2 : 18), renderAffectedY + i * 10 + 12, 0xFFFFFF);
            }
        }
        GL11.glPopMatrix();
    }
    if (renderHeight > 16 && renderWidth > 16) {
        GL11.glColor4d(1, 1, 1, 1);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        if (iStack == null) {
            if (iconResLoc == null)
                iconResLoc = new ResourceLocation(texture);
            drawTexture(iconResLoc, renderBaseX - (leftSided ? 16 : 0), renderAffectedY);
        } else if (gui != null || !(iStack.getItem() instanceof BlockItem)) {
            renderItem(fontRenderer, renderBaseX - (leftSided ? 16 : 0), renderAffectedY, iStack);
        }
    }
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) ResourceLocation(net.minecraft.util.ResourceLocation) BlockItem(net.minecraft.item.BlockItem)

Aggregations

BlockItem (net.minecraft.item.BlockItem)11 ItemStack (net.minecraft.item.ItemStack)5 Item (net.minecraft.item.Item)4 Block (net.minecraft.block.Block)2 BlockState (net.minecraft.block.BlockState)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 BlockRayTraceResult (net.minecraft.util.math.BlockRayTraceResult)2 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)2 BlockBPMicroblock (com.bluepowermod.block.BlockBPMicroblock)1 ItemSaw (com.bluepowermod.item.ItemSaw)1 BlockItemUseContextPublic (com.cjm721.overloaded.util.BlockItemUseContextPublic)1 ModBlocks (com.oitsjustjose.geolosys.common.blocks.ModBlocks)1 Nonnull (javax.annotation.Nonnull)1 ExperienceDroppingBlock (logictechcorp.libraryex.block.ExperienceDroppingBlock)1 FireSustainingBlock (logictechcorp.libraryex.block.FireSustainingBlock)1 ModBreakableBlock (logictechcorp.libraryex.block.ModBreakableBlock)1 PathBlock (logictechcorp.libraryex.block.PathBlock)1 IBookshelfBlock (net.darkhax.bookshelf.block.IBookshelfBlock)1 ClientPlayerEntity (net.minecraft.client.entity.player.ClientPlayerEntity)1 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)1