Search in sources :

Example 1 with ItemScroll

use of com.axanthic.loi.items.ItemScroll in project Lands-of-Icaria by Axanthic-Game-Studios.

the class ClientProxy method registerModels.

@SubscribeEvent
public void registerModels(ModelRegistryEvent event) {
    for (ItemBlock block : Resources.blocks) {
        if (block.getBlock() instanceof BlockFlower || block.getBlock() instanceof BlockTallGrass || block.getBlock() instanceof BlockHerb) {
            for (int i = 0; i < ((IBlockMeta) block.getBlock()).getNames().length; i++) {
                ModelLoader.setCustomModelResourceLocation(block, i, new ModelResourceLocation(block.getRegistryName() + "_inv", "type=" + ((IBlockMeta) block.getBlock()).getNames()[i]));
            }
        } else if (block.getBlock() instanceof BlockLeafOlives) {
            // olive leaves are weird
            ModelLoader.setCustomModelResourceLocation(block, 0, new ModelResourceLocation(block.getRegistryName(), "check_decay=false,decayable=false,type=" + ((IBlockMeta) block.getBlock()).getNameForMeta(0)));
            ModelLoader.setCustomModelResourceLocation(block, 1, new ModelResourceLocation(block.getRegistryName(), "check_decay=false,decayable=false,type=" + ((IBlockMeta) block.getBlock()).getNameForMeta(1)));
        } else if (block instanceof ItemBlockMeta) {
            ModelLoader.setCustomMeshDefinition(block, new ItemMeshDefinition() {

                @Override
                public ModelResourceLocation getModelLocation(ItemStack stack) {
                    return new ModelResourceLocation(block.getRegistryName(), "type=" + ((IBlockMeta) block.getBlock()).getNameForMeta(stack.getMetadata()));
                }
            });
        } else if (block.getBlock() instanceof BlockLeaf || block.getBlock() instanceof BlockSapling || block.getBlock() instanceof BlockCustomWorkbench) {
            String[] path = block.getRegistryName().getResourcePath().split("_");
            if (block.getBlock() instanceof BlockSapling)
                ModelLoader.setCustomModelResourceLocation(block, 0, new ModelResourceLocation(new ResourceLocation(block.getRegistryName().getResourceDomain(), "wood_" + path[1]), "inv_" + path[0]));
            else
                ModelLoader.setCustomModelResourceLocation(block, 0, new ModelResourceLocation(new ResourceLocation(block.getRegistryName().getResourceDomain(), "wood_" + path[1]), path[0]));
            ModelLoader.setCustomStateMapper(block.getBlock(), new StateMapperBase() {

                @Override
                public ModelResourceLocation getModelResourceLocation(IBlockState state) {
                    return new ModelResourceLocation(new ResourceLocation(block.getRegistryName().getResourceDomain(), "wood_" + path[1]), path[0]);
                }
            });
        } else if (block.getBlock() instanceof BlockLog) {
            String[] path = block.getRegistryName().getResourcePath().split("_");
            ResourceLocation loc = new ResourceLocation(block.getRegistryName().getResourceDomain(), "wood_" + path[1]);
            ModelLoader.setCustomModelResourceLocation(block, 0, new ModelResourceLocation(loc, path[0] + "_y"));
            ModelLoader.setCustomStateMapper(block.getBlock(), new StateMapperBase() {

                @Override
                public ModelResourceLocation getModelResourceLocation(IBlockState state) {
                    String axis = "bark";
                    int meta = ((BlockLog) block.getBlock()).getMetaFromState(state);
                    if (meta == 0) {
                        axis = "y";
                    } else if (meta == 4) {
                        axis = "x";
                    } else if (meta == 8) {
                        axis = "z";
                    }
                    return new ModelResourceLocation(loc, path[0] + "_" + axis);
                }
            });
        } else if (block.getBlock() instanceof BlockFluidCustom) {
            ModelLoader.setCustomModelResourceLocation(block, 0, new ModelResourceLocation(block.getRegistryName(), "normal"));
            ModelLoader.setCustomStateMapper(block.getBlock(), new StateMapperBase() {

                @Override
                public ModelResourceLocation getModelResourceLocation(IBlockState state) {
                    return new ModelResourceLocation(block.getRegistryName(), "normal");
                }
            });
        } else
            ModelLoader.setCustomModelResourceLocation(block, 0, new ModelResourceLocation(block.getRegistryName(), "inventory"));
    }
    for (Item item : Resources.items) {
        if (item instanceof IItemMeta) {
            for (int i = 0; i < ((IItemMeta) item).getNames().length; i++) {
                ModelLoader.setCustomModelResourceLocation(item, i, new ModelResourceLocation(item.getRegistryName(), "type=" + ((IItemMeta) item).getNames()[i]));
            }
        } else if (item instanceof ItemTool || item instanceof ItemSword || item instanceof ItemCustomArmor) {
            String[] path = item.getRegistryName().getResourcePath().split("_");
            ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(new ResourceLocation(item.getRegistryName().getResourceDomain(), "tool_" + path[1]), path[0]));
        } else if (item instanceof ItemSpell) {
            ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(new ResourceLocation(item.getRegistryName().getResourceDomain(), "spell"), ((ItemSpell) item).getName()));
        } else if (item instanceof ItemScroll) {
            ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(new ResourceLocation(item.getRegistryName().getResourceDomain(), "spell_scroll"), ((ItemScroll) item).getName()));
        } else if (item instanceof ItemConcoctionFlask) {
            ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(new ResourceLocation(item.getRegistryName().getResourceDomain(), "concoction_flask_filled"), "inventory"));
        } else
            ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(item.getRegistryName(), "inventory"));
    }
    // register special item renderers here
    Resources.saltedFood.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.grinder.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.mobHeadRevenant.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.mobHeadArachne.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.mobHeadArachneDrone.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.mobHeadMyrmeke.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.mobHeadCerver.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.mobHeadArganHound.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.mobHeadForesthagPlane.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.mobHeadForesthagPopulus.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.mobHeadForesthagCypress.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.mobHeadForesthagFir.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.mobHeadForesthagOlive.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.mobHeadForesthagLaurel.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.mobHeadForesthagDroughtroot.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.mobHeadAeternae.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.mobHeadCatoblepas.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    Resources.mobHeadSow.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
    for (ItemScroll scroll : Resources.scrolls) scroll.setTileEntityItemStackRenderer(LOIItemStackRenderer.LOIInstance);
}
Also used : StateMapperBase(net.minecraft.client.renderer.block.statemap.StateMapperBase) BlockLeaf(com.axanthic.loi.blocks.BlockLeaf) IBlockMeta(com.axanthic.loi.blocks.IBlockMeta) BlockLeafOlives(com.axanthic.loi.blocks.BlockLeafOlives) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) BlockCustomWorkbench(com.axanthic.loi.blocks.BlockCustomWorkbench) Item(net.minecraft.item.Item) ItemSpell(com.axanthic.loi.items.ItemSpell) BlockSapling(com.axanthic.loi.blocks.BlockSapling) BlockHerb(com.axanthic.loi.blocks.BlockHerb) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) ItemConcoctionFlask(com.axanthic.loi.items.ItemConcoctionFlask) ItemSword(net.minecraft.item.ItemSword) ItemTool(net.minecraft.item.ItemTool) IBlockState(net.minecraft.block.state.IBlockState) BlockLog(com.axanthic.loi.blocks.BlockLog) IItemMeta(com.axanthic.loi.items.IItemMeta) ItemBlock(net.minecraft.item.ItemBlock) BlockFlower(com.axanthic.loi.blocks.BlockFlower) ItemCustomArmor(com.axanthic.loi.items.ItemCustomArmor) ItemMeshDefinition(net.minecraft.client.renderer.ItemMeshDefinition) BlockTallGrass(com.axanthic.loi.blocks.BlockTallGrass) ItemBlockMeta(com.axanthic.loi.items.ItemBlockMeta) ItemStack(net.minecraft.item.ItemStack) ItemScroll(com.axanthic.loi.items.ItemScroll) BlockFluidCustom(com.axanthic.loi.blocks.BlockFluidCustom) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with ItemScroll

