Jump to content

TESR Problem


kubik_multivitamin

Recommended Posts

Hello, I'm trying to do my own cable, but I have a problem with TESR. Whenever I place a new cable, model of some previously placed cable change. It look like it's completly random. I really don't know what is going on and I don't know what to do. Where is a problem? Here are some pictures and code.

My TileEntity class:

public class TileEntityCable extends TileEntity implements ITickable {

	public CdlmEnergyStorage storage = new CdlmEnergyStorage(400, 100, 10);
	
	@Override
	public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
		if(capability == CapabilityEnergy.ENERGY) return true;
		return super.hasCapability(capability, facing);
	}
	 
	@Override
	public <T> T getCapability(Capability<T> capability, final EnumFacing facing) {
		if(capability == CapabilityEnergy.ENERGY) return (T)this.storage;
		return super.getCapability(capability, facing);
	}
	
	@Override
	public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
		super.writeToNBT(nbt);
		nbt.setTag("EnergyStorage", this.storage.serializeNBT());
		return nbt;
	}
	
	@Override
	public void readFromNBT(NBTTagCompound nbt) {
		super.readFromNBT(nbt);
		this.storage.deserializeNBT(nbt.getCompoundTag("EnergyStorage"));
	}
	
	@Override
	public void update() {
		for (EnumFacing face : EnumFacing.VALUES) {
			this.storage.extractEnergy(EnergyHelper.insertIntoAdjacentTile(this, face, this.storage.getMaxExtract(), false), false);
		}
	}

	public int receiveEnergy(int maxReceive, boolean simulate) {
		this.markDirty();
		return this.storage.receiveEnergy(maxReceive, simulate);
	}
	
	public ArrayList<EnumFacing> getEnergyHandlersSides() {
		ArrayList<EnumFacing> faces = new ArrayList<EnumFacing>();
		
		for (EnumFacing face : EnumFacing.VALUES) {
			if(EnergyHelper.isAdjacentTileEnergyHandler(this, face)) faces.add(face);
		}
		
		return faces;
	}
}

 

My Renderer class:

@SideOnly(Side.CLIENT)
public class RenderCable extends TileEntitySpecialRenderer<TileEntityCable> {
	
	private static final ResourceLocation TEXTURE = new ResourceLocation(Reference.MOD_ID + ":textures/blocks/cable.png");

	private final ModelCable MODEL = new ModelCable();
	
	public void render(TileEntityCable te, double x, double y, double z, float partialTicks, int destroyStage, float alpha)
    {
		GlStateManager.enableDepth();
        GlStateManager.depthFunc(515);
        GlStateManager.depthMask(true);
        
        ModelCable model = MODEL;
        
        if (destroyStage >= 0)
        {
            GlStateManager.matrixMode(5890);
            GlStateManager.pushMatrix();
            GlStateManager.scale(4.0F, 4.0F, 1.0F);
            GlStateManager.translate(0.0625F, 0.0625F, 0.0625F);
            GlStateManager.matrixMode(5888);
        }
        else this.bindTexture(TEXTURE);
        
        GlStateManager.pushMatrix();
        GlStateManager.enableRescaleNormal();
        GlStateManager.translate((float)x, (float)y - 1.0F, (float)z);
        GlStateManager.scale(1.0F, 1.0F, 1.0F);
        
        GlStateManager.translate(0.5F, 0.5F, 0.5F);
        
        model.renderAll();
        
        GlStateManager.disableRescaleNormal();
        GlStateManager.popMatrix();
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);

        if (destroyStage >= 0)
        {
            GlStateManager.matrixMode(5890);
            GlStateManager.popMatrix();
            GlStateManager.matrixMode(5888);
        }
        
        for(EnumFacing face : te.getEnergyHandlersSides()) {
        	switch(face) {
				case DOWN:
					model.hideSides(true, true, true, false, true, true);
					break;
				case EAST:
					model.hideSides(true, true, true, true, true, false);
					break;
				case NORTH:
					model.hideSides(false, true, true, true, true, true);
					break;
				case SOUTH:
					model.hideSides(true, false, true, true, true, true);
					break;
				case UP:
					model.hideSides(true, true, false, true, true, true);
					break;
				case WEST:
					model.hideSides(true, true, true, true, false, true);
					break;
				default:
					model.hideSides(true, true, true, true, true, true);
					break;
        	}
        }
    }
}

 

