Posted June 6, 20169 yr Quick question, is there an easy way to render a block model .json file in a TESR without having to create a block attached to that model? No signature for you!
June 7, 20169 yr Author So I got a bit of a problem that seems really weird. My IDE (intellij) is complaining that I'm accessing a non-static method (getModel()) from a static context. But my TESR class is non-static. What am I doing wrong here? TESR (renderBlood() is the method to look at): package com.darkhawx.planck.main.tileEntities; import com.darkhawx.planck.main.PlanckMod; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.*; import net.minecraft.client.renderer.block.model.IBakedModel; import net.minecraft.client.renderer.block.model.ItemCameraTransforms; import net.minecraft.client.renderer.block.model.ModelManager; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import net.minecraftforge.client.model.IModel; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.client.model.ModelLoaderRegistry; import net.minecraftforge.common.model.TRSRTransformation; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import org.lwjgl.opengl.GL11; import java.util.List; @SideOnly(Side.CLIENT) public class TileAltarRenderer extends TileEntitySpecialRenderer<TileAltar> { private IModel model; private IBakedModel bakedModel; private IBakedModel getBakedModel() { // Since we cannot bake in preInit() we do lazy baking of the model as soon as we need it // for rendering if (bakedModel == null) { try { model = ModelLoaderRegistry.getModel(new ResourceLocation(PlanckMod.MODID, "block/altar")); } catch (Exception e) { throw new RuntimeException(e); } bakedModel = model.bake(TRSRTransformation.identity(), DefaultVertexFormats.ITEM, location -> Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString())); } return bakedModel; } @Override public void renderTileEntityAt(TileAltar te, double x, double y, double z, float partialTicks, int destroyStage) { GlStateManager.pushAttrib(); GlStateManager.pushMatrix(); // Translate to the location of our tile entity GlStateManager.translate(x, y, z); GlStateManager.disableRescaleNormal(); renderModel(te); if (te.isCrafting()) { int craftingProgress = te.getCraftingTime(); // do special crap, otherwise } renderItems(te); renderBlood(te); GlStateManager.popMatrix(); GlStateManager.popAttrib(); } private void renderBlood(TileAltar te) { GlStateManager.pushMatrix(); RenderHelper.disableStandardItemLighting(); IBakedModel m = ModelManager.getModel(new ModelResourceLocation(PlanckMod.MODID, "block/bloodSphere")); World world = te.getWorld(); this.bindTexture(TextureMap.locationBlocksTexture); if (Minecraft.isAmbientOcclusionEnabled()) { GlStateManager.shadeModel(GL11.GL_SMOOTH); } else { GlStateManager.shadeModel(GL11.GL_FLAT); } float scale = te.getBlood()/2500.0F; if (scale < 0.0F) { scale = 0.0F; } else if (scale > 0.75F) { scale = 0.75F; } GlStateManager.translate(te.getPos().getX() + 0.5D, te.getPos().getY() + 1.5D, te.getPos().getZ() + 0.5D); GlStateManager.scale(scale, scale, scale); Tessellator tessellator = Tessellator.getInstance(); tessellator.getBuffer().begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK); Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelRenderer().renderModel(world, m, world.getBlockState(te.getPos()), te.getPos(), Tessellator.getInstance().getBuffer(), false, 0); tessellator.draw(); RenderHelper.enableStandardItemLighting(); GlStateManager.popMatrix(); } private void renderModel(TileAltar te) { GlStateManager.pushMatrix(); RenderHelper.disableStandardItemLighting(); this.bindTexture(TextureMap.locationBlocksTexture); if (Minecraft.isAmbientOcclusionEnabled()) { GlStateManager.shadeModel(GL11.GL_SMOOTH); } else { GlStateManager.shadeModel(GL11.GL_FLAT); } World world = te.getWorld(); // Translate back to local view coordinates so that we can do the actual rendering here GlStateManager.translate(-te.getPos().getX(), -te.getPos().getY(), -te.getPos().getZ()); Tessellator tessellator = Tessellator.getInstance(); tessellator.getBuffer().begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK); Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelRenderer().renderModel(world, getBakedModel(), world.getBlockState(te.getPos()), te.getPos(), Tessellator.getInstance().getBuffer(), false, 0); tessellator.draw(); RenderHelper.enableStandardItemLighting(); GlStateManager.popMatrix(); } private void renderItems(TileAltar te) { List<ItemStack> stack = te.getItems(); int i = 0; double x = 0.0D; double z = 0.0D; int angle = 0; float scale = 0.20F; float iScale = 4.0F; if (stack.size() > 0) { for (ItemStack item : stack) { RenderHelper.enableStandardItemLighting(); GlStateManager.enableLighting(); GlStateManager.pushMatrix(); //TODO Clean up this crap if (!(item.getItem() instanceof ItemBlock)) { GlStateManager.translate(0.5D, 1.01D, 0.5D); } else { GlStateManager.translate(0.5D, 1.1D, 0.5D); } switch (i) { case 0: x = 0.4D; z = 0.0D; break; case 1: x = 0.23D; z = 0.23D; break; case 2: x = 0.0D; z = 0.4D; break; case 3: x = -0.23D; z = 0.23D; break; case 4: x = -0.4D; z = 0.0D; break; case 5: x = -0.23D; z = -0.23D; break; case 6: x = 0.0D; z = -0.4D; break; case 7: x = 0.23D; z = -0.23D; } i++; GlStateManager.translate(x, 0.0D, z); GlStateManager.scale(scale, scale, scale); if (!(item.getItem() instanceof ItemBlock)) { GlStateManager.rotate(90, 1.0F, 0.0F, 0.0F); } Minecraft.getMinecraft().getRenderItem().renderItem(item, ItemCameraTransforms.TransformType.NONE); // GlStateManager.scale(iScale, iScale, iScale); // GlStateManager.translate(-x, 0.0D, -z); RenderHelper.disableStandardItemLighting(); GlStateManager.popMatrix(); } } } } Where I register the model, I think this might be a problem. ModelBakery.registerItemVariants(ModItems.sacrificialKnife, new ResourceLocation(PlanckMod.MODID, "block/bloodSphere")); No signature for you!
June 7, 20169 yr The # in "ModelManager#getModel" means "you need an instance of the ModelManager class in order to use this method." e.g. World#getBlock() or TileEntity#onUpdate() Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
June 7, 20169 yr Author The # in "ModelManager#getModel" means "you need an instance of the ModelManager class in order to use this method." e.g. World#getBlock() or TileEntity#onUpdate() Ah, I was not familiar with that notation, so I simply thought it was a weird way of typing ModelManager.getModel(). Thus my question becomes, how would I obtain an instance of ModelManager? My intuition says to not simply create a new instance of ModelManager but use an existing one, but I have no idea where to look... No signature for you!
June 7, 20169 yr The # in "ModelManager#getModel" means "you need an instance of the ModelManager class in order to use this method." e.g. World#getBlock() or TileEntity#onUpdate() Ah, I was not familiar with that notation, so I simply thought it was a weird way of typing ModelManager.getModel(). Thus my question becomes, how would I obtain an instance of ModelManager? My intuition says to not simply create a new instance of ModelManager but use an existing one, but I have no idea where to look... Use your IDE to find where ModelManager is instantiated and where the instance is stored. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.