summaryrefslogtreecommitdiff
path: root/ihl/worldgen/ores/DebugScannerTileEntity.java
blob: b32f3e8bc0e38c3d9943c69b30727a9e468c6353 (plain)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package ihl.worldgen.ores;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ic2.core.ContainerBase;
import ic2.core.IC2;
import ic2.core.IHasGui;
import ic2.core.block.TileEntityInventory;
import ic2.core.block.invslot.InvSlot;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidContainerItem;
import net.minecraftforge.oredict.OreDictionary;

public class DebugScannerTileEntity extends TileEntityInventory implements IHasGui {
	public final InvSlot itemsSlot;
	private ItemStack lastItem;
	public List<String> oreDictionaryEntries = new ArrayList<String>();

	public DebugScannerTileEntity() {
		this.itemsSlot = new InvSlot(this, "drainInput", 0, InvSlot.Access.I, 2);
	}

	@Override
	public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) {
		return this.getFacing() != (short) side && side != 0 && side != 1;
	}

	@Override
	public void updateEntityClient() {
		if (IC2.platform.isRendering()) {
			if (this.itemsSlot.get(0) != null && this.itemsSlot.get(0) != lastItem) {
				this.oreDictionaryEntries.clear();
				int[] ids = OreDictionary.getOreIDs(this.itemsSlot.get());
				String itemNameFromIR = Item.itemRegistry.getNameForObject(this.itemsSlot.get().getItem());
				this.oreDictionaryEntries.add("ItemRegistry entry:");
				this.oreDictionaryEntries.add(" " + itemNameFromIR);
				this.oreDictionaryEntries.add("Item damage: " + this.itemsSlot.get().getItemDamage());
				this.oreDictionaryEntries.add("Item class:");
				this.oreDictionaryEntries.add(" " + this.itemsSlot.get().getItem().getClass().getCanonicalName());
				if (this.itemsSlot.get().stackTagCompound != null) {
					this.oreDictionaryEntries.add("NBT keys:");
					Iterator<?> iterator = this.itemsSlot.get().stackTagCompound.func_150296_c().iterator();
					while (iterator.hasNext()) {
						String entry = (String) iterator.next();
						if (this.itemsSlot.get().stackTagCompound.getTag(entry) instanceof NBTTagCompound) {
							this.oreDictionaryEntries.add(" " + entry);
							NBTTagCompound ct = this.itemsSlot.get().stackTagCompound.getCompoundTag(entry);
							if (ct != null && ct.func_150296_c() != null && !ct.func_150296_c().isEmpty()) {
								this.oreDictionaryEntries.add(" -NBT compound tag subkeys:");
								Iterator<?> stIterator = ct.func_150296_c().iterator();
								while (stIterator.hasNext()) {
									String entry2 = (String) stIterator.next();
									this.oreDictionaryEntries.add("    " + entry2 + "=" + ct.getString(entry2));
								}
							}
						} else {
							this.oreDictionaryEntries
									.add(" " + entry + "=" + this.itemsSlot.get().stackTagCompound.getString(entry));
						}
					}
				}
				if (ids.length > 0) {
					this.oreDictionaryEntries.add("Ore dict. entries:");
					for (int i = 0; i < ids.length; i++) {
						this.oreDictionaryEntries.add(" " + OreDictionary.getOreName(ids[i]));
					}
				}
				lastItem = this.itemsSlot.get(0);
			}
			if (this.itemsSlot.get(1) != null && this.itemsSlot.get(1) != lastItem) {
				this.oreDictionaryEntries.clear();
				FluidStack fluid = null;
				this.oreDictionaryEntries.add("Fluid related item type:");
				if (this.itemsSlot.get(1).getItem() instanceof IFluidContainerItem) {
					this.oreDictionaryEntries.add(" IFluidContainerItem");
					fluid = ((IFluidContainerItem) this.itemsSlot.get(1).getItem()).getFluid(this.itemsSlot.get(1));
				} else if (FluidContainerRegistry.isContainer(this.itemsSlot.get(1))) {
					this.oreDictionaryEntries.add(" FluidContainerRegistry entry");
					if (FluidContainerRegistry.isBucket(this.itemsSlot.get(1))) {
						this.oreDictionaryEntries.add("This is bucket.");
					} else {
						this.oreDictionaryEntries.add("This is not a bucket.");
					}
					ItemStack emptyContainer = FluidContainerRegistry.drainFluidContainer(this.itemsSlot.get(1));
					if (emptyContainer != null) {
						this.oreDictionaryEntries.add("This container could return empty container:");
						this.oreDictionaryEntries.add(" " + emptyContainer.getDisplayName());
					} else {
						this.oreDictionaryEntries.add("This container has no empty version.");
					}
					fluid = FluidContainerRegistry.getFluidForFilledItem(this.itemsSlot.get(1));
				} else {
					this.oreDictionaryEntries.add(" none");
				}
				if (fluid != null) {
					this.oreDictionaryEntries.add("Internal fluid name:");
					this.oreDictionaryEntries.add(" " + fluid.getFluid().getName());
					this.oreDictionaryEntries.add("Fluid class:");
					this.oreDictionaryEntries.add(" " + fluid.getFluid().getClass().getName());
					this.oreDictionaryEntries.add("Fluid id:");
					this.oreDictionaryEntries.add(" " + fluid.getFluid().getID());
					this.oreDictionaryEntries.add("Fluid still icon:");
					if (fluid.getFluid().getStillIcon() != null) {
						this.oreDictionaryEntries.add(" " + fluid.getFluid().getStillIcon().getIconName());
					} else {
						this.oreDictionaryEntries.add(" <missing icon> ");
					}
					this.oreDictionaryEntries.add("Fluid flowing icon:");
					if (fluid.getFluid().getFlowingIcon() != null) {
						this.oreDictionaryEntries.add(" " + fluid.getFluid().getFlowingIcon().getIconName());
					} else {
						this.oreDictionaryEntries.add(" <missing icon> ");
					}
				}
				lastItem = this.itemsSlot.get(1);
			}
		}
	}

	/**
	 * Returns the name of the inventory
	 */
	@Override
	public String getInventoryName() {
		return "debugScanner";
	}

	@Override
	public ContainerBase<?> getGuiContainer(EntityPlayer entityPlayer) {
		return new DebugScannerContainer(entityPlayer, this);
	}

	@Override
	@SideOnly(Side.CLIENT)
	public GuiScreen getGui(EntityPlayer entityPlayer, boolean isAdmin) {
		return new DebugScannerGui(new DebugScannerContainer(entityPlayer, this));
	}

	@Override
	public void onGuiClosed(EntityPlayer entityPlayer) {
	}

	public boolean getGui(EntityPlayer player) {
		return this instanceof IHasGui ? (IC2.platform.isSimulating() ? IC2.platform.launchGui(player, this) : true)
				: false;
	}
}