tattyseal Posted April 20, 2014 Posted April 20, 2014 Hello. I have a customizable block, and when it is right clicked with an ItemBlock it changes the blocks texture depending on its mode (Shift-RightClick changes it Border/Filler) When it is placed it looks like this: When right clicked with something other than glass (Glass sets a custom texture) it will look like this My Block LEFT What I want the texture inside to look like RIGHT TileEntity Code: package org.db.tileentity; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; import net.minecraft.network.Packet; import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; public class TileEntityDynamicBlock extends TileEntity { public int meta; public int blockMeta; public boolean mode; public TileEntityDynamicBlock() { meta = 1; blockMeta = 1; mode = false; } public void writeToNBT(NBTTagCompound tag) { tag.setInteger("meta", meta); tag.setInteger("blockMeta", blockMeta); tag.setBoolean("mode", mode); } public void readFromNBT(NBTTagCompound tag) { meta = tag.getInteger("meta"); blockMeta = tag.getInteger("blockMeta"); mode = tag.getBoolean("mode"); } @Override public void updateEntity() { if(meta == 0) { meta = 1; } if(blockMeta == 0) { blockMeta = 1; } } @Override public Packet getDescriptionPacket() { NBTTagCompound nbt = new NBTTagCompound(); this.writeToNBT(nbt); return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, nbt); } @Override public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) { readFromNBT(packet.func_148857_g()); } } Renderer Code: package org.db.tileentity; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.entity.Entity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; public class RenderDynamicBlock extends TileEntitySpecialRenderer { public ModelDynamicBlock model; public ModelDynamicBlockFiller glass; public RenderDynamicBlock() { this.model = new ModelDynamicBlock(); this.glass = new ModelDynamicBlockFiller(); } @Override public void renderTileEntityAt(TileEntity te, double x, double y, double z, float scale) { glass = new ModelDynamicBlockFiller(); GL11.glDisable(GL11.GL_CULL_FACE); GL11.glPushMatrix(); GL11.glTranslatef((float) x + 0.5F, (float) y+1.5f, (float) z + 0.5F); GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F); TileEntityDynamicBlock teg = (TileEntityDynamicBlock) te; boolean isTeNull = teg == null; boolean isIconNull = isTeNull ? true : Block.getBlockById(teg.meta).getIcon(0, 0) == null; boolean isNull = isIconNull ? true : false; String icon = isNull ? "minecraft:stone" : Block.getBlockById(teg.meta).getIcon(0, 0).getIconName(); if(icon.contains(":")) { Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation(icon.split(":")[0].toLowerCase(), "textures/blocks/" + icon.split(":")[1] + ".png")); } else { Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation("textures/blocks/" + icon + ".png")); } float f = 0.0625F; this.model.BackDown.render(f); this.model.BackUp.render(f); this.model.FrontDown.render(f); this.model.FrontUp.render(f); this.model.RightUp.render(f); this.model.RightDown.render(f); this.model.RightFront.render(f); this.model.RightBack.render(f); this.model.LeftFront.render(f); this.model.LeftBack.render(f); this.model.LeftUp.render(f); this.model.LeftDown.render(f); icon = Block.getBlockById(teg.blockMeta).getIcon(0, 0).getIconName(); if(icon.contains(":")) { Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation(icon.split(":")[0].toLowerCase(), "textures/blocks/" + icon.split(":")[1] + ".png")); } else { if(icon == "glass") { Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation("db", "models/glass.png")); } else { Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation("textures/blocks/" + icon + ".png")); } } this.glass.render((Entity) null, 0.0625F, 0.0625F, 0.0625F, 0.0625F, 0.0625F, 0.0625F); GL11.glPopMatrix(); } } ModelFiller Code: package org.db.tileentity; import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelRenderer; import net.minecraft.entity.Entity; public class ModelDynamicBlockFiller extends ModelBase { public static ModelRenderer Left; public static ModelRenderer Back; public static ModelRenderer Right; public static ModelRenderer Bottom; public static ModelRenderer Front; public static ModelRenderer Top; public ModelDynamicBlockFiller() { textureWidth = 32; textureHeight = 32; Left = new ModelRenderer(this, 0, 0); Left.addBox(0F, 0F, 0F, 1, 14, 14); Left.setRotationPoint(7F, 9F, -7F); Left.setTextureSize(64, 64); Left.mirror = true; setRotation(Left, 0F, 0F, 0F); Back = new ModelRenderer(this, 0, 0); Back.addBox(0F, 0F, 0F, 14, 14, 1); Back.setRotationPoint(-7F, 9F, 7F); Back.setTextureSize(64, 64); Back.mirror = true; setRotation(Back, 0F, 0F, 0F); Right = new ModelRenderer(this, 0, 0); Right.addBox(0F, 0F, 0F, 1, 14, 14); Right.setRotationPoint(-8F, 9F, -7F); Right.setTextureSize(64, 64); Right.mirror = true; setRotation(Right, 0F, 0F, 0F); Bottom = new ModelRenderer(this, 0, 0); Bottom.addBox(0F, 0F, 0F, 14, 14, 1); Bottom.setRotationPoint(-7F, 9F, -7F); Bottom.setTextureSize(64, 64); Bottom.mirror = true; setRotation(Bottom, 1.570796F, 0F, 0F); Front = new ModelRenderer(this, 0, 0); Front.addBox(0F, 0F, 0F, 14, 14, 1); Front.setRotationPoint(-7F, 9F, -8F); Front.setTextureSize(64, 64); Front.mirror = true; setRotation(Front, 0F, 0F, 0F); Top = new ModelRenderer(this, 0, 0); Top.addBox(0F, 0F, 0F, 14, 14, 1); Top.setRotationPoint(-7F, 24F, -7F); Top.setTextureSize(64, 64); Top.mirror = true; setRotation(Top, 1.570796F, 0F, 0F); } public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) { super.render(entity, f, f1, f2, f3, f4, f5); setRotationAngles(f, f1, f2, f3, f4, f5, entity); Left.render(f5); Back.render(f5); Right.render(f5); Bottom.render(f5); Front.render(f5); Top.render(f5); } private void setRotation(ModelRenderer model, float x, float y, float z) { model.rotateAngleX = x; model.rotateAngleY = y; model.rotateAngleZ = z; } public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity e) { super.setRotationAngles(f, f1, f2, f3, f4, f5, e); } } ModelBorder Code: package org.db.tileentity; import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelRenderer; import net.minecraft.entity.Entity; public class ModelDynamicBlock extends ModelBase { public static ModelRenderer FrontDown; public static ModelRenderer LeftBack; public static ModelRenderer LeftFront; public static ModelRenderer RightFront; public static ModelRenderer RightBack; public static ModelRenderer FrontUp; public static ModelRenderer LeftDown; public static ModelRenderer BackDown; public static ModelRenderer BackUp; public static ModelRenderer LeftUp; public static ModelRenderer RightUp; public static ModelRenderer RightDown; public static ModelRenderer Left; public static ModelRenderer Right; public static ModelRenderer Top; public static ModelRenderer Bottom; public ModelDynamicBlock() { textureWidth = 64; textureHeight = 32; FrontDown = new ModelRenderer(this, 0, 0); FrontDown.addBox(0F, 0F, 0F, 16, 1, 1); FrontDown.setRotationPoint(-8F, 23F, -8F); FrontDown.setTextureSize(64, 32); FrontDown.mirror = true; setRotation(FrontDown, 0F, 0F, 0F); LeftBack = new ModelRenderer(this, 0, 0); LeftBack.addBox(0F, 0F, 0F, 1, 16, 1); LeftBack.setRotationPoint(7F, 8F, 7F); LeftBack.setTextureSize(64, 32); LeftBack.mirror = true; setRotation(LeftBack, 0F, 0F, 0F); LeftFront = new ModelRenderer(this, 13, 0); LeftFront.addBox(0F, 0F, 0F, 1, 16, 1); LeftFront.setRotationPoint(7F, 8F, -8F); LeftFront.setTextureSize(64, 32); LeftFront.mirror = true; setRotation(LeftFront, 0F, 0F, 0F); RightFront = new ModelRenderer(this, 40, 0); RightFront.addBox(0F, 0F, 0F, 1, 16, 1); RightFront.setRotationPoint(-8F, 8F, -8F); RightFront.setTextureSize(64, 32); RightFront.mirror = true; setRotation(RightFront, 0F, 0F, 0F); RightBack = new ModelRenderer(this, 0, 0); RightBack.addBox(0F, 0F, 0F, 1, 16, 1); RightBack.setRotationPoint(-8F, 8F, 7F); RightBack.setTextureSize(64, 32); RightBack.mirror = true; setRotation(RightBack, 0F, 0F, 0F); FrontUp = new ModelRenderer(this, 30, 30); FrontUp.addBox(0F, 0F, 0F, 16, 1, 1); FrontUp.setRotationPoint(-8F, 8F, -8F); FrontUp.setTextureSize(64, 32); FrontUp.mirror = true; setRotation(FrontUp, 0F, 0F, 0F); LeftDown = new ModelRenderer(this, 0, 0); LeftDown.addBox(0F, 0F, 0F, 1, 1, 16); LeftDown.setRotationPoint(7F, 23F, -8F); LeftDown.setTextureSize(64, 32); LeftDown.mirror = true; setRotation(LeftDown, 0F, 0F, 0F); BackDown = new ModelRenderer(this, 0, 0); BackDown.addBox(0F, 0F, 0F, 16, 1, 1); BackDown.setRotationPoint(-8F, 23F, 7F); BackDown.setTextureSize(64, 32); BackDown.mirror = true; setRotation(BackDown, 0F, 0F, 0F); BackUp = new ModelRenderer(this, 29, 17); BackUp.addBox(0F, 0F, 0F, 16, 1, 1); BackUp.setRotationPoint(-8F, 8F, 7F); BackUp.setTextureSize(64, 32); BackUp.mirror = true; setRotation(BackUp, 0F, 0F, 0F); LeftUp = new ModelRenderer(this, 30, 15); LeftUp.addBox(0F, 0F, 0F, 1, 1, 16); LeftUp.setRotationPoint(7F, 8F, -8F); LeftUp.setTextureSize(64, 32); LeftUp.mirror = true; setRotation(LeftUp, 0F, 0F, 0F); RightUp = new ModelRenderer(this, 30, 0); RightUp.addBox(0F, 0F, 0F, 1, 1, 16); RightUp.setRotationPoint(-8F, 8F, -8F); RightUp.setTextureSize(64, 32); RightUp.mirror = true; setRotation(RightUp, 0F, 0F, 0F); RightDown = new ModelRenderer(this, 0, 0); RightDown.addBox(0F, 0F, 0F, 1, 1, 16); RightDown.setRotationPoint(-8F, 23F, -8F); RightDown.setTextureSize(64, 32); RightDown.mirror = true; setRotation(RightDown, 0F, 0F, 0F); } public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) { super.render(entity, f, f1, f2, f3, f4, f5); setRotationAngles(f, f1, f2, f3, f4, f5, entity); FrontDown.render(f5); LeftBack.render(f5); LeftFront.render(f5); RightFront.render(f5); RightBack.render(f5); FrontUp.render(f5); LeftDown.render(f5); BackDown.render(f5); BackUp.render(f5); LeftUp.render(f5); RightUp.render(f5); RightDown.render(f5); } private void setRotation(ModelRenderer model, float x, float y, float z) { model.rotateAngleX = x; model.rotateAngleY = y; model.rotateAngleZ = z; } public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity ent) { super.setRotationAngles(f, f1, f2, f3, f4, f5, ent); } } Thanks Quote
TheGreyGhost Posted April 20, 2014 Posted April 20, 2014 Hi It looks to me like there might be a mismatch in the texture scaling; Your renderer thinks that it should only use 8 texels wide instead of the 16. Pure guesswork, since I'm not familiar with ModelRendering: Perhaps something to do with this textureWidth = 32; textureHeight = 32; Left = new ModelRenderer(this, 0, 0); Left.addBox(0F, 0F, 0F, 1, 14, 14); Left.setRotationPoint(7F, 9F, -7F); Left.setTextureSize(64, 64); // why 64 here, but 32 above? Alternatively, perhaps these numbers don't match the actual number of pixels in the image you're using for the texture? -TGG Quote
Recommended Posts
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.