mirror of
https://github.com/GTNewHorizons/Binnie.git
synced 2026-11-13 17:04:26 +00:00
Another performance pass (#110)
This commit is contained in:
1 parent
50bed12f66
commit
52d9d1aedc
19 files changed
+151
-56
No files matched your search
@@ -194,7 +194,7 @@ public class Widget implements IWidget {
|
||||
|
||||
@Override
|
||||
public void setOffset(IPoint offset) {
|
||||
if (offset != this.offset) {
|
||||
if (!offset.equals(this.offset)) {
|
||||
this.offset = new IPoint(offset);
|
||||
callEvent(new EventWidget.ChangeOffset(this));
|
||||
}
|
||||
@@ -285,6 +285,10 @@ public class Widget implements IWidget {
|
||||
onRender(RenderStage.PreChildren);
|
||||
|
||||
for (IWidget widget : getWidgets()) {
|
||||
if (!widget.isVisible()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
widget.render();
|
||||
CraftGUI.render.preRender(widget);
|
||||
widget.onRender(RenderStage.PostSiblings);
|
||||
@@ -343,7 +347,7 @@ public class Widget implements IWidget {
|
||||
|
||||
@Override
|
||||
public boolean isMouseOverWidget(IPoint relativeMouse) {
|
||||
return getArea().contains(relativeMouse);
|
||||
return contains(relativeMouse);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -471,7 +475,8 @@ public class Widget implements IWidget {
|
||||
|
||||
@Override
|
||||
public boolean contains(IPoint position) {
|
||||
return getArea().contains(position);
|
||||
IPoint size = size();
|
||||
return position.x() >= 0.0f && position.y() >= 0.0f && position.x() <= size.x() && position.y() <= size.y();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package binnie.core.craftgui.controls.tab;
|
||||
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import binnie.core.craftgui.CraftGUI;
|
||||
import binnie.core.craftgui.ITooltip;
|
||||
import binnie.core.craftgui.Tooltip;
|
||||
@@ -21,6 +24,7 @@ public class ControlTab<T> extends Control implements ITooltip, IControlValue<T>
|
||||
protected T value;
|
||||
|
||||
private final ControlTabBar<T> tabBar;
|
||||
private final Map<Texture, Texture> croppedTextures = new IdentityHashMap<>();
|
||||
|
||||
public ControlTab(ControlTabBar<T> parent, float x, float y, float w, float h, T value) {
|
||||
super(parent, x, y, w, h);
|
||||
@@ -45,9 +49,8 @@ public class ControlTab<T> extends Control implements ITooltip, IControlValue<T>
|
||||
texture = CraftGUITexture.Tab;
|
||||
}
|
||||
|
||||
Texture lTexture = CraftGUI.render.getTexture(texture);
|
||||
Position position = getTabPosition();
|
||||
Texture iTexture = lTexture.crop(position, 8.0f);
|
||||
Texture iTexture = getCroppedTexture(texture);
|
||||
IArea area = getArea();
|
||||
if (texture == CraftGUITexture.TabDisabled) {
|
||||
if (position == Position.TOP || position == Position.LEFT) {
|
||||
@@ -68,14 +71,23 @@ public class ControlTab<T> extends Control implements ITooltip, IControlValue<T>
|
||||
}
|
||||
|
||||
if (icon.hasOutline()) {
|
||||
iTexture = CraftGUI.render.getTexture(CraftGUITexture.TabOutline);
|
||||
iTexture = iTexture.crop(position, 8.0f);
|
||||
iTexture = getCroppedTexture(CraftGUITexture.TabOutline);
|
||||
CraftGUI.render.color(icon.getOutlineColor());
|
||||
CraftGUI.render.texture(iTexture, area.inset(2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Texture getCroppedTexture(Object key) {
|
||||
Texture source = CraftGUI.render.getTexture(key);
|
||||
Texture cropped = croppedTextures.get(source);
|
||||
if (cropped == null) {
|
||||
cropped = source.crop(getTabPosition(), 8.0f);
|
||||
croppedTextures.put(source, cropped);
|
||||
}
|
||||
return cropped;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getTooltip(Tooltip tooltip) {
|
||||
String name = getName();
|
||||
|
||||
@@ -4,6 +4,7 @@ import static net.minecraftforge.common.util.Constants.NBT.TAG_COMPOUND;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -37,6 +38,8 @@ import binnie.core.machines.power.TankInfo;
|
||||
import binnie.core.machines.transfer.TransferRequest;
|
||||
import binnie.core.network.packet.MessageContainerUpdate;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
|
||||
public class ContainerCraftGUI extends Container {
|
||||
|
||||
@@ -80,6 +83,7 @@ public class ContainerCraftGUI extends Container {
|
||||
private final Map<String, NBTTagCompound> syncedNBT = new HashMap<>();
|
||||
private final Map<String, NBTTagCompound> sentNBT = new HashMap<>();
|
||||
private final Map<Integer, TankInfo> syncedTanks = new HashMap<>();
|
||||
private final Map<IInventory, Int2ObjectMap<CustomSlot>> slotsByInventory = new IdentityHashMap<>();
|
||||
private PowerInfo syncedPower = new PowerInfo();
|
||||
private ProcessInfo syncedProcess = new ProcessInfo();
|
||||
private int errorType = 0;
|
||||
@@ -109,9 +113,17 @@ public class ContainerCraftGUI extends Container {
|
||||
|
||||
@Override
|
||||
protected Slot addSlotToContainer(Slot slot) {
|
||||
indexSlot(slot);
|
||||
return super.addSlotToContainer(slot);
|
||||
}
|
||||
|
||||
private void indexSlot(Slot slot) {
|
||||
if (slot instanceof CustomSlot customSlot) {
|
||||
slotsByInventory.computeIfAbsent(customSlot.inventory, key -> new Int2ObjectOpenHashMap<>())
|
||||
.putIfAbsent(customSlot.getSlotIndex(), customSlot);
|
||||
}
|
||||
}
|
||||
|
||||
private Side getSide() {
|
||||
return window.isServer() ? Side.SERVER : Side.CLIENT;
|
||||
}
|
||||
@@ -320,7 +332,7 @@ public class ContainerCraftGUI extends Container {
|
||||
|
||||
action.setString(ACTION_TYPE, actionType);
|
||||
|
||||
if (action.equals(actionPrev)) continue;
|
||||
if (action == actionPrev || action.equals(actionPrev)) continue;
|
||||
|
||||
if (actions == null) {
|
||||
actions = new NBTTagList();
|
||||
@@ -482,13 +494,8 @@ public class ContainerCraftGUI extends Container {
|
||||
}
|
||||
|
||||
private CustomSlot getSlot(IInventory inventory, int id) {
|
||||
for (Object o : inventorySlots) {
|
||||
CustomSlot slot = (CustomSlot) o;
|
||||
if (slot.inventory == inventory && slot.getSlotIndex() == id) {
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
Int2ObjectMap<CustomSlot> slots = slotsByInventory.get(inventory);
|
||||
return (slots == null) ? null : slots.get(id);
|
||||
}
|
||||
|
||||
public void receiveNBT(Side side, EntityPlayer player, NBTTagCompound action) {
|
||||
@@ -549,6 +556,7 @@ public class ContainerCraftGUI extends Container {
|
||||
IInventory inventory = getInventory(type);
|
||||
Slot slot = new CustomSlot(inventory, index);
|
||||
slot.slotNumber = slotNumber;
|
||||
indexSlot(slot);
|
||||
inventorySlots.add(slotNumber, slot);
|
||||
ItemStack stack = slot.getStack();
|
||||
inventoryItemStacks.add(slotNumber, stack == null ? null : stack.copy());
|
||||
|
||||
@@ -11,6 +11,9 @@ import binnie.core.machines.inventory.InventorySlot;
|
||||
|
||||
public class CustomSlot extends Slot {
|
||||
|
||||
private InventorySlot inventorySlot;
|
||||
private boolean inventorySlotResolved;
|
||||
|
||||
public CustomSlot(IInventory inventory, int index) {
|
||||
super(inventory, index, 0, 0);
|
||||
}
|
||||
@@ -21,11 +24,12 @@ public class CustomSlot extends Slot {
|
||||
}
|
||||
|
||||
public InventorySlot getInventorySlot() {
|
||||
IInventorySlots slots = Machine.getInterface(IInventorySlots.class, inventory);
|
||||
if (slots != null) {
|
||||
return slots.getSlot(getSlotIndex());
|
||||
if (!inventorySlotResolved) {
|
||||
IInventorySlots slots = Machine.getInterface(IInventorySlots.class, inventory);
|
||||
inventorySlot = (slots == null) ? null : slots.getSlot(getSlotIndex());
|
||||
inventorySlotResolved = true;
|
||||
}
|
||||
return null;
|
||||
return inventorySlot;
|
||||
}
|
||||
|
||||
public boolean handleClick() {
|
||||
|
||||
@@ -21,6 +21,7 @@ import net.minecraft.util.ResourceLocation;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
import binnie.core.BinnieCore;
|
||||
import binnie.core.craftgui.IWidget;
|
||||
@@ -83,7 +84,7 @@ public class GuiCraftGUI extends GuiContainer {
|
||||
window.setMousePosition(mouseX - (int) window.getPosition().x(), mouseY - (int) window.getPosition().y());
|
||||
drawDefaultBackground();
|
||||
|
||||
GL11.glDisable(32826); // GL_RESCALE_NORMAL_EXT
|
||||
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
@@ -98,7 +99,7 @@ public class GuiCraftGUI extends GuiContainer {
|
||||
NEIHook.renderObjects(window, mouseX, mouseY);
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glEnable(32826); // GL_RESCALE_NORMAL_EXT
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240.0f, 240.0f);
|
||||
InventoryPlayer playerInventory = mc.thePlayer.inventory;
|
||||
draggedItem = playerInventory.getItemStack();
|
||||
@@ -106,7 +107,7 @@ public class GuiCraftGUI extends GuiContainer {
|
||||
GL11.glTranslatef(0.0f, 0.0f, 200.0f);
|
||||
renderItem(new IPoint(mouseX - 8, mouseY - 8), draggedItem, false);
|
||||
}
|
||||
GL11.glDisable(32826); // GL_RESCALE_NORMAL_EXT
|
||||
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
|
||||
GL11.glPopMatrix();
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
@@ -133,7 +134,7 @@ public class GuiCraftGUI extends GuiContainer {
|
||||
int mouseX = (int) mousePosition.x();
|
||||
int mouseY = (int) mousePosition.y();
|
||||
FontRenderer font = getFontRenderer();
|
||||
GL11.glDisable(32826); // GL_RESCALE_NORMAL_EXT
|
||||
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
@@ -224,7 +225,7 @@ public class GuiCraftGUI extends GuiContainer {
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
RenderHelper.enableStandardItemLighting();
|
||||
GL11.glEnable(32826); // GL_RESCALE_NORMAL_EXT
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -424,8 +425,9 @@ public class GuiCraftGUI extends GuiContainer {
|
||||
|
||||
public void renderItem(IPoint pos, ItemStack item, boolean rotating) {
|
||||
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240.0f, 240.0f);
|
||||
GL11.glPushAttrib(8256);
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT | GL11.GL_LIGHTING_BIT);
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
FontRenderer font = item.getItem().getFontRenderer(item);
|
||||
if (font == null) {
|
||||
@@ -458,11 +460,11 @@ public class GuiCraftGUI extends GuiContainer {
|
||||
}
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glEnable(32826); // GL_RESCALE_NORMAL_EXT
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
BinnieCore.proxy.bindTexture(map);
|
||||
GuiScreen.itemRender.zLevel = zLevel;
|
||||
GuiScreen.itemRender.renderIcon((int) pos.x(), (int) pos.y(), icon, 16, 16);
|
||||
GL11.glEnable(32826); // GL_RESCALE_NORMAL_EXT
|
||||
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package binnie.core.craftgui.minecraft;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Deque;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -47,6 +46,7 @@ import binnie.core.resource.BinnieResource;
|
||||
import binnie.core.resource.ResourceType;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||
|
||||
public abstract class Window extends TopLevelWidget implements INetwork.ReceiveGuiNBT {
|
||||
|
||||
@@ -81,7 +81,7 @@ public abstract class Window extends TopLevelWidget implements INetwork.ReceiveG
|
||||
setSize(new IPoint(width, height));
|
||||
gui = new GuiCraftGUI(this);
|
||||
for (EnumHighlighting h : EnumHighlighting.values()) {
|
||||
ControlSlot.highlighting.put(h, new ArrayList<>());
|
||||
ControlSlot.highlighting.put(h, new IntOpenHashSet());
|
||||
}
|
||||
|
||||
renderer = new Renderer(gui);
|
||||
|
||||
@@ -57,9 +57,10 @@ public class ControlErrorState extends Control implements ITooltip {
|
||||
|
||||
ControlEnergyBar.isError = errorState.isPowerError();
|
||||
if (errorState.isItemError()) {
|
||||
CustomSlot[] customSlots = Window.get(this).getContainer().getCustomSlots();
|
||||
for (int slot : errorState.getData()) {
|
||||
int id = -1;
|
||||
for (CustomSlot cslot : Window.get(this).getContainer().getCustomSlots()) {
|
||||
for (CustomSlot cslot : customSlots) {
|
||||
if (!(cslot.inventory instanceof InventoryPlayer) && cslot.getSlotIndex() == slot) {
|
||||
id = cslot.slotNumber;
|
||||
}
|
||||
|
||||
@@ -47,13 +47,13 @@ public class ControlItemDisplay extends Control implements ITooltip {
|
||||
|
||||
@Override
|
||||
public void onRenderBackground() {
|
||||
IPoint relativeToWindow = getAbsolutePosition().sub(getSuperParent().getPosition());
|
||||
if (relativeToWindow.x() > Window.get(this).getSize().x() + 100.0f
|
||||
|| relativeToWindow.y() > Window.get(this).getSize().y() + 100.0f) {
|
||||
if (itemStack == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (itemStack == null) {
|
||||
IPoint relativeToWindow = getAbsolutePosition().sub(getSuperParent().getPosition());
|
||||
if (relativeToWindow.x() > Window.get(this).getSize().x() + 100.0f
|
||||
|| relativeToWindow.y() > Window.get(this).getSize().y() + 100.0f) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import static binnie.core.craftgui.minecraft.ContainerCraftGUI.SLOT_REG;
|
||||
import static binnie.core.craftgui.minecraft.ContainerCraftGUI.SLOT_TYPE;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -36,15 +36,17 @@ import binnie.core.machines.inventory.MachineSide;
|
||||
import binnie.core.machines.inventory.SlotValidator;
|
||||
import binnie.core.network.packet.MessageCraftGUI;
|
||||
import binnie.core.util.I18N;
|
||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||
|
||||
public class ControlSlot extends ControlSlotBase {
|
||||
|
||||
public static Map<EnumHighlighting, List<Integer>> highlighting = new HashMap<>();
|
||||
public static Map<EnumHighlighting, IntSet> highlighting = new EnumMap<>(EnumHighlighting.class);
|
||||
public static boolean shiftClickActive = false;
|
||||
|
||||
static {
|
||||
for (EnumHighlighting h : EnumHighlighting.values()) {
|
||||
ControlSlot.highlighting.put(h, new ArrayList<>());
|
||||
ControlSlot.highlighting.put(h, new IntOpenHashSet());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +108,7 @@ public class ControlSlot extends ControlSlotBase {
|
||||
}
|
||||
|
||||
boolean highlighted = false;
|
||||
for (Map.Entry<EnumHighlighting, List<Integer>> highlight : ControlSlot.highlighting.entrySet()) {
|
||||
for (Map.Entry<EnumHighlighting, IntSet> highlight : ControlSlot.highlighting.entrySet()) {
|
||||
if (highlight.getKey() == EnumHighlighting.SHIFT_CLICK && !ControlSlot.shiftClickActive) {
|
||||
continue;
|
||||
}
|
||||
@@ -135,7 +137,7 @@ public class ControlSlot extends ControlSlotBase {
|
||||
}
|
||||
|
||||
boolean highlighted = false;
|
||||
for (Map.Entry<EnumHighlighting, List<Integer>> highlight : ControlSlot.highlighting.entrySet()) {
|
||||
for (Map.Entry<EnumHighlighting, IntSet> highlight : ControlSlot.highlighting.entrySet()) {
|
||||
if (highlight.getKey() == EnumHighlighting.SHIFT_CLICK && !ControlSlot.shiftClickActive) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -52,9 +52,9 @@ public abstract class ControlSlotBase extends Control implements ITooltip {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateClient() {
|
||||
super.onUpdateClient();
|
||||
public void render() {
|
||||
itemDisplay.setItemStack(getItemStack());
|
||||
super.render();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,15 +9,17 @@ class ParsedTextureSheet implements IBinnieTexture {
|
||||
private final String name;
|
||||
private final String modid;
|
||||
private final String path;
|
||||
private final BinnieResource texture;
|
||||
|
||||
public ParsedTextureSheet(String name, String modid, String path) {
|
||||
this.name = name;
|
||||
this.modid = modid;
|
||||
this.path = path;
|
||||
texture = new BinnieResource(modid, ResourceType.GUI, path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BinnieResource getTexture() {
|
||||
return new BinnieResource(modid, ResourceType.GUI, path);
|
||||
return texture;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package binnie.core.machines;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -71,8 +72,9 @@ public class Machine implements INetworkedEntity, INBTTagable, INetwork.TilePack
|
||||
|
||||
@Override
|
||||
public <T> T getInterface(Class<T> cls) {
|
||||
if (hasInterface(cls)) {
|
||||
return getInterfaces(cls).get(0);
|
||||
List<MachineComponent> components = componentInterfaceMap.get(cls);
|
||||
if (components != null && !components.isEmpty()) {
|
||||
return cls.cast(components.get(0));
|
||||
}
|
||||
if (cls.isInstance(getPackage())) {
|
||||
return cls.cast(getPackage());
|
||||
@@ -88,11 +90,13 @@ public class Machine implements INetworkedEntity, INBTTagable, INetwork.TilePack
|
||||
|
||||
@Override
|
||||
public <T> List<T> getInterfaces(Class<T> cls) {
|
||||
ArrayList<T> interfaces = new ArrayList<>();
|
||||
if (!hasInterface(cls)) {
|
||||
return interfaces;
|
||||
List<MachineComponent> components = componentInterfaceMap.get(cls);
|
||||
if (components == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
for (MachineComponent component : componentInterfaceMap.get(cls)) {
|
||||
|
||||
List<T> interfaces = new ArrayList<>(components.size());
|
||||
for (MachineComponent component : components) {
|
||||
interfaces.add(cls.cast(component));
|
||||
}
|
||||
return interfaces;
|
||||
|
||||
@@ -27,6 +27,12 @@ public abstract class MachinePackage {
|
||||
|
||||
public abstract TileEntity createTileEntity();
|
||||
|
||||
/// Whether this machine's tile entity needs {@link net.minecraft.tileentity.TileEntity#updateEntity()}.
|
||||
/// Override to false only when no component implements onUpdate, onInventoryUpdate or a client display tick.
|
||||
public boolean isTickable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return I18N.localise(group.getMod().getModID() + ".machine." + group.getShortUID() + "." + getUID());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package binnie.core.machines;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
@@ -12,6 +15,8 @@ import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||
// Hmm. It's used class
|
||||
public class RendererMachine extends TileEntitySpecialRenderer implements ISimpleBlockRenderingHandler {
|
||||
|
||||
private final Map<Block, Map<Integer, TileEntityMachine>> inventoryTiles = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntity entity, double x, double y, double z, float partialTick) {
|
||||
renderTileEntity((TileEntityMachine) entity, x, y, z, partialTick);
|
||||
@@ -25,8 +30,20 @@ public class RendererMachine extends TileEntitySpecialRenderer implements ISimpl
|
||||
}
|
||||
|
||||
private void renderInvBlock(Block block, int i, int j) {
|
||||
TileEntity entity = block.createTileEntity(null, i);
|
||||
renderTileEntity((TileEntityMachine) entity, 0.0, -0.1, 0.0, 0.0625f);
|
||||
renderTileEntity(getInventoryTile(block, i), 0.0, -0.1, 0.0, 0.0625f);
|
||||
}
|
||||
|
||||
private TileEntityMachine getInventoryTile(Block block, int metadata) {
|
||||
Map<Integer, TileEntityMachine> tiles = inventoryTiles.computeIfAbsent(block, key -> new HashMap<>());
|
||||
TileEntityMachine tile = tiles.get(metadata);
|
||||
if (tile == null) {
|
||||
if (!(block.createTileEntity(null, metadata) instanceof TileEntityMachine created)) {
|
||||
return null;
|
||||
}
|
||||
tile = created;
|
||||
tiles.put(metadata, tile);
|
||||
}
|
||||
return tile;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,6 +21,11 @@ public class TileEntityMachine extends TileEntityMachineBase implements INetwork
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUpdate() {
|
||||
return machine == null || machine.getPackage() == null || machine.getPackage().isTickable();
|
||||
}
|
||||
|
||||
public TileEntityMachine(MachinePackage pack) {
|
||||
setMachine(pack);
|
||||
}
|
||||
|
||||
@@ -21,19 +21,23 @@ import cpw.mods.fml.common.Optional;
|
||||
|
||||
public class TileEntityMachineBase extends TileEntity implements IInventoryMachine, ITankMachine, IPoweredMachine {
|
||||
|
||||
private static final DefaultInventory DEFAULT_INVENTORY = new DefaultInventory();
|
||||
private static final DefaultTankContainer DEFAULT_TANK_CONTAINER = new DefaultTankContainer();
|
||||
private static final DefaultPower DEFAULT_POWER = new DefaultPower();
|
||||
|
||||
public IInventoryMachine getInventory() {
|
||||
IInventoryMachine inv = Machine.getInterface(IInventoryMachine.class, this);
|
||||
return (inv == null || inv == this) ? new DefaultInventory() : inv;
|
||||
return (inv == null || inv == this) ? DEFAULT_INVENTORY : inv;
|
||||
}
|
||||
|
||||
public ITankMachine getTankContainer() {
|
||||
ITankMachine inv = Machine.getInterface(ITankMachine.class, this);
|
||||
return (inv == null || inv == this) ? new DefaultTankContainer() : inv;
|
||||
return (inv == null || inv == this) ? DEFAULT_TANK_CONTAINER : inv;
|
||||
}
|
||||
|
||||
public IPoweredMachine getPower() {
|
||||
IPoweredMachine inv = Machine.getInterface(IPoweredMachine.class, this);
|
||||
return (inv == null || inv == this) ? new DefaultPower() : inv;
|
||||
return (inv == null || inv == this) ? DEFAULT_POWER : inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -49,6 +49,11 @@ enum Compartment implements IMachineType {
|
||||
return new TileEntityMachine(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTickable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderMachine(Machine machine, double x, double y, double z, float partialTick) {
|
||||
MachineRendererCompartment.instance.renderMachine(machine, renderTexture, x, y, z);
|
||||
|
||||
@@ -37,6 +37,7 @@ import binnie.core.craftgui.events.EventMouse;
|
||||
import binnie.core.craftgui.events.EventTextEdit;
|
||||
import binnie.core.craftgui.events.EventValueChanged;
|
||||
import binnie.core.craftgui.geometry.CraftGUIUtil;
|
||||
import binnie.core.craftgui.geometry.IArea;
|
||||
import binnie.core.craftgui.geometry.IBorder;
|
||||
import binnie.core.craftgui.geometry.IPoint;
|
||||
import binnie.core.craftgui.geometry.Position;
|
||||
@@ -372,7 +373,20 @@ public class WindowCompartment extends WindowMachine implements IWindowAffectsSh
|
||||
.texture(CraftGUITexture.Outline, getArea().inset(new IBorder(0.0f, 6.0f, 0.0f, 0.0f)));
|
||||
}
|
||||
};
|
||||
slotGrid = new Control(scroll, 1.0f, 1.0f, 108.0f, 18.0f);
|
||||
slotGrid = new Control(scroll, 1.0f, 1.0f, 108.0f, 18.0f) {
|
||||
|
||||
@Override
|
||||
public boolean isChildVisible(IWidget child) {
|
||||
IArea visible = getCroppedZone();
|
||||
if (visible == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
float top = -getOffset().y();
|
||||
float childTop = child.getOriginalPosition().y() + child.getOffset().y();
|
||||
return childTop + child.getSize().y() > top && childTop < top + visible.h();
|
||||
}
|
||||
};
|
||||
scroll.setScrollableContent(slotGrid);
|
||||
new ControlPlayerInventory(this, true).createAndRegister();
|
||||
new ControlTextEdit(this, 16.0f, 16.0f, 100.0f, 14.0f).addEventHandler(new EventTextEdit.Handler() {
|
||||
|
||||
@@ -9,6 +9,8 @@ public class BinnieResource {
|
||||
String mod;
|
||||
private final ResourceType type;
|
||||
String path;
|
||||
private final String shortPath;
|
||||
private final ResourceLocation resourceLocation;
|
||||
|
||||
public BinnieResource(AbstractMod mod, ResourceType type, String path) {
|
||||
this(mod.getModID(), type, path);
|
||||
@@ -18,13 +20,15 @@ public class BinnieResource {
|
||||
mod = modid;
|
||||
this.type = type;
|
||||
this.path = path;
|
||||
shortPath = "textures/" + type + "/" + path;
|
||||
resourceLocation = new ResourceLocation(modid, shortPath);
|
||||
}
|
||||
|
||||
public ResourceLocation getResourceLocation() {
|
||||
return new ResourceLocation(mod, "textures/" + type.toString() + "/" + path);
|
||||
return resourceLocation;
|
||||
}
|
||||
|
||||
public String getShortPath() {
|
||||
return "textures/" + type.toString() + "/" + path;
|
||||
return shortPath;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user