Jump to content

[SOLVED]Custom Tile Entity rendering twice while near a beacon?


AlexDGr8r

Recommended Posts

I've noticed this problem for a little while now, but I'm still unsure as to what causes it. If the tile entity is placed before the beacon, then it will render just fine when I place down the beacon. But, if I place down the beacon and then the tile entity, it will appear like it is rendering twice with all the clipping it has.

 

Here's the associated files:

 

TileEntityMeteorShield

package net.meteor.common.tileentity;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import net.meteor.common.ClientHandler;
import net.meteor.common.ClientProxy;
import net.meteor.common.EnumMeteor;
import net.meteor.common.IMeteorShield;
import net.meteor.common.MeteorItems;
import net.meteor.common.MeteorsMod;
import net.meteor.common.climate.HandlerMeteor;
import net.meteor.common.climate.MeteorShieldData;
import net.meteor.common.entity.EntityComet;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class TileEntityMeteorShield extends TileEntity implements ISidedInventory, IMeteorShield
{

public static final int CHARGE_TIME = 1600;

private boolean shieldedChunks;
public String owner;

private int range;
private int powerLevel;
private int cometX;
private int cometZ;
private int cometType = -1;

public int age;

// Inventory stuff
private ItemStack[] inv;

public TileEntityMeteorShield() {
	this.range = 0;
	this.powerLevel = 0;
	this.age = 0;
	this.shieldedChunks = false;
	this.inv = new ItemStack[13];
}

public TileEntityMeteorShield(String theOwner) {
	this();
	this.owner = theOwner;
}

@Override
public void updateEntity()
{
	++age;

	if (!this.shieldedChunks) {
		if (powerLevel > 0) {
			if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
				MeteorsMod.proxy.metHandlers.get(worldObj.provider.dimensionId).getShieldManager().addShield(this);
			}
			this.shieldedChunks = true;
			this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
		} else if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) {
			GenerateParticles(this.worldObj, this.xCoord, this.yCoord, this.zCoord, this.worldObj.rand);
		} else if (age >= CHARGE_TIME) {
			setCharged();
			if (!worldObj.isRemote) {
				if (owner != null && owner.length() > 0) {
					EntityPlayer player = worldObj.getPlayerEntityByName(owner);
					if (player != null) {
						player.addChatMessage(ClientHandler.createMessage(StatCollector.translateToLocal("MeteorShield.howToUpgrade"), EnumChatFormatting.GOLD));
					}
				}
			}
		}
	}
	if (this.shieldedChunks) {
		range = powerLevel * MeteorsMod.instance.ShieldRadiusMultiplier;	// update range (may load as 0 for old updates, thus check with this)
	}
}

public void setCharged() {
	if (powerLevel == 0) {
		powerLevel = 1;
	}
}

public EnumMeteor getCometType() {
	if (cometType == -1) return EnumMeteor.METEORITE;
	return EnumMeteor.getTypeFromID(cometType);
}

public List<String> getDisplayInfo() {
	List<String> info = new ArrayList<String>();

	if (powerLevel == 0) {
		info.add("Charging...");
		info.add("Charged: " + (int)((float)age / (float)CHARGE_TIME * 100) + "%");
	} else {
		info.add("Power Level: " + powerLevel + " / 5");
		info.add("Range: " + range + " blocks");
	}

	info.add("Owner: " + owner);

	if (powerLevel != 0) {
		if (cometType != -1) {
			EnumMeteor type = EnumMeteor.getTypeFromID(cometType);
			info.add("Comet Entered Orbit at:");
			info.add("X: " + cometX);
			info.add("Z: " + cometZ);
		} else {
			info.add("No Comets Detected");
		}
	}

	return info;
}

