mirror of
https://github.com/GTNewHorizons/Draconic-Evolution.git
synced 2026-10-25 20:22:19 +00:00
Avoid instantiating EntityItem in the render loop (#99)
This commit is contained in:
1 parent
e564437ed7
commit
7f87295901
5 files changed
+76
-53
No files matched your search
+15
-9
@@ -7,6 +7,7 @@ import net.minecraft.client.renderer.entity.RenderItem;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
@@ -18,10 +19,7 @@ import com.brandon3055.draconicevolution.common.tileentities.TileDissEnchanter;
|
||||
|
||||
public class RenderTileDissEnchanter extends TileEntitySpecialRenderer {
|
||||
|
||||
// private final ResourceLocation texture = new ResourceLocation(References.MODID.toLowerCase(),
|
||||
// "textures/models/EnergyInfuserTextureSheet.png");
|
||||
|
||||
// private static float pxl = 1F / 256F;
|
||||
private final EntityItem cachedEntity = new EntityItem(null, 0, 0, 0, new ItemStack(Items.apple));
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float f) {
|
||||
@@ -71,10 +69,7 @@ public class RenderTileDissEnchanter extends TileEntitySpecialRenderer {
|
||||
if (tile.getStackInSlot(i) != null) {
|
||||
GL11.glPushMatrix();
|
||||
|
||||
ItemStack stack = tile.getStackInSlot(i).copy();
|
||||
stack.stackSize = 1;
|
||||
EntityItem itemEntity = new EntityItem(tile.getWorldObj(), 0, 0, 0, stack);
|
||||
itemEntity.hoverStart = 0.0F;
|
||||
ItemStack stack = tile.getStackInSlot(i);
|
||||
|
||||
GL11.glTranslatef(0.5F, 0.5F, 0.5F);
|
||||
GL11.glScalef(1F, 1F, 1F);
|
||||
@@ -85,7 +80,18 @@ public class RenderTileDissEnchanter extends TileEntitySpecialRenderer {
|
||||
}
|
||||
|
||||
RenderItem.renderInFrame = true;
|
||||
RenderManager.instance.renderEntityWithPosYaw(itemEntity, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F);
|
||||
final int stackSize = stack.stackSize;
|
||||
try {
|
||||
stack.stackSize = 1;
|
||||
this.cachedEntity.setEntityItemStack(stack);
|
||||
this.cachedEntity.setWorld(tile.getWorldObj());
|
||||
this.cachedEntity.hoverStart = 0.0F;
|
||||
RenderManager.instance.renderEntityWithPosYaw(this.cachedEntity, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F);
|
||||
} finally {
|
||||
stack.stackSize = stackSize;
|
||||
this.cachedEntity.setEntityItemStack(null);
|
||||
this.cachedEntity.setWorld(null);
|
||||
}
|
||||
RenderItem.renderInFrame = false;
|
||||
|
||||
GL11.glPopMatrix();
|
||||
|
||||
+12
-5
@@ -5,6 +5,7 @@ import net.minecraft.client.renderer.entity.RenderItem;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
@@ -17,11 +18,11 @@ import com.brandon3055.draconicevolution.common.tileentities.TileEnergyInfuser;
|
||||
|
||||
public class RenderTileEnergyInfiser extends TileEntitySpecialRenderer {
|
||||
|
||||
private static final float pxl = 1F / 256F;
|
||||
private final ResourceLocation texture = new ResourceLocation(
|
||||
References.MODID.toLowerCase(),
|
||||
"textures/models/EnergyInfuserTextureSheet.png");
|
||||
|
||||
private static float pxl = 1F / 256F;
|
||||
private final EntityItem cachedEntity = new EntityItem(null, 0, 0, 0, new ItemStack(Items.apple));
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float f) {
|
||||
@@ -238,8 +239,6 @@ public class RenderTileEnergyInfiser extends TileEntitySpecialRenderer {
|
||||
GL11.glPushMatrix();
|
||||
|
||||
ItemStack stack = tile.getStackInSlot(0);
|
||||
EntityItem itemEntity = new EntityItem(tile.getWorldObj(), 0, 0, 0, tile.getStackInSlot(0));
|
||||
itemEntity.hoverStart = 0.0F;
|
||||
|
||||
GL11.glTranslatef(0.5F, 0.5F, 0.5F);
|
||||
GL11.glScalef(1F, 1F, 1F);
|
||||
@@ -252,7 +251,15 @@ public class RenderTileEnergyInfiser extends TileEntitySpecialRenderer {
|
||||
}
|
||||
|
||||
RenderItem.renderInFrame = true;
|
||||
RenderManager.instance.renderEntityWithPosYaw(itemEntity, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F);
|
||||
try {
|
||||
this.cachedEntity.setEntityItemStack(stack);
|
||||
this.cachedEntity.setWorld(tile.getWorldObj());
|
||||
this.cachedEntity.hoverStart = 0.0F;
|
||||
RenderManager.instance.renderEntityWithPosYaw(this.cachedEntity, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F);
|
||||
} finally {
|
||||
this.cachedEntity.setEntityItemStack(null);
|
||||
this.cachedEntity.setWorld(null);
|
||||
}
|
||||
RenderItem.renderInFrame = false;
|
||||
|
||||
GL11.glPopMatrix();
|
||||
|
||||
+19
-15
@@ -1,16 +1,16 @@
|
||||
package com.brandon3055.draconicevolution.client.render.tile;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.entity.RenderItem;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemArmor;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemBow;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
@@ -22,12 +22,11 @@ import com.brandon3055.draconicevolution.common.tileentities.TilePlacedItem;
|
||||
*/
|
||||
public class RenderTilePlacedItem extends TileEntitySpecialRenderer {
|
||||
|
||||
public RenderTilePlacedItem() {}
|
||||
private final EntityItem cachedEntity = new EntityItem(null, 0, 0, 0, new ItemStack(Items.apple));
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntity te, double x, double y, double z, float timeSinceLastTick) {
|
||||
if (te == null || !(te instanceof TilePlacedItem)) return;
|
||||
TilePlacedItem tile = (TilePlacedItem) te;
|
||||
if (!(te instanceof TilePlacedItem tile)) return;
|
||||
if (tile.getStack() == null) return;
|
||||
GL11.glPushMatrix();
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
|
||||
@@ -39,20 +38,18 @@ public class RenderTilePlacedItem extends TileEntitySpecialRenderer {
|
||||
|
||||
public void renderItem(TilePlacedItem tile) {
|
||||
ItemStack stack = tile.getStack();
|
||||
World world = Minecraft.getMinecraft().theWorld;
|
||||
EntityItem itemEntity = new EntityItem(tile.getWorldObj(), 0, 0, 0, stack);
|
||||
int meta = world.getBlockMetadata(tile.xCoord, tile.yCoord, tile.zCoord);
|
||||
int meta = tile.getWorldObj().getBlockMetadata(tile.xCoord, tile.yCoord, tile.zCoord);
|
||||
// itemEntity.getEntityItem().stackSize = 1;
|
||||
itemEntity.hoverStart = 0.0F;
|
||||
boolean is3D = stack.getItem().isFull3D();
|
||||
boolean isBlock = stack.getItem() instanceof ItemBlock;
|
||||
final Item item = stack.getItem();
|
||||
boolean is3D = item.isFull3D();
|
||||
boolean isBlock = item instanceof ItemBlock;
|
||||
|
||||
if (isBlock) {
|
||||
GL11.glTranslatef(0.5F, 0.25F, 0.5F);
|
||||
GL11.glScalef(1.5F, 1.5F, 1.5F);
|
||||
metaAdjustBlock(meta);
|
||||
GL11.glRotatef(tile.rotation, 0F, 1F, 0F);
|
||||
} else if (is3D || stack.getItem() instanceof ItemArmor || stack.getItem() instanceof ItemBow) {
|
||||
} else if (is3D || item instanceof ItemArmor || item instanceof ItemBow) {
|
||||
GL11.glScalef(2F, 2F, 2F);
|
||||
GL11.glRotatef(90F, -1F, 0F, 0F);
|
||||
GL11.glTranslatef(0.25F, -0.45F, 0.02F);
|
||||
@@ -60,8 +57,7 @@ public class RenderTilePlacedItem extends TileEntitySpecialRenderer {
|
||||
GL11.glTranslatef(0.0F, 0.21F, 0.0F);
|
||||
GL11.glRotatef(tile.rotation, 0F, 0F, 1F);
|
||||
GL11.glTranslatef(0.0F, -0.21F, 0.0F);
|
||||
} else if (stack.getItem() instanceof MobSoul) {
|
||||
|
||||
} else if (item instanceof MobSoul) {
|
||||
GL11.glTranslatef(0.5F, 0.3F, 0.5F);
|
||||
} else {
|
||||
GL11.glRotatef(90F, -1F, 0F, 0F);
|
||||
@@ -74,7 +70,15 @@ public class RenderTilePlacedItem extends TileEntitySpecialRenderer {
|
||||
|
||||
GL11.glPushAttrib(GL11.GL_COLOR_BUFFER_BIT);
|
||||
RenderItem.renderInFrame = true;
|
||||
RenderManager.instance.renderEntityWithPosYaw(itemEntity, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F);
|
||||
try {
|
||||
this.cachedEntity.setEntityItemStack(stack);
|
||||
this.cachedEntity.setWorld(tile.getWorldObj());
|
||||
this.cachedEntity.hoverStart = 0.0F;
|
||||
RenderManager.instance.renderEntityWithPosYaw(this.cachedEntity, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F);
|
||||
} finally {
|
||||
this.cachedEntity.setEntityItemStack(null);
|
||||
this.cachedEntity.setWorld(null);
|
||||
}
|
||||
RenderItem.renderInFrame = false;
|
||||
GL11.glPopAttrib();
|
||||
}
|
||||
|
||||
+18
-20
@@ -1,7 +1,5 @@
|
||||
package com.brandon3055.draconicevolution.client.render.tile;
|
||||
|
||||
import java.awt.Point;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
@@ -10,6 +8,7 @@ import net.minecraft.client.renderer.entity.RenderItem;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
@@ -33,11 +32,11 @@ import com.brandon3055.draconicevolution.common.utils.Utils;
|
||||
*/
|
||||
public class RenderTileTeleporterStand extends TileEntitySpecialRenderer {
|
||||
|
||||
ModelTeleporterStand model = new ModelTeleporterStand();
|
||||
|
||||
private final ModelTeleporterStand model = new ModelTeleporterStand();
|
||||
private final ResourceLocation texture = new ResourceLocation(
|
||||
References.MODID.toLowerCase(),
|
||||
"textures/models/TeleporterStand.png");
|
||||
private final EntityItem cachedEntity = new EntityItem(null, 0, 0, 0, new ItemStack(Items.apple));
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) {
|
||||
@@ -69,27 +68,29 @@ public class RenderTileTeleporterStand extends TileEntitySpecialRenderer {
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
public void renderItem(TileEntity tile, ItemStack item, float f) {
|
||||
if (item.getItem() == null) return;
|
||||
public void renderItem(TileEntity tile, ItemStack stack, float f) {
|
||||
if (stack.getItem() == null) return;
|
||||
GL11.glPushMatrix();
|
||||
|
||||
EntityItem itemEntity = new EntityItem(tile.getWorldObj(), 0, 0, 0, item);
|
||||
itemEntity.hoverStart = 0.0F;
|
||||
|
||||
if (item.getItem() instanceof TeleporterMKII) {
|
||||
if (stack.getItem() instanceof TeleporterMKII) {
|
||||
GL11.glTranslatef(0F, 0.18F, 0.864F);
|
||||
GL11.glRotated(180, 0, 0, 1);
|
||||
GL11.glRotated(30, 1, 0, 0);
|
||||
GL11.glScalef(1F, 1F, 1F);
|
||||
} else {
|
||||
GL11.glTranslatef(0F, 0.22F, 0.84F);
|
||||
GL11.glRotated(180, 0, 0, 1);
|
||||
GL11.glRotated(30, 1, 0, 0);
|
||||
GL11.glScalef(1F, 1F, 1F);
|
||||
}
|
||||
GL11.glRotated(180, 0, 0, 1);
|
||||
GL11.glRotated(30, 1, 0, 0);
|
||||
GL11.glScalef(1F, 1F, 1F);
|
||||
|
||||
RenderItem.renderInFrame = true;
|
||||
RenderManager.instance.renderEntityWithPosYaw(itemEntity, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F);
|
||||
try {
|
||||
this.cachedEntity.setEntityItemStack(stack);
|
||||
this.cachedEntity.setWorld(tile.getWorldObj());
|
||||
this.cachedEntity.hoverStart = 0.0F;
|
||||
RenderManager.instance.renderEntityWithPosYaw(this.cachedEntity, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F);
|
||||
} finally {
|
||||
this.cachedEntity.setEntityItemStack(null);
|
||||
this.cachedEntity.setWorld(null);
|
||||
}
|
||||
RenderItem.renderInFrame = false;
|
||||
|
||||
GL11.glPopMatrix();
|
||||
@@ -126,9 +127,6 @@ public class RenderTileTeleporterStand extends TileEntitySpecialRenderer {
|
||||
GL11.glRotated(180, 0, 1, 0);
|
||||
GL11.glTranslated(0, -40, 0);
|
||||
|
||||
Point.Double p1 = new Point.Double(tileentity.xCoord + 0.5, tileentity.zCoord + 0.5);
|
||||
Point.Double p2 = new Point.Double(player.posX, player.posZ);
|
||||
|
||||
double xDiff = player.posX - (tileentity.xCoord + 0.5);
|
||||
double yDiff = player.posY - (tileentity.yCoord + 0.5);
|
||||
double zDiff = player.posZ - (tileentity.zCoord + 0.5);
|
||||
|
||||
+12
-4
@@ -5,6 +5,7 @@ import net.minecraft.client.renderer.entity.RenderItem;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
@@ -16,7 +17,8 @@ import com.brandon3055.draconicevolution.common.tileentities.TileUpgradeModifier
|
||||
|
||||
public class RenderTileUpgradeModifier extends TileEntitySpecialRenderer {
|
||||
|
||||
private static float pxl = 1F / 256F;
|
||||
private static final float pxl = 1F / 256F;
|
||||
private final EntityItem cachedEntity = new EntityItem(null, 0, 0, 0, new ItemStack(Items.apple));
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float f) {
|
||||
@@ -207,8 +209,6 @@ public class RenderTileUpgradeModifier extends TileEntitySpecialRenderer {
|
||||
GL11.glPushMatrix();
|
||||
|
||||
ItemStack stack = tile.getStackInSlot(0);
|
||||
EntityItem itemEntity = new EntityItem(tile.getWorldObj(), 0, 0, 0, tile.getStackInSlot(0));
|
||||
itemEntity.hoverStart = 0.0F;
|
||||
|
||||
GL11.glTranslatef(0.5F, 0.5F, 0.5F);
|
||||
GL11.glScalef(1F, 1F, 1F);
|
||||
@@ -220,7 +220,15 @@ public class RenderTileUpgradeModifier extends TileEntitySpecialRenderer {
|
||||
}
|
||||
|
||||
RenderItem.renderInFrame = true;
|
||||
RenderManager.instance.renderEntityWithPosYaw(itemEntity, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F);
|
||||
try {
|
||||
this.cachedEntity.setEntityItemStack(stack);
|
||||
this.cachedEntity.setWorld(tile.getWorldObj());
|
||||
this.cachedEntity.hoverStart = 0.0F;
|
||||
RenderManager.instance.renderEntityWithPosYaw(this.cachedEntity, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F);
|
||||
} finally {
|
||||
this.cachedEntity.setEntityItemStack(null);
|
||||
this.cachedEntity.setWorld(null);
|
||||
}
|
||||
RenderItem.renderInFrame = false;
|
||||
|
||||
GL11.glPopMatrix();
|
||||
|
||||
Reference in new issue
Block a user