use of com.axanthic.loi.items.ItemScroll in project Lands-of-Icaria by Axanthic-Game-Studios.

the class LOIItemStackRenderer method renderByItem.

public void renderByItem(ItemStack stack, float partialTicks) {
    Item item = stack.getItem();
    if (item instanceof ItemBlockMobHead) {
        if (TileEntitySpecialRendererMobHead.instance != null) {
            GlStateManager.pushMatrix();
            GlStateManager.disableCull();
            TileEntitySpecialRendererMobHead.instance.renderSkull(0.0F, 0.1F, 0.0F, EnumFacing.DOWN, 0.0F, ((BlockMobHead) ((ItemBlock) item).getBlock()).name, -1, 1.6F);
            GlStateManager.enableCull();
            GlStateManager.popMatrix();
        }
    }
    if (item instanceof ItemSaltedFood) {
        GlStateManager.pushMatrix();
        GlStateManager.translate(0.5F, 0.5F, 0.5F);
        if (stack.hasTagCompound()) {
            ItemStack foodStack = ItemSaltedFood.getContainedItem(stack.getTagCompound());
            if (!foodStack.isEmpty())
                Minecraft.getMinecraft().getRenderItem().renderItem(foodStack, ItemCameraTransforms.TransformType.NONE);
        }
        Minecraft.getMinecraft().getRenderItem().renderItem(saltOverlay, ItemCameraTransforms.TransformType.NONE);
        GlStateManager.popMatrix();
    }
    if (item instanceof ItemBlock && ((ItemBlock) item).getBlock() instanceof BlockGrinder) {
        if (TileEntitySpecialRendererGrinder.instance != null) {
            GlStateManager.pushMatrix();
            GlStateManager.disableCull();
            TileEntitySpecialRendererGrinder.instance.renderInventory();
            GlStateManager.enableCull();
            GlStateManager.popMatrix();
        }
    }
    if (item instanceof ItemScroll) {
        ItemScroll scroll = ((ItemScroll) item);
        if (!Minecraft.getMinecraft().player.isInvisible()) {
            EnumHand rightHand = EnumHand.MAIN_HAND;
            EnumHand leftHand = EnumHand.OFF_HAND;
            if (Minecraft.getMinecraft().player.getPrimaryHand() == EnumHandSide.LEFT) {
                rightHand = EnumHand.OFF_HAND;
                leftHand = EnumHand.MAIN_HAND;
            }
            // render player arms
            if (BakedModelScroll.transform == TransformType.FIRST_PERSON_RIGHT_HAND) {
                GlStateManager.translate(((float) Minecraft.getMinecraft().displayWidth) / ((float) Minecraft.getMinecraft().displayHeight) * 0.5F, 0.9F, 0.4F);
                GlStateManager.disableCull();
                GlStateManager.pushMatrix();
                GlStateManager.rotate(90.0F, 0.0F, 1.0F, 0.0F);
                if (Minecraft.getMinecraft().player.getHeldItem(leftHand).isEmpty() && rightHand != EnumHand.OFF_HAND)
                    renderArm(EnumHandSide.LEFT);
                GlStateManager.translate(0.0F, 0.3F, -0.7F);
                GlStateManager.rotate(-60.0F, 1.0F, 0.0F, 0.0F);
                renderArm(EnumHandSide.RIGHT);
                GlStateManager.popMatrix();
                GlStateManager.enableCull();
            }
            if (BakedModelScroll.transform == TransformType.FIRST_PERSON_LEFT_HAND) {
                GlStateManager.translate(((float) Minecraft.getMinecraft().displayWidth) / ((float) Minecraft.getMinecraft().displayHeight) * -0.5F + 1.68F, 0.9F, 0.4F);
                GlStateManager.disableCull();
                GlStateManager.pushMatrix();
                GlStateManager.rotate(90.0F, 0.0F, 1.0F, 0.0F);
                GlStateManager.translate(-0.1F, 0.03F, -0.7F);
                if (Minecraft.getMinecraft().player.getHeldItem(rightHand).isEmpty() && leftHand != EnumHand.OFF_HAND)
                    renderArm(EnumHandSide.RIGHT);
                GlStateManager.translate(0.1F, 0.27F, 0.7F);
                GlStateManager.rotate(60.0F, 1.0F, 0.0F, 0.0F);
                renderArm(EnumHandSide.LEFT);
                GlStateManager.popMatrix();
                GlStateManager.enableCull();
            }
        }
        // render scroll background
        GlStateManager.scale(0.76F, 0.76F, 0.76F);
        GlStateManager.disableLighting();
        Minecraft.getMinecraft().getTextureManager().bindTexture(RES_SCROLL_BACKGROUND);
        Tessellator tessellator = Tessellator.getInstance();
        BufferBuilder bufferbuilder = tessellator.getBuffer();
        GlStateManager.translate(-1.0F, -0.6F, -0.2F);
        GlStateManager.scale(0.0078125F, 0.0078125F, 0.0078125F);
        bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX);
        bufferbuilder.pos(0.0D, 0.0D, 0.0D).tex(0.0D, 1.0D).endVertex();
        bufferbuilder.pos(142.0D, 0.0D, 0.0D).tex(1.0D, 1.0D).endVertex();
        bufferbuilder.pos(142.0D, 142.0D, 0.0D).tex(1.0D, 0.0D).endVertex();
        bufferbuilder.pos(0.0D, 142.0D, 0.0D).tex(0.0D, 0.0D).endVertex();
        tessellator.draw();
        GlStateManager.translate(71.0F, 44.5F, 0.01F);
        // render scroll title
        GlStateManager.pushMatrix();
        GlStateManager.rotate(180.0F, 1.0F, 0.0F, 0.0F);
        FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
        String title = I18n.translateToLocal("spell." + scroll.getName() + ".name");
        fontRenderer.drawString(title, -fontRenderer.getStringWidth(title) / 2, -60, 0x82735A);
        GlStateManager.popMatrix();
        GlStateManager.scale(25.0F, 25.0F, 0.001F);
        // render ingredients
        Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
        GlStateManager.pushMatrix();
        GlStateManager.scale(0.6F, 0.6F, 1.0F);
        GlStateManager.translate(0.55F - scroll.getRecipe().order.size() * 0.55F, 2.5F, 0.0F);
        for (int i = 0; i < scroll.getRecipe().order.size(); ++i) {
            Minecraft.getMinecraft().getRenderItem().renderItem(scroll.getRecipe().getInputs().get(scroll.getRecipe().order.get(i)).getMatchingStacks()[0], ItemCameraTransforms.TransformType.GUI);
            GlStateManager.translate(1.1F, 0.0F, 0.0F);
        }
        GlStateManager.popMatrix();
        // render result
        Minecraft.getMinecraft().getRenderItem().renderItem(scroll.getRecipe().recipeOutput, ItemCameraTransforms.TransformType.GUI);
        GlStateManager.enableLighting();
    }
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) BlockGrinder(com.axanthic.loi.blocks.BlockGrinder) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) ItemBlock(net.minecraft.item.ItemBlock) Item(net.minecraft.item.Item) ItemBlockMobHead(com.axanthic.loi.items.ItemBlockMobHead) EnumHand(net.minecraft.util.EnumHand) ItemSaltedFood(com.axanthic.loi.items.ItemSaltedFood) FontRenderer(net.minecraft.client.gui.FontRenderer) ItemStack(net.minecraft.item.ItemStack) ItemScroll(com.axanthic.loi.items.ItemScroll)

