Jump to content

Recommended Posts

Posted

Hello, I'm attempting to render a techne model for my block instead of the usual cube. The renderTileEntityAt method is being called.

 

*Edit: Forgot to explain what the problem was *facepalm*

*When I place the block down, the outline appears when I hover over it, but the model isn't being rendered.

 

Mod:

package simplyberries;

import static simplyberries.ReferenceSB.ID;
import static simplyberries.ReferenceSB.NAME;
import static simplyberries.ReferenceSB.VERSION;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;

@Mod(modid = ID, name = NAME, version = VERSION, dependencies = "required-after:tlhpoeCore")
public class SimplyBushes {
@Instance(ID)
public static SimplyBushes instance;

@SidedProxy(clientSide = ID + ".ClientProxySB", serverSide = ID + ".ServerProxySB")
public static ServerProxySB proxy;

@EventHandler
public void preInit(FMLPreInitializationEvent event) {
	proxy.initServer();
	proxy.initClient();
}
}

 

ServerProxy:

package simplyberries;

import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import simplyberries.block.BlockBerryBush;
import simplyberries.block.TileEntityBerryBush;
import cpw.mods.fml.common.registry.GameRegistry;

public class ServerProxySB {
public static Block berryBush = new BlockBerryBush();

public void initServer() {
	GameRegistry.registerTileEntity(TileEntityBerryBush.class, "tileEntityBerryBush");

	GameRegistry.registerBlock(berryBush, "berryBush");
}

public void initClient() {
}
}

 

ClientProxy:

package simplyberries;

import simplyberries.block.TileEntityBerryBush;
import simplyberries.client.render.TileEntityBerryBushRenderer;
import tlhpoeCore.TLHPoE;
import cpw.mods.fml.client.registry.ClientRegistry;

public class ClientProxySB extends ServerProxySB {
@Override
public void initClient() {
	TLHPoE.registerUpdateDetector(ReferenceSB.ID, ReferenceSB.NAME, ReferenceSB.VERSION, "0B6mhkrh-GwwwR2JjUUdDSWh3d0U");

	ClientRegistry.bindTileEntitySpecialRenderer(TileEntityBerryBush.class, new TileEntityBerryBushRenderer());
}
}

 

Block:

package simplyberries.block;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

public class BlockBerryBush extends BlockContainer {
public BlockBerryBush() {
	super(Material.leaves);

	this.setBlockTextureName("leaves");
	this.setStepSound(Block.soundTypeGrass);
	this.setCreativeTab(CreativeTabs.tabDecorations);
	this.setBlockName("berryBush");
}

@Override
public TileEntity createNewTileEntity(World world, int meta) {
	return new TileEntityBerryBush();
}

@Override
public int getRenderType() {
	return -1;
}

@Override
public boolean isOpaqueCube() {
	return false;
}

@Override
public boolean renderAsNormalBlock() {
	return false;
}
}

 

TileEntity:

package simplyberries.block;

import net.minecraft.tileentity.TileEntity;

public class TileEntityBerryBush extends TileEntity {
}

 

Model:

package simplyberries.client.model;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;