public void addMeteorMaterials(List<ItemStack> items) {

	for (int i = 0; i < items.size(); i++) {
		ItemStack par1ItemStack = items.get(i);
		System.out.println(par1ItemStack);
		ItemStack itemstack1;
		int k = 5;
		if (par1ItemStack.isStackable())
		{
			while (par1ItemStack.stackSize > 0 && k >= 5 && k < this.getSizeInventory())
			{
				itemstack1 = inv[k];

				if (itemstack1 != null && itemstack1.getItem() == par1ItemStack.getItem() && (!par1ItemStack.getHasSubtypes() || par1ItemStack.getItemDamage() == itemstack1.getItemDamage()) && ItemStack.areItemStackTagsEqual(par1ItemStack, itemstack1))
				{
					int l = itemstack1.stackSize + par1ItemStack.stackSize;

					if (l <= par1ItemStack.getMaxStackSize())
					{
						par1ItemStack.stackSize = 0;
						itemstack1.stackSize = l;
					}
					else if (itemstack1.stackSize < par1ItemStack.getMaxStackSize())
					{
						par1ItemStack.stackSize -= par1ItemStack.getMaxStackSize() - itemstack1.stackSize;
						itemstack1.stackSize = par1ItemStack.getMaxStackSize();
					}
				}

				++k;
			}
		}

		if (par1ItemStack.stackSize > 0)
		{
			k = 5;

			while (k >= 5 && k < this.getSizeInventory())
			{
				itemstack1 = inv[k];

				if (itemstack1 == null)
				{
					inv[k] = par1ItemStack.copy();
					par1ItemStack.stackSize = 0;
					break;
				}

				++k;
			}
		}
	}
	worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
	this.markDirty();
}

public void detectComet(EntityComet comet) {
	this.cometX = (int)comet.posX;
	this.cometZ = (int)comet.posZ;
	this.cometType = comet.meteorType.getID();
	worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
	this.markDirty();
}

@SideOnly(Side.CLIENT)
private void GenerateParticles(World world, int x, int y, int z, Random random)
{
	if (world.getBlock(x, y + 1, z).isOpaqueCube()) return;
	for (int currX = x - 2; currX <= x + 2; currX++)
	{
		for (int currZ = z - 2; currZ <= z + 2; currZ++)
		{
			if ((currX > x - 2) && (currX < x + 2) && (currZ == z - 1))
			{
				currZ = z + 2;
			}
			if (random.nextInt(100) == 25)
			{
				for (int currY = y; currY <= y + 1; currY++)
				{
					if (!world.isAirBlock((currX - x) / 2 + x, currY, (currZ - z) / 2 + z))
					{
						break;
					}
					ClientProxy.spawnParticle("meteorshield", x + 0.5D, y + 2.0D, z + 0.5D, currX - x + random.nextFloat() - 0.5D, currY - y - random.nextFloat() - 1.0F, currZ - z + random.nextFloat() - 0.5D, world, -1);
				}
			}
		}
	}
}

@Override
public void readFromNBT(NBTTagCompound nbt)
{
	super.readFromNBT(nbt);
	this.owner = nbt.getString("owner");
	if (owner == null || owner.trim().isEmpty()) {
		owner = "None";
	}

	this.powerLevel = nbt.getInteger("powerLevel");
	this.range = MeteorsMod.instance.ShieldRadiusMultiplier * powerLevel;

	if (nbt.hasKey("cometType")) {
		this.cometType = nbt.getInteger("cometType");
		this.cometX = nbt.getInteger("cometX");
		this.cometZ = nbt.getInteger("cometZ");
	}

	NBTTagList nbttaglist = nbt.getTagList("Items", 10);
	this.inv = new ItemStack[this.getSizeInventory()];

	for (int i = 0; i < nbttaglist.tagCount(); i++) {
		NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
		int j = nbttagcompound1.getByte("Slot") & 255;

		if (j >= 0 && j < this.inv.length) {
			this.inv[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
		}
	}
}

@Override
public void writeToNBT(NBTTagCompound nbt)
{
	super.writeToNBT(nbt);
	nbt.setString("owner", this.owner);
	nbt.setInteger("powerLevel", powerLevel);
	if (cometType != -1) {
		nbt.setInteger("cometType", cometType);
		nbt.setInteger("cometX", cometX);
		nbt.setInteger("cometZ", cometZ);
	}

	NBTTagList nbttaglist = new NBTTagList();
	for (int i = 0; i < inv.length; i++) {
		if (inv[i] != null) {
			NBTTagCompound nbttagcompound1 = new NBTTagCompound();
			nbttagcompound1.setByte("Slot", (byte)i);
			this.inv[i].writeToNBT(nbttagcompound1);
			nbttaglist.appendTag(nbttagcompound1);
		}
	}

	nbt.setTag("Items", nbttaglist);
}

@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt)
{
	readFromNBT(pkt.func_148857_g());
}