Aggregations

ItemScroll (com.axanthic.loi.items.ItemScroll)2 Item (net.minecraft.item.Item)2 ItemBlock (net.minecraft.item.ItemBlock)2 ItemStack (net.minecraft.item.ItemStack)2 BlockCustomWorkbench (com.axanthic.loi.blocks.BlockCustomWorkbench)1 BlockFlower (com.axanthic.loi.blocks.BlockFlower)1 BlockFluidCustom (com.axanthic.loi.blocks.BlockFluidCustom)1 BlockGrinder (com.axanthic.loi.blocks.BlockGrinder)1 BlockHerb (com.axanthic.loi.blocks.BlockHerb)1 BlockLeaf (com.axanthic.loi.blocks.BlockLeaf)1 BlockLeafOlives (com.axanthic.loi.blocks.BlockLeafOlives)1 BlockLog (com.axanthic.loi.blocks.BlockLog)1 BlockSapling (com.axanthic.loi.blocks.BlockSapling)1 BlockTallGrass (com.axanthic.loi.blocks.BlockTallGrass)1 IBlockMeta (com.axanthic.loi.blocks.IBlockMeta)1 IItemMeta (com.axanthic.loi.items.IItemMeta)1 ItemBlockMeta (com.axanthic.loi.items.ItemBlockMeta)1 ItemBlockMobHead (com.axanthic.loi.items.ItemBlockMobHead)1 ItemConcoctionFlask (com.axanthic.loi.items.ItemConcoctionFlask)1 ItemCustomArmor (com.axanthic.loi.items.ItemCustomArmor)1