public class ModelBerryBush extends ModelBase {
ModelRenderer mainStem;

ModelRenderer branch1;
ModelRenderer branch2;
ModelRenderer branch3;

ModelRenderer leaves;

ModelRenderer dirtPile;

public ModelBerryBush() {
	textureWidth = 64;
	textureHeight = 32;

	mainStem = new ModelRenderer(this, 4, 0);
	mainStem.addBox(0F, 0F, 0F, 2, 6, 2);
	mainStem.setRotationPoint(-1F, 18F, -1F);
	mainStem.setTextureSize(64, 32);
	mainStem.mirror = true;
	setRotation(mainStem, 0F, 0F, 0F);

	branch1 = new ModelRenderer(this, 0, 0);
	branch1.addBox(0F, 0F, 0F, 1, 5, 1);
	branch1.setRotationPoint(2.933333F, 15.66667F, -2.9F);
	branch1.setTextureSize(64, 32);
	branch1.mirror = true;
	setRotation(branch1, 0F, 0.669215F, 0.9294653F);

	branch2 = new ModelRenderer(this, 0, 0);
	branch2.addBox(0F, 0F, 0F, 1, 5, 1);
	branch2.setRotationPoint(-3.066667F, 14.8F, -2.4F);
	branch2.setTextureSize(64, 32);
	branch2.mirror = true;
	setRotation(branch2, -0.0743572F, -0.6320364F, -0.669215F);

	branch3 = new ModelRenderer(this, 0, 0);
	branch3.addBox(0F, 0F, 0F, 1, 5, 1);
	branch3.setRotationPoint(-0.6666667F, 15.93333F, 5F);
	branch3.setTextureSize(64, 32);
	branch3.mirror = true;
	setRotation(branch3, 0.1487144F, 1.673038F, -0.9294653F);

	leaves = new ModelRenderer(this, 0, ;
	leaves.addBox(0F, 0F, 0F, 10, 10, 10);
	leaves.setRotationPoint(-5F, 11.4F, -5F);
	leaves.setTextureSize(64, 32);
	leaves.mirror = true;
	setRotation(leaves, 0F, 0F, 0F);

	dirtPile = new ModelRenderer(this, 12, 0);
	dirtPile.addBox(0F, 0F, 0F, 3, 1, 3);
	dirtPile.setRotationPoint(-1.5F, 23.4F, -1.5F);
	dirtPile.setTextureSize(64, 32);
	dirtPile.mirror = true;
	setRotation(dirtPile, 0F, 0F, 0F);
}

@Override
public void render(Entity e, float f, float f1, float f2, float f3, float f4, float f5) {
	super.render(e, f, f1, f2, f3, f4, f5);

	setRotationAngles(f, f1, f2, f3, f4, f5, e);

	mainStem.render(f5);

	branch1.render(f5);
	branch2.render(f5);
	branch3.render(f5);

	leaves.render(f5);

	dirtPile.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 entity) {
	super.setRotationAngles(f, f1, f2, f3, f4, f5, entity);
}
}

 

TileEntityRenderer:

package simplyberries.client.render;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;

import org.lwjgl.opengl.GL11;

import simplyberries.client.model.ModelBerryBush;
import tlhpoeCore.util.MCUtil;

public class TileEntityBerryBushRenderer extends TileEntitySpecialRenderer {
private static final ResourceLocation TEXTURE = MCUtil.newResource("simplyberries:textures/blocks/berryBush.png");
private final ModelBerryBush model;

public TileEntityBerryBushRenderer() {
	super();

	this.model = new ModelBerryBush();
}

@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float scale) {
	System.out.println("RENDER");

	GL11.glPushMatrix();

	GL11.glTranslated(x + 0.5D, y + 1.5D, z + 0.5D);

	Minecraft mc = MCUtil.getMC();
	World world = mc.theWorld;

	mc.renderEngine.bindTexture(TEXTURE);

	GL11.glPushMatrix();

	GL11.glRotatef(180F, 0, 0, 0);

	model.render(null, 0F, 0F, 0F, 0F, 0F, 0F);

	GL11.glPopMatrix();

	GL11.glPopMatrix();
}

private void adjustRotatePivotViaMeta(World world, int x, int y, int z) {
	int meta = world.getBlockMetadata(x, y, z);

	GL11.glPushMatrix();
	GL11.glRotated(meta * (-90), 0, 0, 1);
	GL11.glPopMatrix();
}

private void adjustLightFixture(World world, int i, int j, int k, Block block) {
	Tessellator tess = Tessellator.instance;

	float brightness = block.getLightValue(world, i, j, k);

	int skyLight = world.getLightBrightnessForSkyBlocks(i, j, k, 0);

	int modulousModifier = skyLight % 65536;
	int divModifier = skyLight / 65536;

	tess.setColorOpaque_F(brightness, brightness, brightness);

	OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float) modulousModifier, divModifier);
}
}

Kain

Posted

Try to use this:

                System.out.println("RENDER");

	Minecraft mc = MCUtil.getMC();
	World world = mc.theWorld;

	mc.renderEngine.bindTexture(TEXTURE);

	GL11.glPushMatrix();

                GL11.glTranslated(x + 0.5D, y + 1.5D, z + 0.5D);

	GL11.glRotatef(180F, 0, 0, 0);

	model.render(null, 0F, 0F, 0F, 0F, 0F, 0.0625F);

	GL11.glPopMatrix();

PM's regarding modding questions should belong in the Modder Support sub-forum and won't be answered.

Posted

Ok, it's rendering now, but it seems kind of wonky. :(

 

Ingame:

pfCbq8r.png

 

Techne:

8k1ylmY.png

 

TileEntityRenderer:

package simplyberries.client.render;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;

import org.lwjgl.opengl.GL11;

import simplyberries.client.model.ModelBerryBush;
import tlhpoeCore.util.MCUtil;