And my Model class:

@SideOnly(Side.CLIENT)
public class ModelCable extends ModelBase
{
	public ModelRenderer up;
	public ModelRenderer down;
	public ModelRenderer middle;
	public ModelRenderer back;
	public ModelRenderer front;
	public ModelRenderer left;
	public ModelRenderer right;
	
	public ModelCable()
	{
		textureWidth = 64;
		textureHeight = 64;
		
		up = new ModelRenderer(this, 0, 0);
		up.addBox(0F, 0F, 0F, 4, 6, 4, 0F);
		up.setRotationPoint(-2F, 8F, -2F);
		up.rotateAngleX = 0F;
		up.rotateAngleY = 0F;
		up.rotateAngleZ = 0F;
		up.mirror = false;
		up.isHidden = true;
		down = new ModelRenderer(this, 0, 0);
		down.addBox(0F, 0F, 0F, 4, 6, 4, 0F);
		down.setRotationPoint(-2F, 18F, -2F);
		down.rotateAngleX = 0F;
		down.rotateAngleY = 0F;
		down.rotateAngleZ = 0F;
		down.mirror = false;
		down.isHidden = true;
		middle = new ModelRenderer(this, 0, 10);
		middle.addBox(0F, 0F, 0F, 4, 4, 4, 0F);
		middle.setRotationPoint(-2F, 14F, -2F);
		middle.rotateAngleX = 0F;
		middle.rotateAngleY = 0F;
		middle.rotateAngleZ = 0F;
		middle.mirror = false;
		middle.isHidden = false;
		back = new ModelRenderer(this, 16, 0);
		back.addBox(0F, 0F, 0F, 4, 4, 6, 0F);
		back.setRotationPoint(-2F, 14F, 2F);
		back.rotateAngleX = 0F;
		back.rotateAngleY = 0F;
		back.rotateAngleZ = 0F;
		back.mirror = false;
		back.isHidden = true;
		front = new ModelRenderer(this, 16, 0);
		front.addBox(0F, 0F, 0F, 4, 4, 6, 0F);
		front.setRotationPoint(-2F, 14F, -8F);
		front.rotateAngleX = 0F;
		front.rotateAngleY = 0F;
		front.rotateAngleZ = 0F;
		front.mirror = false;
		front.isHidden = true;
		left = new ModelRenderer(this, 36, 0);
		left.addBox(0F, 0F, 0F, 6, 4, 4, 0F);
		left.setRotationPoint(2F, 14F, -2F);
		left.rotateAngleX = 0F;
		left.rotateAngleY = 0F;
		left.rotateAngleZ = 0F;
		left.mirror = false;
		left.isHidden = true;
		right = new ModelRenderer(this, 36, 0);
		right.addBox(0F, 0F, 0F, 6, 4, 4, 0F);
		right.setRotationPoint(-8F, 14F, -2F);
		right.rotateAngleX = 0F;
		right.rotateAngleY = 0F;
		right.rotateAngleZ = 0F;
		right.mirror = false;
		right.isHidden = true;
	}
	
	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);
		up.render(f5);
		down.render(f5);
		middle.render(f5);
		back.render(f5);
		front.render(f5);
		left.render(f5);
		right.render(f5);
	}
	
	public void renderAll() {
		up.render(0.0625F);
		down.render(0.0625F);
		middle.render(0.0625F);
		back.render(0.0625F);
		front.render(0.0625F);
		left.render(0.0625F);
		right.render(0.0625F);
	}
	
	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);
	}
	
    public void hideSides(boolean front, boolean back, boolean up, boolean down, boolean left, boolean right) {
        this.front.isHidden = front;
        this.back.isHidden = back;
        this.up.isHidden = up;
        this.down.isHidden = down;
        this.left.isHidden = left;
        this.right.isHidden = right;
    }
}

 

Minecraft%201.12.2%2004.02.2020%2021_04_Minecraft%201.12.2%2004.02.2020%2021_04_Minecraft%201.12.2%2004.02.2020%2021_04_

Thank you for your help.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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