@Override
public Packet getDescriptionPacket()
{
	NBTTagCompound var1 = new NBTTagCompound();
	writeToNBT(var1);
	return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, var1);
}

@Override
@SideOnly(Side.CLIENT)
public AxisAlignedBB getRenderBoundingBox() {
	return AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1.5, zCoord + 1);
}

@Override
public int getSizeInventory() {
	return inv.length;
}

@Override
public ItemStack getStackInSlot(int i) {
	return inv[i];
}

@Override
public ItemStack decrStackSize(int i, int j) {
	ItemStack stack = getStackInSlot(i);
	if (stack != null) {
		if (stack.stackSize <= j) {
			setInventorySlotContents(i, null);
		} else {
			ItemStack stack2 = stack.splitStack(j);
			if (stack.stackSize <= 0) {
				setInventorySlotContents(i, null);
			}
			stack = stack2;
		}
	}
	return stack;
}

@Override
public ItemStack getStackInSlotOnClosing(int i) {
	return null; // not needed, no items should be dropped
}

@Override
public void setInventorySlotContents(int i, ItemStack itemstack) {
	if (itemstack == null) {
		inv[i] = null;
		if (i > 0 && i < 5 && powerLevel > 1) {
			this.updateRange();
		}
	} else if (isItemValidForSlot(i, itemstack)) {
		if (i < 5 && itemstack.stackSize > 1) {
			itemstack.stackSize = 1;
		}
		if (i == 0) {
			this.setCharged();
			this.worldObj.playSoundEffect(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D, "meteors:shield.powerup", 1.0F, 0.6F);
			this.markDirty();
		} else if (i > 0 && i < 5) {
			inv[i] = itemstack;
			this.updateRange();
		}
	}
}

@Override
public int getInventoryStackLimit() {
	return 1;
}

@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
	return true; // TODO put in some proper checks for this
}

@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack) {
	if (itemstack.getItem() == MeteorItems.itemRedMeteorGem) {
		return powerLevel > 0 && i > 0 && i < 5 && powerLevel < 5 && inv[i] == null;
	} else if (itemstack.getItem() == MeteorItems.itemMeteorChips) {
		return i == 0 && powerLevel == 0;
	}

	return false;
}

@Override
public String getInventoryName() {
	return "Meteor Shield";
}

@Override
public boolean hasCustomInventoryName() {
	return false; // TODO localize later
}

@Override
public void openInventory() {}

@Override
public void closeInventory() {}

private void updateRange() {
	int powerCrystals = 0;
	for (int i = 1; i <= 4; i++) {
		if (inv[i] != null && inv[i].getItem() == MeteorItems.itemRedMeteorGem) {
			powerCrystals++;
		}
	}

	int oldLevel = this.powerLevel;
	this.powerLevel = 1 + powerCrystals;
	this.range = MeteorsMod.instance.ShieldRadiusMultiplier * powerLevel;
	this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);

	if (powerLevel > oldLevel) {
		this.worldObj.playSoundEffect(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D, "meteors:shield.powerup", 1.0F, powerLevel / 10.0F + 0.5F);
		if (MeteorsMod.instance.ShieldRadiusMultiplier <= 0 && !worldObj.isRemote) {
			EntityPlayer player = worldObj.getPlayerEntityByName(owner);
			if (player != null) {
				player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("MeteorShield.noUpgrade")));
			}	
		}
	} else if (powerLevel < oldLevel) {
		// TODO Add sound for power down
	}

	this.markDirty();
}

@Override
public int getRange() {
	return this.range;
}

@Override
public int getX() {
	return this.xCoord;
}

@Override
public int getY() {
	return this.yCoord;
}