public class TileEntityBerryBushRenderer extends TileEntitySpecialRenderer {
private static final ResourceLocation TEXTURE = MCUtil.newResource("simplyberries:textures/blocks/berryBush.png");
private final ModelBerryBush model;

public TileEntityBerryBushRenderer() {
	super();

	this.model = new ModelBerryBush();
}

@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float scale) {
	System.out.println("RENDER");

	Minecraft mc = MCUtil.getMC();
	World world = mc.theWorld;

	mc.renderEngine.bindTexture(TEXTURE);

	GL11.glPushMatrix();

	GL11.glTranslated(x + 0.5D, y + 1.5D, z + 0.5D);

	GL11.glRotatef(180F, 0, 0, 0);

	model.render(null, 0F, 0F, 0F, 0F, 0F, 0.0625F);

	GL11.glPopMatrix();
}

private void adjustRotatePivotViaMeta(World world, int x, int y, int z) {
	int meta = world.getBlockMetadata(x, y, z);

	GL11.glPushMatrix();
	GL11.glRotated(meta * (-90), 0, 0, 1);
	GL11.glPopMatrix();
}

private void adjustLightFixture(World world, int i, int j, int k, Block block) {
	Tessellator tess = Tessellator.instance;

	float brightness = block.getLightValue(world, i, j, k);

	int skyLight = world.getLightBrightnessForSkyBlocks(i, j, k, 0);

	int modulousModifier = skyLight % 65536;
	int divModifier = skyLight / 65536;

	tess.setColorOpaque_F(brightness, brightness, brightness);

	OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float) modulousModifier, divModifier);
}
}

 

Model:

package simplyberries.client.model;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;

public class ModelBerryBush extends ModelBase {
private ModelRenderer mainStem;
private ModelRenderer branch1;
private ModelRenderer branch2;
private ModelRenderer branch3;
private ModelRenderer bush;
private ModelRenderer dirtPile;

public ModelBerryBush() {
	textureWidth = 64;
	textureHeight = 32;

	mainStem = new ModelRenderer(this, 4, 0);
	mainStem.addBox(0F, 0F, 0F, 2, 6, 2);
	mainStem.setRotationPoint(-1F, 18F, -1F);
	mainStem.setTextureSize(64, 32);
	mainStem.mirror = true;
	setRotation(mainStem, 0F, 0F, 0F);

	branch1 = new ModelRenderer(this, 0, 0);
	branch1.addBox(0F, 0F, 0F, 1, 5, 1);
	branch1.setRotationPoint(2.933333F, 15.66667F, -2.9F);
	branch1.setTextureSize(64, 32);
	branch1.mirror = true;
	setRotation(branch1, 0F, 0.669215F, 0.9294653F);
	branch2 = new ModelRenderer(this, 0, 0);
	branch2.addBox(0F, 0F, 0F, 1, 5, 1);
	branch2.setRotationPoint(-3.066667F, 14.8F, -2.4F);
	branch2.setTextureSize(64, 32);
	branch2.mirror = true;
	setRotation(branch2, -0.0743572F, -0.6320364F, -0.669215F);
	branch3 = new ModelRenderer(this, 0, 0);
	branch3.addBox(0F, 0F, 0F, 1, 5, 1);
	branch3.setRotationPoint(-0.6666667F, 15.93333F, 5F);
	branch3.setTextureSize(64, 32);
	branch3.mirror = true;
	setRotation(branch3, 0.1487144F, 1.673038F, -0.9294653F);

	bush = new ModelRenderer(this, 0, ;
	bush.addBox(0F, 0F, 0F, 10, 10, 10);
	bush.setRotationPoint(-5F, 11.4F, -5F);
	bush.setTextureSize(64, 32);
	bush.mirror = true;
	setRotation(bush, 0F, 0F, 0F);

	dirtPile = new ModelRenderer(this, 12, 0);
	dirtPile.addBox(0F, 0F, 0F, 3, 1, 3);
	dirtPile.setRotationPoint(-1.5F, 23.4F, -1.5F);
	dirtPile.setTextureSize(64, 32);
	dirtPile.mirror = true;
	setRotation(dirtPile, 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);

	mainStem.render(f5);

	branch1.render(f5);
	branch2.render(f5);
	branch3.render(f5);

	bush.render(f5);

	dirtPile.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);
}

}

Kain

Posted

Everything is rendering inside-out because of this line of code:

GL11.glRotatef(180F, 0, 0, 0);

. Either remove this line or actually rotate something (changing on of the 0's to a 1).

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.