-
Notifications
You must be signed in to change notification settings - Fork 12
/
ElectriItemRenderer.java
74 lines (63 loc) · 2.57 KB
/
ElectriItemRenderer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*******************************************************************************
* @author Reika Kalseki
*
* Copyright 2017
*
* All rights reserved.
* Distribution of the software in any form is only allowed with
* explicit, prior permission from the owner.
******************************************************************************/
package Reika.ElectriCraft;
import org.lwjgl.opengl.GL11;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.client.IItemRenderer;
import Reika.DragonAPI.Libraries.IO.ReikaTextureHelper;
import Reika.ElectriCraft.Auxiliary.Interfaces.BatteryTile;
import Reika.ElectriCraft.Registry.ElectriTiles;
import Reika.ElectriCraft.Registry.WireType;
import Reika.ElectriCraft.TileEntities.TileEntityWire;
public class ElectriItemRenderer implements IItemRenderer {
public ElectriItemRenderer() {
}
@Override
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
return true;
}
@Override
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
return true;
}
@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
float a = 0; float b = 0;
RenderBlocks rb = (RenderBlocks)data[0];
if (type == type.ENTITY) {
a = -0.5F;
b = -0.5F;
GL11.glScalef(0.5F, 0.5F, 0.5F);
}
ElectriTiles machine = ElectriTiles.getMachine(item);
if (machine == ElectriTiles.WIRE) {
TileEntityWire wire = (TileEntityWire)ElectriTiles.WIRE.createTEInstanceForRender();
wire.insulated = item.getItemDamage() >= WireType.INS_OFFSET;
wire.setBlockMetadata(item.getItemDamage()%WireType.INS_OFFSET);
TileEntityRendererDispatcher.instance.renderTileEntityAt(wire, a, -0.1D, b, 0.0F);
}
else if (machine == ElectriTiles.RFBATTERY || machine == ElectriTiles.EUBATTERY) {
BatteryTile te = (BatteryTile)machine.createTEInstanceForRender();
ReikaTextureHelper.bindTerrainTexture();
rb.renderBlockAsItem(machine.getBlockInstance(), item.getItemDamage(), 1);
te.setEnergyFromNBT(item);
TileEntityRendererDispatcher.instance.renderTileEntityAt((TileEntity)te, -0.5, -0.5, -0.5, 0.0F);
}
else if (machine.hasRender())
TileEntityRendererDispatcher.instance.renderTileEntityAt(machine.createTEInstanceForRender(), a, -0.1D, b, 0.0F);
else {
ReikaTextureHelper.bindTerrainTexture();
rb.renderBlockAsItem(machine.getBlockInstance(), item.getItemDamage(), 1);
}
}
}