@Override
public int getZ() {
	return this.zCoord;
}

@Override
public boolean isTileEntity() {
	return true;
}

@Override
public String getOwner() {
	return this.owner;
}

@Override
public int getPowerLevel() {
	return this.powerLevel;
}

@Override
public boolean equals(Object o) {
	if (o instanceof IMeteorShield) {
		IMeteorShield shield = (IMeteorShield)o;
		return (this.getX() == shield.getX()) && (this.getY() == shield.getY()) && (this.getZ() == shield.getZ());
	}
	return super.equals(o);
}

@Override
public void onChunkUnload() {
	if (!this.worldObj.isRemote) {
		HandlerMeteor metHandler = MeteorsMod.proxy.metHandlers.get(worldObj.provider.dimensionId);
		metHandler.getShieldManager().addShield(new MeteorShieldData(xCoord, yCoord, zCoord, powerLevel, owner));
	}
}

@Override
public int[] getAccessibleSlotsFromSide(int side) {
	int[] slots = new int[8];
	for (int i = 0; i < 8; i++) {
		slots[i] = i + 5;
	}

	return slots;
}

@Override
public boolean canInsertItem(int slot, ItemStack item, int side) {
	return slot < 5 && isItemValidForSlot(slot, item);
}

@Override
public boolean canExtractItem(int slot, ItemStack item, int side) {
	return slot > 4;
}

}

 

BlockMeteorShield

package net.meteor.common.block;

import java.util.Random;

import net.meteor.common.ClientHandler;
import net.meteor.common.MeteorsMod;
import net.meteor.common.tileentity.TileEntityMeteorShield;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.MathHelper;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class BlockMeteorShield extends BlockContainerMeteorsMod
{

public BlockMeteorShield()
{
	super(Material.rock);
	this.setLightOpacity(0);
	this.setBlockBounds(0.0625F, 0.375F, 0.0625F, 0.9375F, 1.0F, 0.9375F);
}

@Override
public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLiving, ItemStack itemstack)
{
	if ((par5EntityLiving instanceof EntityPlayer)) {
		EntityPlayer player = (EntityPlayer)par5EntityLiving;
		if (!par1World.isRemote) {
			player.addChatMessage(ClientHandler.createMessage(StatCollector.translateToLocal("MeteorShield.charging"), EnumChatFormatting.YELLOW));
		}
		TileEntityMeteorShield shield = (TileEntityMeteorShield) par1World.getTileEntity(par2, par3, par4);
		shield.owner = player.getCommandSenderName();
		par1World.playSoundEffect(par2, par3, par4, "meteors:shield.humm", 1.0F, 1.0F);
	}

	int l = MathHelper.floor_double((double)(par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;

        if (l == 0)
        {
        	par1World.setBlockMetadataWithNotify(par2, par3, par4, 1, 2);
        }

        if (l == 1)
        {
        	par1World.setBlockMetadataWithNotify(par2, par3, par4, 0, 2);
        }

        if (l == 2)
        {
        	par1World.setBlockMetadataWithNotify(par2, par3, par4, 3, 2);
        }

        if (l == 3)
        {
        	par1World.setBlockMetadataWithNotify(par2, par3, par4, 2, 2);
        }
        
        super.onBlockPlacedBy(par1World, par2, par3, par4, par5EntityLiving, itemstack);
}

@Override
public void breakBlock(World par1World, int par2, int par3, int par4, Block par5, int par6)
{
	TileEntityMeteorShield shield = (TileEntityMeteorShield)par1World.getTileEntity(par2, par3, par4);
	if (!par1World.isRemote) {
		if (MeteorsMod.proxy.metHandlers.get(par1World.provider.dimensionId).getShieldManager().meteorShields.remove(shield)) {
			//MeteorsMod.log.info("METEOR SHIELD SHOULD BE REMOVED");
		}
		par1World.playSoundEffect(par2 + 0.5D, par3 + 0.5D, par4 + 0.5D, "meteors:shield.powerdown", 1.0F, 1.0F);
	}

	if (shield != null)
        {
            for (int i1 = 0; i1 < shield.getSizeInventory(); ++i1)
            {
                ItemStack itemstack = shield.getStackInSlot(i1);

                if (itemstack != null)
                {
                    float f = par1World.rand.nextFloat() * 0.8F + 0.1F;
                    float f1 = par1World.rand.nextFloat() * 0.8F + 0.1F;
                    EntityItem entityitem;

                    for (float f2 = par1World.rand.nextFloat() * 0.8F + 0.1F; itemstack.stackSize > 0; par1World.spawnEntityInWorld(entityitem))
                    {
                        int j1 = par1World.rand.nextInt(21) + 10;

                        if (j1 > itemstack.stackSize)
                        {
                            j1 = itemstack.stackSize;
                        }

                        itemstack.stackSize -= j1;
                        entityitem = new EntityItem(par1World, (double)((float)par2 + f), (double)((float)par3 + f1), (double)((float)par4 + f2), new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage()));
                        float f3 = 0.05F;
                        entityitem.motionX = (double)((float)par1World.rand.nextGaussian() * f3);
                        entityitem.motionY = (double)((float)par1World.rand.nextGaussian() * f3 + 0.2F);
                        entityitem.motionZ = (double)((float)par1World.rand.nextGaussian() * f3);

                        if (itemstack.hasTagCompound())
                        {
                            entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
                        }
                    }
                }
            }

        }

	super.breakBlock(par1World, par2, par3, par4, par5, par6);
}

@SideOnly(Side.CLIENT)
@Override
public void randomDisplayTick(World world, int i, int j, int k, Random random)
{
	if (MeteorsMod.instance.meteorShieldSound && random.nextInt(256) == 100) {
		world.playSound(i + 0.5D, j + 0.5D, k + 0.5D, "meteors:shield.humm", 0.6F, 1.0F, false);
	}
}

@Override
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer player, int par6, float par7, float par8, float par9)
{
	player.openGui(MeteorsMod.instance, 0, world, i, j, k);
	return true;
}

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

/**
     * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
     * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
     */
    public boolean isOpaqueCube() {
        return false;
    }
    
    /**
     * The type of render function that is called for this block
     */
    public int getRenderType() {
        return -1;
    }
    
    /**
     * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
     */
    public boolean renderAsNormalBlock() {
        return false;
    }

}

 

ModelMeteorShield

package net.meteor.client.model;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.util.MathHelper;

public class ModelMeteorShield extends ModelBase
{
//fields
private ModelRenderer BaseShape;
private ModelRenderer TopLayer;
private ModelRenderer MiddleLayer;
private ModelRenderer BottomLayer;
private ModelRenderer Side1;
private ModelRenderer Side2;
private ModelRenderer Side3;
private ModelRenderer Side4;
private ModelRenderer Leg1;
private ModelRenderer Leg2;
private ModelRenderer Leg3;
private ModelRenderer Leg4;
private ModelRenderer Foot1;
private ModelRenderer Foot2;
private ModelRenderer Foot3;
private ModelRenderer Foot4;
private ModelRenderer InnerSlope1;
private ModelRenderer InnerSlope2;
private ModelRenderer InnerSlope3;
private ModelRenderer InnerSlope4;
private ModelRenderer SidePanel1;
private ModelRenderer SidePanel2;

private float topY;
private float midY;
private float botY;

public ModelMeteorShield()
{
	textureWidth = 128;
	textureHeight = 64;

	BaseShape = new ModelRenderer(this, 0, 0);
	BaseShape.addBox(-6F, 0F, -6F, 12, 0, 12);
	BaseShape.setRotationPoint(0F, 15F, 0F);
	BaseShape.setTextureSize(128, 64);
	BaseShape.mirror = true;
	setRotation(BaseShape, 0F, 0F, 0F);
	TopLayer = new ModelRenderer(this, 0, 14);
	TopLayer.addBox(-5F, -8F, -5F, 10, 1, 10);
	TopLayer.setRotationPoint(0F, 15F, 0F);
	TopLayer.setTextureSize(128, 64);
	TopLayer.mirror = true;
	setRotation(TopLayer, 0F, 0F, 0F);
	topY = TopLayer.rotationPointY;
	MiddleLayer = new ModelRenderer(this, 0, 26);
	MiddleLayer.addBox(-4F, -10F, -4F, 8, 1, ;
	MiddleLayer.setRotationPoint(0F, 15F, 0F);
	MiddleLayer.setTextureSize(128, 64);
	MiddleLayer.mirror = true;
	setRotation(MiddleLayer, 0F, 0F, 0F);
	midY = MiddleLayer.rotationPointY;
	BottomLayer = new ModelRenderer(this, 0, 35);
	BottomLayer.addBox(-3F, -12F, -3F, 6, 1, 6);
	BottomLayer.setRotationPoint(0F, 15F, 0F);
	BottomLayer.setTextureSize(128, 64);
	BottomLayer.mirror = true;
	setRotation(BottomLayer, 0F, 0F, 0F);
	botY = BottomLayer.rotationPointY;
	Side1 = new ModelRenderer(this, 66, 0);
	Side1.addBox(-7F, -7F, -7F, 14, 10, 1);
	Side1.setRotationPoint(0F, 15F, 0F);
	Side1.setTextureSize(128, 64);
	Side1.mirror = true;
	setRotation(Side1, 0F, 0F, 0F);
	Side2 = new ModelRenderer(this, 66, 0);
	Side2.addBox(-7F, -7F, 6F, 14, 10, 1);
	Side2.setRotationPoint(0F, 15F, 0F);
	Side2.setTextureSize(128, 64);
	Side2.mirror = true;
	setRotation(Side2, 0F, 0F, 0F);
	Side3 = new ModelRenderer(this, 83, 0);
	Side3.addBox(-7F, -7F, -7F, 1, 10, 14);
	Side3.setRotationPoint(0F, 15F, 0F);
	Side3.setTextureSize(128, 64);
	Side3.mirror = true;
	setRotation(Side3, 0F, 0F, 0F);
	Side4 = new ModelRenderer(this, 83, 0);
	Side4.addBox(6F, -7F, -7F, 1, 10, 14);
	Side4.setRotationPoint(0F, 15F, 0F);
	Side4.setTextureSize(128, 64);
	Side4.mirror = true;
	setRotation(Side4, 0F, 0F, 0F);
	Leg1 = new ModelRenderer(this, 48, 0);
	Leg1.addBox(-0.5F, 0F, -0.5F, 1, 6, 1);
	Leg1.setRotationPoint(-6F, 18F, 6F);
	Leg1.setTextureSize(128, 64);
	Leg1.mirror = true;
	setRotation(Leg1, 0.2617994F, -0.7853982F, 0F);
	Leg2 = new ModelRenderer(this, 48, 0);
	Leg2.addBox(-0.5F, 0F, -0.5F, 1, 6, 1);
	Leg2.setRotationPoint(6F, 18F, 6F);
	Leg2.setTextureSize(128, 64);
	Leg2.mirror = true;
	setRotation(Leg2, 0.2617994F, 0.7853982F, 0F);
	Leg3 = new ModelRenderer(this, 48, 0);
	Leg3.addBox(-0.5F, 0F, -0.5F, 1, 6, 1);
	Leg3.setRotationPoint(6F, 18F, -6F);
	Leg3.setTextureSize(128, 64);
	Leg3.mirror = true;
	setRotation(Leg3, -0.2617994F, -0.7853982F, 0F);
	Leg4 = new ModelRenderer(this, 48, 0);
	Leg4.addBox(-0.5F, 0F, -0.5F, 1, 6, 1);
	Leg4.setRotationPoint(-6F, 18F, -6F);
	Leg4.setTextureSize(128, 64);
	Leg4.mirror = true;
	setRotation(Leg4, -0.2617994F, 0.7853982F, 0F);
	Foot1 = new ModelRenderer(this, 52, 0);
	Foot1.addBox(-0.5F, 0F, -0.5F, 1, 1, 2);
	Foot1.setRotationPoint(-7F, 23F, 7F);
	Foot1.setTextureSize(128, 64);
	Foot1.mirror = true;
	setRotation(Foot1, 0F, -0.7853982F, 0F);
	Foot2 = new ModelRenderer(this, 52, 0);
	Foot2.addBox(-0.5F, 0F, -0.5F, 1, 1, 2);
	Foot2.setRotationPoint(7F, 23F, 7F);
	Foot2.setTextureSize(128, 64);
	Foot2.mirror = true;
	setRotation(Foot2, 0F, 0.7853982F, 0F);
	Foot3 = new ModelRenderer(this, 52, 0);
	Foot3.addBox(-0.5F, 0F, -0.5F, 1, 1, 2);
	Foot3.setRotationPoint(-7F, 23F, -7F);
	Foot3.setTextureSize(128, 64);
	Foot3.mirror = true;
	setRotation(Foot3, 0F, -2.356194F, 0F);
	Foot4 = new ModelRenderer(this, 52, 0);
	Foot4.addBox(-0.5F, 0F, -0.5F, 1, 1, 2);
	Foot4.setRotationPoint(7F, 23F, -7F);
	Foot4.setTextureSize(128, 64);
	Foot4.mirror = true;
	setRotation(Foot4, 0F, 2.356194F, 0F);
	InnerSlope1 = new ModelRenderer(this, 32, 26);
	InnerSlope1.addBox(-6F, 1F, 1F, 12, 0, 7);
	InnerSlope1.setRotationPoint(0F, 15F, 0F);
	InnerSlope1.setTextureSize(128, 64);
	InnerSlope1.mirror = true;
	setRotation(InnerSlope1, 0.8203047F, 0F, 0F);
	InnerSlope2 = new ModelRenderer(this, 32, 26);
	InnerSlope2.addBox(-6F, 1F, -8F, 12, 0, 7);
	InnerSlope2.setRotationPoint(0F, 15F, 0F);
	InnerSlope2.setTextureSize(128, 64);
	InnerSlope2.mirror = true;
	setRotation(InnerSlope2, -0.8203047F, 0F, 0F);
	InnerSlope3 = new ModelRenderer(this, 32, 14);
	InnerSlope3.addBox(-8F, 1F, -6F, 7, 0, 12);
	InnerSlope3.setRotationPoint(0F, 15F, 0F);
	InnerSlope3.setTextureSize(128, 64);
	InnerSlope3.mirror = true;
	setRotation(InnerSlope3, 0F, 0F, 0.8203047F);
	InnerSlope4 = new ModelRenderer(this, 32, 14);
	InnerSlope4.addBox(1F, 1F, -6F, 7, 0, 12);
	InnerSlope4.setRotationPoint(0F, 15F, 0F);
	InnerSlope4.setTextureSize(128, 64);
	InnerSlope4.mirror = true;
	setRotation(InnerSlope4, 0F, 0F, -0.8203047F);
	SidePanel1 = new ModelRenderer(this, 32, 34);
	SidePanel1.addBox(6F, 1F, -2F, 1, 4, 4);
	SidePanel1.setRotationPoint(0F, 12F, 0F);
	SidePanel1.setTextureSize(128, 64);
	SidePanel1.mirror = true;
	setRotation(SidePanel1, 0F, 0F, -0.2617994F);
	SidePanel2 = new ModelRenderer(this, 32, 34);
	SidePanel2.addBox(-7F, 1F, -2F, 1, 4, 4);
	SidePanel2.setRotationPoint(0F, 12F, 0F);
	SidePanel2.setTextureSize(128, 64);
	SidePanel2.mirror = true;
	setRotation(SidePanel2, 0F, 0F, 0.2617994F);
}

public void render(int pLevel, float partialTick, float f1, float f2, float f3, float f4, float f5, int age)
{
	setRotationAngles(partialTick, f1, f2, f3, f4, f5, pLevel, age);
	float bobModifier = MathHelper.sin(((float)age + partialTick) / 1600F * 360F) * 0.5F - 0.3F;
	BottomLayer.rotationPointY = botY + bobModifier;
	MiddleLayer.rotationPointY = midY + bobModifier;
	TopLayer.rotationPointY = topY + bobModifier;
	BaseShape.render(f5);
	switch (pLevel) {
		case 5:
		case 4:
			BottomLayer.render(f5);
		case 3:
			MiddleLayer.render(f5);
		case 2:
			TopLayer.render(f5);
	}
	Side1.render(f5);
	Side2.render(f5);
	Side3.render(f5);
	Side4.render(f5);
	Leg1.render(f5);
	Leg2.render(f5);
	Leg3.render(f5);
	Leg4.render(f5);
	Foot1.render(f5);
	Foot2.render(f5);
	Foot3.render(f5);
	Foot4.render(f5);
	InnerSlope1.render(f5);
	InnerSlope2.render(f5);
	InnerSlope3.render(f5);
	InnerSlope4.render(f5);
	SidePanel1.render(f5);
	SidePanel2.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, int pLevel, int age)
{
	if (pLevel == 0) {
		return;
	}
	TopLayer.rotateAngleY = ((float)age + f) / (140F / pLevel);
	MiddleLayer.rotateAngleY = ((float)age + f) / (70F / pLevel);
	BottomLayer.rotateAngleY = ((float)age + f) / (40F / pLevel);
}

}

 

TileEntityMeteorShieldRenderer

package net.meteor.client.tileentity;

import net.meteor.client.model.ModelMeteorShield;
import net.meteor.common.MeteorsMod;
import net.meteor.common.tileentity.TileEntityMeteorShield;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;

import org.lwjgl.opengl.GL11;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class TileEntityMeteorShieldRenderer extends TileEntitySpecialRenderer
{
private static final ResourceLocation shieldTexture = new ResourceLocation(MeteorsMod.MOD_ID, "textures/entities/meteorShield.png");

private ModelMeteorShield modelShield;

public TileEntityMeteorShieldRenderer() {
	this.modelShield = new ModelMeteorShield();
}

public void renderTileEntityAt(TileEntity tileentity, double d, double d1, double d2, float f) {
	renderAModelAt((TileEntityMeteorShield)tileentity, d, d1, d2, f);
}

public void renderAModelAt(TileEntityMeteorShield shield, double par2, double par4, double par6, float par8) {

	int level = shield.getPowerLevel();
	if (!shield.getWorldObj().isAirBlock(shield.xCoord, shield.yCoord + 1, shield.zCoord)) {
		level = 0;
	}
	int meta = shield.getBlockMetadata();

	GL11.glPushMatrix();
	GL11.glTranslatef((float)par2 + 0.5F, (float)par4 + 1.5F, (float)par6 + 0.5F);
	this.bindTexture(shieldTexture);
	GL11.glPushMatrix();
	GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
	GL11.glRotatef(meta * -90F, 0.0F, 1.0F, 0.0F);
	this.modelShield.render(level, par8, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F, shield.age);
	GL11.glPopMatrix();
	GL11.glPopMatrix();

}
}

 

And yes, I've registered it forge and such.

 

Side question, is there a way to check to see if this is being rendered twice? Just as a way to validate that the tile entity is indeed the tile entity that needs to be rendered and not some possibly memory leaked tile entity?

Link to comment
Share on other sites

  • 2 weeks later...

Hi

 

I don't think it is rendering twice.  I am not sure exactly what I'm seeing, but I sure it's because one of the rendering settings from the beacon is carrying over into your render.

 

Common settings which cause problems are back face culling, depth culling, and alpha blending.

 

I wrote a tool a while ago that is useful for determining openGL settings:

 

https://github.com/TheGreyGhost/SpeedyTools/blob/Working/src/speedytools/common/Utilities/OpenGLdebugging.java

 

I've used it in the past to check what the OpenGL settings are; it's not complete, but dumpAllIsEnabled() works and has showed up problems for me before- dump for a good render, dump for a bad render, and spot the difference.

 

-TGG

Link to comment
Share on other sites

Okay it is now fixed! Thanks TheGreyGhost!

 

The problem was that the beacon renderer was disabling GL_CULL_FACE and enabling GL_BLEND when I need it to be the opposite for my meteor shield. Ensuring that these properties were correct made my tile entity render correctly.

Link to comment
Share on other sites

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.