mirror of
https://github.com/GTNewHorizons/EnderCore.git
synced 2026-11-25 06:14:33 +00:00
Add widget system, more code from EIO, merge some EIO and ttCore classes
This commit is contained in:
1 parent
063e7688f2
commit
31b72d1295
55 files changed
+1232
-834
No files matched your search
@@ -0,0 +1,17 @@
|
||||
package com.enderio.core.api.client.gui;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IAdvancedTooltipProvider {
|
||||
|
||||
public void addCommonEntries(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag);
|
||||
|
||||
public void addBasicEntries(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag);
|
||||
|
||||
public void addDetailedEntries(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag);
|
||||
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.enderio.core.client.gui;
|
||||
package com.enderio.core.api.client.gui;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
|
||||
+5
-1
@@ -1,6 +1,10 @@
|
||||
package com.enderio.core.client.gui;
|
||||
package com.enderio.core.api.client.gui;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.enderio.core.client.gui.widget.GhostSlot;
|
||||
import com.enderio.core.client.gui.widget.GuiToolTip;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
|
||||
public interface IGuiScreen {
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.enderio.core.api.client.gui;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IResourceTooltipProvider {
|
||||
|
||||
String getUnlocalizedNameForTooltip(ItemStack itemStack);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.enderio.core.api.client.gui;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
|
||||
import com.enderio.core.api.client.render.IWidgetIcon;
|
||||
|
||||
public interface ITabPanel {
|
||||
|
||||
void onGuiInit(int x, int y, int width, int height);
|
||||
|
||||
void deactivate();
|
||||
|
||||
IWidgetIcon getIcon();
|
||||
|
||||
void render(float par1, int par2, int par3);
|
||||
|
||||
void actionPerformed(GuiButton guiButton);
|
||||
|
||||
void mouseClicked(int x, int y, int par3);
|
||||
|
||||
void keyTyped(char par1, int par2);
|
||||
|
||||
void updateScreen();
|
||||
|
||||
}
|
||||
+3
-1
@@ -1,4 +1,6 @@
|
||||
package com.enderio.core.client.gui;
|
||||
package com.enderio.core.api.client.gui;
|
||||
|
||||
import com.enderio.core.client.gui.widget.GuiScrollableList;
|
||||
|
||||
public interface ListSelectionListener<T> {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.enderio.core.client.render;
|
||||
package com.enderio.core.api.client.render;
|
||||
|
||||
public interface IConnectedTextureRenderer {
|
||||
|
||||
+2
-1
@@ -1,7 +1,8 @@
|
||||
package com.enderio.core.client.render;
|
||||
package com.enderio.core.api.client.render;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.enderio.core.client.render.CustomRenderBlocks;
|
||||
import com.enderio.core.common.vecmath.Vertex;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.enderio.core.api.client.render;
|
||||
|
||||
public interface IWidgetIcon {
|
||||
|
||||
int getX();
|
||||
|
||||
int getY();
|
||||
|
||||
int getWidth();
|
||||
|
||||
int getHeight();
|
||||
|
||||
IWidgetIcon getOverlay();
|
||||
|
||||
IWidgetMap getMap();
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.enderio.core.api.client.render;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.enderio.core.client.render.RenderUtil;
|
||||
|
||||
public interface IWidgetMap {
|
||||
|
||||
int getSize();
|
||||
|
||||
ResourceLocation getTexture();
|
||||
|
||||
void render(IWidgetIcon widget, double x, double y);
|
||||
|
||||
void render(IWidgetIcon widget, double x, double y, boolean doDraw);
|
||||
|
||||
void render(IWidgetIcon widget, double x, double y, double width, double height, double zLevel, boolean doDraw);
|
||||
|
||||
void render(IWidgetIcon widget, double x, double y, double width, double height, double zLevel, boolean doDraw, boolean flipY);
|
||||
|
||||
@RequiredArgsConstructor
|
||||
static class WidgetMapImpl implements IWidgetMap {
|
||||
|
||||
private final int size;
|
||||
private final ResourceLocation res;
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getTexture() {
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(IWidgetIcon widget, double x, double y) {
|
||||
render(widget, x, y, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(IWidgetIcon widget, double x, double y, boolean doDraw) {
|
||||
render(widget, x, y, widget.getWidth(), widget.getHeight(), 0, doDraw);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(IWidgetIcon widget, double x, double y, double width, double height, double zLevel, boolean doDraw) {
|
||||
render(widget, x, y, width, height, zLevel, doDraw, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(IWidgetIcon widget, double x, double y, double width, double height, double zLevel, boolean doDraw, boolean flipY) {
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
if (doDraw) {
|
||||
RenderUtil.bindTexture(getTexture());
|
||||
tessellator.startDrawingQuads();
|
||||
}
|
||||
double minU = (double) widget.getX() / getSize();
|
||||
double maxU = (double) (widget.getX() + widget.getWidth()) / getSize();
|
||||
double minV = (double) widget.getY() / getSize();
|
||||
double maxV = (double) (widget.getY() + widget.getHeight()) / getSize();
|
||||
|
||||
if (flipY) {
|
||||
tessellator.addVertexWithUV(x, y + height, zLevel, minU, minV);
|
||||
tessellator.addVertexWithUV(x + width, y + height, zLevel, maxU, minV);
|
||||
tessellator.addVertexWithUV(x + width, y + 0, zLevel, maxU, maxV);
|
||||
tessellator.addVertexWithUV(x, y + 0, zLevel, minU, maxV);
|
||||
} else {
|
||||
tessellator.addVertexWithUV(x, y + height, zLevel, minU, maxV);
|
||||
tessellator.addVertexWithUV(x + width, y + height, zLevel, maxU, maxV);
|
||||
tessellator.addVertexWithUV(x + width, y + 0, zLevel, maxU, minV);
|
||||
tessellator.addVertexWithUV(x, y + 0, zLevel, minU, minV);
|
||||
}
|
||||
if (widget.getOverlay() != null) {
|
||||
widget.getOverlay().getMap().render(widget.getOverlay(), x, y, width, height, zLevel, false, flipY);
|
||||
}
|
||||
if (doDraw) {
|
||||
tessellator.draw();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.enderio.core.client.render;
|
||||
package com.enderio.core.api.client.render;
|
||||
|
||||
import com.enderio.core.common.vecmath.Vector3d;
|
||||
import com.enderio.core.common.vecmath.Vector3f;
|
||||
@@ -1,42 +0,0 @@
|
||||
package com.enderio.core.client.gui;
|
||||
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.enderio.core.client.render.RenderUtil;
|
||||
|
||||
class FakeEmptySlot {
|
||||
|
||||
private static final int WIDTH = ItemButton.DEFAULT_WIDTH;
|
||||
private static final int HWIDTH = ItemButton.HWIDTH;
|
||||
private static final int HEIGHT = ItemButton.DEFAULT_HEIGHT;
|
||||
private static final int HHEIGHT = ItemButton.HHEIGHT;
|
||||
|
||||
private int xPosition;
|
||||
private int yPosition;
|
||||
private GuiScreen g;
|
||||
|
||||
public FakeEmptySlot(GuiScreen g, int x, int y) {
|
||||
xPosition = x;
|
||||
yPosition = y;
|
||||
this.g = g;
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("synthetic-access")
|
||||
public void drawSlot() {
|
||||
RenderUtil.bindItemTexture();
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
int hoverState = 0;
|
||||
// top half
|
||||
g.drawTexturedModalRect(xPosition, yPosition, 0, 46 + hoverState * 20, HWIDTH, HHEIGHT);
|
||||
g.drawTexturedModalRect(xPosition + HWIDTH, yPosition, 200 - HWIDTH, 46 + hoverState * 20, HWIDTH, HHEIGHT);
|
||||
// bottom half
|
||||
g.drawTexturedModalRect(xPosition, yPosition + HHEIGHT, 0, 64 - HHEIGHT + (hoverState * 20), HWIDTH, HHEIGHT);
|
||||
g.drawTexturedModalRect(xPosition + HWIDTH, yPosition + HHEIGHT, 200 - HWIDTH, 64 - HHEIGHT + (hoverState * 20), HWIDTH, HHEIGHT);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,7 +23,14 @@ import codechicken.nei.VisiblityData;
|
||||
import codechicken.nei.api.INEIGuiHandler;
|
||||
import codechicken.nei.api.TaggedInventoryArea;
|
||||
|
||||
import com.enderio.core.api.client.gui.IGuiOverlay;
|
||||
import com.enderio.core.api.client.gui.IGuiScreen;
|
||||
import com.enderio.core.client.gui.ToolTipManager.ToolTipRenderer;
|
||||
import com.enderio.core.client.gui.button.IconButton;
|
||||
import com.enderio.core.client.gui.widget.GhostSlot;
|
||||
import com.enderio.core.client.gui.widget.GuiToolTip;
|
||||
import com.enderio.core.client.gui.widget.TextFieldEnder;
|
||||
import com.enderio.core.client.gui.widget.VScrollbar;
|
||||
import com.enderio.core.client.render.RenderUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@@ -36,12 +43,12 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
|
||||
protected ToolTipManager ttMan = new ToolTipManager();
|
||||
protected List<IGuiOverlay> overlays = new ArrayList<IGuiOverlay>();
|
||||
protected List<TextFieldEIO> textFields = Lists.newArrayList();
|
||||
protected List<VScrollbarEIO> scrollbars = new ArrayList<VScrollbarEIO>();
|
||||
protected List<TextFieldEnder> textFields = Lists.newArrayList();
|
||||
protected List<VScrollbar> scrollbars = new ArrayList<VScrollbar>();
|
||||
protected List<GhostSlot> ghostSlots = new ArrayList<GhostSlot>();
|
||||
|
||||
protected GhostSlot hoverGhostSlot;
|
||||
protected VScrollbarEIO draggingScrollbar;
|
||||
protected VScrollbar draggingScrollbar;
|
||||
|
||||
protected GuiContainerBase(Container par1Container) {
|
||||
super(par1Container);
|
||||
@@ -54,7 +61,7 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
for (IGuiOverlay overlay : overlays) {
|
||||
overlay.init(this);
|
||||
}
|
||||
for (TextFieldEIO f : textFields) {
|
||||
for (TextFieldEnder f : textFields) {
|
||||
f.init(this);
|
||||
}
|
||||
}
|
||||
@@ -87,7 +94,7 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
// If the user pressed tab, switch to the next text field, or unfocus if there are none
|
||||
if(c == '\t') {
|
||||
for (int i = 0; i < textFields.size(); i++) {
|
||||
TextFieldEIO f = textFields.get(i);
|
||||
TextFieldEnder f = textFields.get(i);
|
||||
if (f.isFocused()) {
|
||||
textFields.get((i + 1) % textFields.size()).setFocused(true);
|
||||
f.setFocused(false);
|
||||
@@ -194,7 +201,7 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
draggingScrollbar.mouseClicked(x, y, button);
|
||||
return;
|
||||
}
|
||||
for(VScrollbarEIO vs : scrollbars) {
|
||||
for(VScrollbar vs : scrollbars) {
|
||||
if(vs.mouseClicked(x, y, button)) {
|
||||
draggingScrollbar = vs;
|
||||
return;
|
||||
@@ -210,7 +217,7 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
}
|
||||
// Right click field clearing
|
||||
if(button == 1) {
|
||||
for (TextFieldEIO tf : textFields) {
|
||||
for (TextFieldEnder tf : textFields) {
|
||||
if(tf.contains(x, y)) {
|
||||
tf.setText("");
|
||||
}
|
||||
@@ -219,8 +226,8 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
// Button events for non-left-clicks
|
||||
if(button >= 1) {
|
||||
for(Object obj : buttonList) {
|
||||
if(obj instanceof IconButtonEIO) {
|
||||
IconButtonEIO btn = (IconButtonEIO) obj;
|
||||
if(obj instanceof IconButton) {
|
||||
IconButton btn = (IconButton) obj;
|
||||
if(btn.mousePressedButton(mc, x, y, button)) {
|
||||
btn.func_146113_a(this.mc.getSoundHandler());
|
||||
actionPerformedButton(btn, button);
|
||||
@@ -251,13 +258,13 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
|
||||
protected void mouseWheel(int x, int y, int delta) {
|
||||
if(!scrollbars.isEmpty()) {
|
||||
for(VScrollbarEIO vs : scrollbars) {
|
||||
for(VScrollbar vs : scrollbars) {
|
||||
vs.mouseWheel(x, y, delta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void actionPerformedButton(IconButtonEIO btn, int mouseButton) {
|
||||
protected void actionPerformedButton(IconButton btn, int mouseButton) {
|
||||
actionPerformed(btn);
|
||||
}
|
||||
|
||||
@@ -269,12 +276,12 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
overlays.remove(overlay);
|
||||
}
|
||||
|
||||
public void addScrollbar(VScrollbarEIO vs) {
|
||||
public void addScrollbar(VScrollbar vs) {
|
||||
scrollbars.add(vs);
|
||||
vs.adjustPosition();
|
||||
}
|
||||
|
||||
public void removeScrollbar(VScrollbarEIO vs) {
|
||||
public void removeScrollbar(VScrollbar vs) {
|
||||
scrollbars.remove(vs);
|
||||
if(draggingScrollbar == vs) {
|
||||
draggingScrollbar = null;
|
||||
@@ -309,7 +316,7 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
f.drawTextBox();
|
||||
}
|
||||
if(!scrollbars.isEmpty()) {
|
||||
for(VScrollbarEIO vs : scrollbars) {
|
||||
for(VScrollbar vs : scrollbars) {
|
||||
vs.drawScrollbar(mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,9 @@ import net.minecraft.client.renderer.RenderHelper;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
import com.enderio.core.api.client.gui.IGuiScreen;
|
||||
import com.enderio.core.client.gui.ToolTipManager.ToolTipRenderer;
|
||||
import com.enderio.core.client.gui.widget.GuiToolTip;
|
||||
|
||||
public abstract class GuiScreenBase extends GuiScreen implements ToolTipRenderer, IGuiScreen {
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ import java.util.List;
|
||||
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
|
||||
import com.enderio.core.client.gui.widget.GuiToolTip;
|
||||
|
||||
public class ToolTipManager {
|
||||
|
||||
public static interface ToolTipRenderer {
|
||||
@@ -17,7 +19,7 @@ public class ToolTipManager {
|
||||
|
||||
FontRenderer getFontRenderer();
|
||||
|
||||
void drawHoveringText(List par1List, int par2, int par3, FontRenderer font);
|
||||
void drawHoveringText(List<String> par1List, int par2, int par3, FontRenderer font);
|
||||
}
|
||||
|
||||
private List<GuiToolTip> toolTips = new ArrayList<GuiToolTip>();
|
||||
@@ -58,7 +60,7 @@ public class ToolTipManager {
|
||||
|
||||
if(mouseX > renderer.getGuiLeft() + renderer.getXSize() / 2) {
|
||||
int maxWidth = 0;
|
||||
Iterator iterator = formatted.iterator();
|
||||
Iterator<String> iterator = formatted.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
String s = (String) iterator.next();
|
||||
int w = renderer.getFontRenderer().getStringWidth(s);
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
package com.enderio.core.client.gui;
|
||||
package com.enderio.core.client.gui.bettermodlist;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
@@ -14,7 +14,7 @@ import cpw.mods.fml.client.GuiModList;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
@Handler(HandlerType.FORGE)
|
||||
public class GuiEventHandler
|
||||
public class EventHandlerGui
|
||||
{
|
||||
private static Field _mainMenu, _parentScreen;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.enderio.core.client.gui;
|
||||
package com.enderio.core.client.gui.bettermodlist;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collections;
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.enderio.core.client.gui.button;
|
||||
|
||||
import com.enderio.core.api.client.gui.IGuiScreen;
|
||||
import com.enderio.core.client.render.EnderWidget;
|
||||
|
||||
public class CheckBox extends ToggleButton {
|
||||
|
||||
public CheckBox(IGuiScreen gui, int id, int x, int y) {
|
||||
super(gui, id, x, y, EnderWidget.BUTTON, EnderWidget.BUTTON_CHECKED);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
package com.enderio.core.client.gui.button;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.item.ItemDye;
|
||||
import net.minecraft.util.MathHelper;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.enderio.core.api.client.gui.IGuiScreen;
|
||||
import com.enderio.core.common.util.DyeColor;
|
||||
|
||||
public class ColorButton extends IconButton {
|
||||
|
||||
private int colorIndex = 0;
|
||||
|
||||
private String tooltipPrefix = "";
|
||||
|
||||
public ColorButton(IGuiScreen gui, int id, int x, int y) {
|
||||
super(gui, id, x, y, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressed(Minecraft par1Minecraft, int par2, int par3) {
|
||||
boolean result = super.mousePressed(par1Minecraft, par2, par3);
|
||||
if(result) {
|
||||
nextColor();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressedButton(Minecraft mc, int x, int y, int button) {
|
||||
boolean result = button == 1 && super.checkMousePress(mc, x, y);
|
||||
if(result) {
|
||||
prevColor();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getTooltipPrefix() {
|
||||
return tooltipPrefix;
|
||||
}
|
||||
|
||||
public void setToolTipHeading(String tooltipPrefix) {
|
||||
if(tooltipPrefix == null) {
|
||||
this.tooltipPrefix = "";
|
||||
} else {
|
||||
this.tooltipPrefix = tooltipPrefix;
|
||||
}
|
||||
}
|
||||
|
||||
private void nextColor() {
|
||||
colorIndex++;
|
||||
if(colorIndex >= ItemDye.field_150923_a.length) {
|
||||
colorIndex = 0;
|
||||
}
|
||||
setColorIndex(colorIndex);
|
||||
}
|
||||
|
||||
private void prevColor() {
|
||||
colorIndex--;
|
||||
if(colorIndex < 0) {
|
||||
colorIndex = ItemDye.field_150923_a.length - 1;
|
||||
}
|
||||
setColorIndex(colorIndex);
|
||||
}
|
||||
|
||||
public int getColorIndex() {
|
||||
return colorIndex;
|
||||
}
|
||||
|
||||
public void setColorIndex(int colorIndex) {
|
||||
this.colorIndex = MathHelper.clamp_int(colorIndex, 0, ItemDye.field_150923_a.length - 1);
|
||||
String colStr = DyeColor.values()[colorIndex].getLocalisedName();
|
||||
if(tooltipPrefix != null && tooltipPrefix.length() > 0) {
|
||||
setToolTip(tooltipPrefix, colStr);
|
||||
} else {
|
||||
setToolTip(colStr);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
|
||||
super.drawButton(mc, mouseX, mouseY);
|
||||
if(visible) {
|
||||
Tessellator tes = Tessellator.instance;
|
||||
tes.startDrawingQuads();
|
||||
|
||||
int x = xPosition + 2;
|
||||
int y = yPosition + 2;
|
||||
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
|
||||
int col = ItemDye.field_150922_c[colorIndex];
|
||||
tes.setColorOpaque_I(col);
|
||||
tes.addVertex(x, y + height - 4, zLevel);
|
||||
tes.addVertex(x + width - 4, y + height - 4, zLevel);
|
||||
tes.addVertex(x + width - 4, y + 0, zLevel);
|
||||
tes.addVertex(x, y + 0, zLevel);
|
||||
|
||||
tes.draw();
|
||||
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
package com.enderio.core.client.gui;
|
||||
package com.enderio.core.client.gui.button;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
@@ -10,7 +10,7 @@ import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.enderio.core.client.render.RenderUtil;
|
||||
|
||||
public class IconButton extends GuiButton {
|
||||
public class IIconButton extends GuiButton {
|
||||
|
||||
public static final int DEFAULT_WIDTH = 24;
|
||||
public static final int HWIDTH = DEFAULT_WIDTH / 2;
|
||||
@@ -23,7 +23,7 @@ public class IconButton extends GuiButton {
|
||||
protected IIcon icon;
|
||||
protected ResourceLocation texture;
|
||||
|
||||
public IconButton(FontRenderer fr, int id, int x, int y, IIcon icon, ResourceLocation texture) {
|
||||
public IIconButton(FontRenderer fr, int id, int x, int y, IIcon icon, ResourceLocation texture) {
|
||||
super(id, x, y, DEFAULT_WIDTH, DEFAULT_HEIGHT, "");
|
||||
hwidth = HWIDTH;
|
||||
hheight = HHEIGHT;
|
||||
+42
-39
@@ -1,23 +1,24 @@
|
||||
package com.enderio.core.client.gui;
|
||||
package com.enderio.core.client.gui.button;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.enderio.core.client.render.RenderUtil;
|
||||
import com.enderio.core.api.client.gui.IGuiScreen;
|
||||
import com.enderio.core.api.client.render.IWidgetIcon;
|
||||
import com.enderio.core.client.gui.widget.GuiToolTip;
|
||||
import com.enderio.core.client.render.EnderWidget;
|
||||
|
||||
public class IconButtonEIO extends GuiButton {
|
||||
public class IconButton extends GuiButton {
|
||||
|
||||
public static final int DEFAULT_WIDTH = 16;
|
||||
public static final int DEFAULT_HEIGHT = 16;
|
||||
|
||||
protected IconEIO icon;
|
||||
protected ResourceLocation texture;
|
||||
protected IWidgetIcon icon;
|
||||
private int xOrigin;
|
||||
private int yOrigin;
|
||||
|
||||
@@ -27,31 +28,30 @@ public class IconButtonEIO extends GuiButton {
|
||||
private int marginY = 0;
|
||||
private int marginX = 0;
|
||||
|
||||
public IconButtonEIO(IGuiScreen gui, int id, int x, int y, IconEIO icon) {
|
||||
public IconButton(IGuiScreen gui, int id, int x, int y, IWidgetIcon icon) {
|
||||
super(id, x, y, DEFAULT_WIDTH, DEFAULT_HEIGHT, "");
|
||||
this.gui = gui;
|
||||
this.icon = icon;
|
||||
texture = IconEIO.TEXTURE;
|
||||
this.xOrigin = x;
|
||||
this.yOrigin = y;
|
||||
}
|
||||
|
||||
|
||||
public void setToolTip(String... tooltipText) {
|
||||
if(toolTip == null) {
|
||||
if (toolTip == null) {
|
||||
toolTip = new GuiToolTip(getBounds(), tooltipText);
|
||||
//gui.addToolTip(toolTip);
|
||||
} else {
|
||||
toolTip.setToolTipText(tooltipText);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public final Rectangle getBounds() {
|
||||
return new Rectangle(xOrigin, yOrigin, getWidth(), getHeight());
|
||||
}
|
||||
|
||||
|
||||
public void onGuiInit() {
|
||||
gui.addButton(this);
|
||||
if(toolTip != null) {
|
||||
if (toolTip != null) {
|
||||
gui.addToolTip(toolTip);
|
||||
}
|
||||
xPosition = xOrigin + gui.getGuiLeft();
|
||||
@@ -69,7 +69,7 @@ public class IconButtonEIO extends GuiButton {
|
||||
updateTooltipBounds();
|
||||
}
|
||||
|
||||
public IconButtonEIO setPosition(int x, int y) {
|
||||
public IconButton setPosition(int x, int y) {
|
||||
this.xOrigin = x;
|
||||
this.yOrigin = y;
|
||||
updateTooltipBounds();
|
||||
@@ -77,12 +77,12 @@ public class IconButtonEIO extends GuiButton {
|
||||
}
|
||||
|
||||
private void updateTooltipBounds() {
|
||||
if(toolTip != null) {
|
||||
if (toolTip != null) {
|
||||
toolTip.setBounds(new Rectangle(xOrigin, yOrigin, width, height));
|
||||
}
|
||||
}
|
||||
|
||||
public IconButtonEIO setIconMargin(int x, int y) {
|
||||
public IconButton setIconMargin(int x, int y) {
|
||||
marginX = x;
|
||||
marginY = y;
|
||||
return this;
|
||||
@@ -96,24 +96,29 @@ public class IconButtonEIO extends GuiButton {
|
||||
return height;
|
||||
}
|
||||
|
||||
public IconEIO getIcon() {
|
||||
public IWidgetIcon getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
public void setIcon(IconEIO icon) {
|
||||
public void setIcon(IWidgetIcon icon) {
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
|
||||
public GuiToolTip getToolTip() {
|
||||
return toolTip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this to handle mouse clicks with other buttons than the left
|
||||
* @param mc The MC instance
|
||||
* @param x X coordinate of mouse click
|
||||
* @param y Y coordinate of mouse click
|
||||
* @param button the mouse button - only called for button >= 1
|
||||
*
|
||||
* @param mc
|
||||
* The MC instance
|
||||
* @param x
|
||||
* X coordinate of mouse click
|
||||
* @param y
|
||||
* Y coordinate of mouse click
|
||||
* @param button
|
||||
* the mouse button - only called for button >= 1
|
||||
* @return true if the mouse click is handled
|
||||
*/
|
||||
public boolean mousePressedButton(Minecraft mc, int x, int y, int button) {
|
||||
@@ -131,20 +136,18 @@ public class IconButtonEIO extends GuiButton {
|
||||
@SuppressWarnings("synthetic-access")
|
||||
@Override
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
|
||||
if(toolTip != null) {
|
||||
if (toolTip != null) {
|
||||
toolTip.setVisible(visible);
|
||||
}
|
||||
if(visible) {
|
||||
}
|
||||
if (visible) {
|
||||
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.field_146123_n = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + width
|
||||
&& mouseY < this.yPosition + height;
|
||||
this.field_146123_n = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + width && mouseY < this.yPosition + height;
|
||||
int hoverState = getHoverState(this.field_146123_n);
|
||||
mouseDragged(mc, mouseX, mouseY);
|
||||
|
||||
IconEIO background = getIconForHoverState(hoverState);
|
||||
IWidgetIcon background = getIconForHoverState(hoverState);
|
||||
|
||||
RenderUtil.bindTexture(texture);
|
||||
GL11.glColor3f(1, 1, 1);
|
||||
|
||||
Tessellator tes = Tessellator.instance;
|
||||
@@ -157,9 +160,9 @@ public class IconButtonEIO extends GuiButton {
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
background.renderIcon(x, y, width, height, 0, false);
|
||||
if(icon != null) {
|
||||
icon.renderIcon(x + marginX, y + marginY, width - (2 * marginX), height - (2 * marginY), 0, false);
|
||||
background.getMap().render(background, x, y, width, height, 0, false);
|
||||
if (icon != null) {
|
||||
icon.getMap().render(icon, x + marginX, y + marginY, width - (2 * marginX), height - (2 * marginY), 0, false);
|
||||
}
|
||||
|
||||
tes.draw();
|
||||
@@ -169,14 +172,14 @@ public class IconButtonEIO extends GuiButton {
|
||||
}
|
||||
}
|
||||
|
||||
protected IconEIO getIconForHoverState(int hoverState) {
|
||||
if(hoverState == 0) {
|
||||
return IconEIO.BUTTON_DISABLED;
|
||||
protected IWidgetIcon getIconForHoverState(int hoverState) {
|
||||
if (hoverState == 0) {
|
||||
return EnderWidget.BUTTON_DISABLED;
|
||||
}
|
||||
if(hoverState == 2) {
|
||||
return IconEIO.BUTTON_HIGHLIGHT;
|
||||
if (hoverState == 2) {
|
||||
return EnderWidget.BUTTON_HIGHLIGHT;
|
||||
}
|
||||
return IconEIO.BUTTON;
|
||||
return EnderWidget.BUTTON;
|
||||
}
|
||||
|
||||
}
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
package com.enderio.core.client.gui;
|
||||
package com.enderio.core.client.gui.button;
|
||||
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class IconToggleButton extends IconButton {
|
||||
public class IconToggleButton extends IIconButton {
|
||||
|
||||
private boolean selected = false;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.enderio.core.client.gui;
|
||||
package com.enderio.core.client.gui.button;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.enderio.core.client.gui.button;
|
||||
|
||||
import com.enderio.core.api.client.gui.IGuiScreen;
|
||||
import com.enderio.core.api.client.render.IWidgetIcon;
|
||||
import com.enderio.core.client.render.EnderWidget;
|
||||
|
||||
public class MultiIconButton extends IconButton {
|
||||
|
||||
private final IWidgetIcon unpressed;
|
||||
private final IWidgetIcon pressed;
|
||||
private final IWidgetIcon hover;
|
||||
|
||||
public MultiIconButton(IGuiScreen gui, int id, int x, int y, IWidgetIcon unpressed, IWidgetIcon pressed, IWidgetIcon hover) {
|
||||
super(gui, id, x, y, null);
|
||||
this.unpressed = unpressed;
|
||||
this.pressed = pressed;
|
||||
this.hover = hover;
|
||||
setSize((int) unpressed.getWidth(), (int) unpressed.getHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IWidgetIcon getIconForHoverState(int hoverState) {
|
||||
if (hoverState == 0) {
|
||||
return pressed;
|
||||
}
|
||||
if (hoverState == 2) {
|
||||
return hover;
|
||||
}
|
||||
return unpressed;
|
||||
}
|
||||
|
||||
public static MultiIconButton createRightArrowButton(IGuiScreen gui, int id, int x, int y) {
|
||||
return new MultiIconButton(gui, id, x, y, EnderWidget.RIGHT_ARROW, EnderWidget.RIGHT_ARROW_PRESSED, EnderWidget.RIGHT_ARROW_HOVER);
|
||||
}
|
||||
|
||||
public static MultiIconButton createLeftArrowButton(IGuiScreen gui, int id, int x, int y) {
|
||||
return new MultiIconButton(gui, id, x, y, EnderWidget.LEFT_ARROW, EnderWidget.LEFT_ARROW_PRESSED, EnderWidget.LEFT_ARROW_HOVER);
|
||||
}
|
||||
|
||||
public static MultiIconButton createAddButton(IGuiScreen gui, int id, int x, int y) {
|
||||
return new MultiIconButton(gui, id, x, y, EnderWidget.ADD_BUT, EnderWidget.ADD_BUT_PRESSED, EnderWidget.ADD_BUT_HOVER);
|
||||
}
|
||||
|
||||
public static MultiIconButton createMinusButton(IGuiScreen gui, int id, int x, int y) {
|
||||
return new MultiIconButton(gui, id, x, y, EnderWidget.MINUS_BUT, EnderWidget.MINUS_BUT_PRESSED, EnderWidget.MINUS_BUT_HOVER);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.enderio.core.client.gui.button;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
import com.enderio.core.api.client.gui.IGuiScreen;
|
||||
import com.enderio.core.api.client.render.IWidgetIcon;
|
||||
import com.enderio.core.client.render.EnderWidget;
|
||||
|
||||
public class ToggleButton extends IconButton {
|
||||
|
||||
private boolean selected;
|
||||
private final IWidgetIcon unselectedIcon;
|
||||
private final IWidgetIcon selectedIcon;
|
||||
|
||||
private String[] selectedTooltip;
|
||||
private String[] unselectedTooltip;
|
||||
private boolean paintSelectionBorder;
|
||||
|
||||
public ToggleButton(IGuiScreen gui, int id, int x, int y, IWidgetIcon unselectedIcon, IWidgetIcon selectedIcon) {
|
||||
super(gui, id, x, y, unselectedIcon);
|
||||
this.unselectedIcon = unselectedIcon;
|
||||
this.selectedIcon = selectedIcon;
|
||||
selected = false;
|
||||
paintSelectionBorder = true;
|
||||
}
|
||||
|
||||
public boolean isSelected() {
|
||||
return selected;
|
||||
}
|
||||
|
||||
public ToggleButton setSelected(boolean selected) {
|
||||
this.selected = selected;
|
||||
icon = selected ? selectedIcon : unselectedIcon;
|
||||
if (selected && selectedTooltip != null) {
|
||||
setToolTip(selectedTooltip);
|
||||
} else if (!selected && unselectedTooltip != null) {
|
||||
setToolTip(unselectedTooltip);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IWidgetIcon getIconForHoverState(int hoverState) {
|
||||
if (!selected || !paintSelectionBorder) {
|
||||
return super.getIconForHoverState(hoverState);
|
||||
}
|
||||
if (hoverState == 0) {
|
||||
return EnderWidget.BUTTON_DISABLED;
|
||||
}
|
||||
if (hoverState == 2) {
|
||||
return EnderWidget.BUTTON_DOWN_HIGHLIGHT;
|
||||
}
|
||||
return EnderWidget.BUTTON_DOWN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressed(Minecraft par1Minecraft, int par2, int par3) {
|
||||
if (super.mousePressed(par1Minecraft, par2, par3)) {
|
||||
return toggleSelected();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean toggleSelected() {
|
||||
setSelected(!selected);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setSelectedToolTip(String... tt) {
|
||||
this.selectedTooltip = tt;
|
||||
setSelected(selected);
|
||||
}
|
||||
|
||||
public void setUnselectedToolTip(String... tt) {
|
||||
this.unselectedTooltip = tt;
|
||||
setSelected(selected);
|
||||
}
|
||||
|
||||
public void setPaintSelectedBorder(boolean b) {
|
||||
this.paintSelectionBorder = b;
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.enderio.core.client.gui;
|
||||
package com.enderio.core.client.gui.widget;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
+4
-1
@@ -1,4 +1,4 @@
|
||||
package com.enderio.core.client.gui;
|
||||
package com.enderio.core.client.gui.widget;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
@@ -11,6 +11,9 @@ import net.minecraft.client.renderer.Tessellator;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.enderio.core.api.client.gui.IGuiScreen;
|
||||
import com.enderio.core.api.client.gui.ListSelectionListener;
|
||||
|
||||
public abstract class GuiScrollableList<T> {
|
||||
|
||||
private final Minecraft mc = Minecraft.getMinecraft();
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.enderio.core.client.gui;
|
||||
package com.enderio.core.client.gui.widget;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.enderio.core.client.gui;
|
||||
package com.enderio.core.client.gui.widget;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
+10
-9
@@ -1,38 +1,39 @@
|
||||
package com.enderio.core.client.gui;
|
||||
package com.enderio.core.client.gui.widget;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
|
||||
import com.enderio.core.api.client.gui.IGuiScreen;
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
|
||||
public class TextFieldEIO extends GuiTextField {
|
||||
public class TextFieldEnder extends GuiTextField {
|
||||
|
||||
public interface ICharFilter {
|
||||
|
||||
boolean passesFilter(TextFieldEIO tf, char c);
|
||||
boolean passesFilter(TextFieldEnder tf, char c);
|
||||
}
|
||||
|
||||
public static final ICharFilter FILTER_NUMERIC = new ICharFilter() {
|
||||
@Override
|
||||
public boolean passesFilter(TextFieldEIO tf, char c) {
|
||||
public boolean passesFilter(TextFieldEnder tf, char c) {
|
||||
return Character.isDigit(c) || (c == '-' && Strings.isNullOrEmpty(tf.getText()));
|
||||
}
|
||||
};
|
||||
|
||||
public static ICharFilter FILTER_ALPHABETICAL = new ICharFilter() {
|
||||
@Override
|
||||
public boolean passesFilter(TextFieldEIO tf, char c) {
|
||||
public boolean passesFilter(TextFieldEnder tf, char c) {
|
||||
return Character.isLetter(c);
|
||||
}
|
||||
};
|
||||
|
||||
public static ICharFilter FILTER_ALPHANUMERIC = new ICharFilter() {
|
||||
@Override
|
||||
public boolean passesFilter(TextFieldEIO tf, char c) {
|
||||
public boolean passesFilter(TextFieldEnder tf, char c) {
|
||||
return FILTER_NUMERIC.passesFilter(tf, c) || FILTER_ALPHABETICAL.passesFilter(tf, c);
|
||||
}
|
||||
};
|
||||
@@ -52,11 +53,11 @@ public class TextFieldEIO extends GuiTextField {
|
||||
}
|
||||
}
|
||||
|
||||
public TextFieldEIO(FontRenderer fnt, int x, int y, int width, int height) {
|
||||
public TextFieldEnder(FontRenderer fnt, int x, int y, int width, int height) {
|
||||
this(fnt, x, y, width, height, null);
|
||||
}
|
||||
|
||||
public TextFieldEIO(FontRenderer fnt, int x, int y, int width, int height, ICharFilter charFilter) {
|
||||
public TextFieldEnder(FontRenderer fnt, int x, int y, int width, int height, ICharFilter charFilter) {
|
||||
super(fnt, x, y, width, height);
|
||||
this.xOrigin = x;
|
||||
this.yOrigin = y;
|
||||
@@ -68,7 +69,7 @@ public class TextFieldEIO extends GuiTextField {
|
||||
this.yPosition = yOrigin + gui.getGuiTop();
|
||||
}
|
||||
|
||||
public TextFieldEIO setCharFilter(ICharFilter filter) {
|
||||
public TextFieldEnder setCharFilter(ICharFilter filter) {
|
||||
this.filter = filter;
|
||||
return this;
|
||||
}
|
||||
+51
-50
@@ -1,4 +1,4 @@
|
||||
package com.enderio.core.client.gui;
|
||||
package com.enderio.core.client.gui.widget;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
|
||||
@@ -7,9 +7,12 @@ import net.minecraft.client.renderer.Tessellator;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.enderio.core.api.client.gui.IGuiScreen;
|
||||
import com.enderio.core.api.client.render.IWidgetIcon;
|
||||
import com.enderio.core.client.render.EnderWidget;
|
||||
import com.enderio.core.client.render.RenderUtil;
|
||||
|
||||
public class VScrollbarEIO {
|
||||
public class VScrollbar {
|
||||
|
||||
protected final IGuiScreen gui;
|
||||
|
||||
@@ -33,7 +36,7 @@ public class VScrollbarEIO {
|
||||
protected int scrollDir;
|
||||
protected long timeNextScroll;
|
||||
|
||||
public VScrollbarEIO(IGuiScreen gui, int xOrigin, int yOrigin, int height) {
|
||||
public VScrollbar(IGuiScreen gui, int xOrigin, int yOrigin, int height) {
|
||||
this.gui = gui;
|
||||
this.xOrigin = xOrigin;
|
||||
this.yOrigin = yOrigin;
|
||||
@@ -43,14 +46,12 @@ public class VScrollbarEIO {
|
||||
public void adjustPosition() {
|
||||
xPosition = xOrigin + gui.getGuiLeft();
|
||||
yPosition = yOrigin + gui.getGuiTop();
|
||||
wholeArea = new Rectangle(xPosition, yPosition,
|
||||
(int)IconEIO.VSCROLL_THUMB_OFF.width, height);
|
||||
btnUp = new Rectangle(xPosition, yPosition,
|
||||
(int)IconEIO.UP_ARROW_OFF.width, (int)IconEIO.UP_ARROW_OFF.height);
|
||||
btnDown = new Rectangle(xPosition, yPosition + Math.max(0, height - (int)IconEIO.DOWN_ARROW_OFF.height),
|
||||
(int)IconEIO.DOWN_ARROW_OFF.width, (int)IconEIO.DOWN_ARROW_OFF.height);
|
||||
thumbArea = new Rectangle(xPosition, yPosition + btnUp.height,
|
||||
(int)IconEIO.VSCROLL_THUMB_OFF.width, Math.max(0, height - (btnUp.height + btnDown.height)));
|
||||
wholeArea = new Rectangle(xPosition, yPosition, (int) EnderWidget.VSCROLL_THUMB_OFF.width, height);
|
||||
btnUp = new Rectangle(xPosition, yPosition, (int) EnderWidget.UP_ARROW_OFF.width, (int) EnderWidget.UP_ARROW_OFF.height);
|
||||
btnDown = new Rectangle(xPosition, yPosition + Math.max(0, height - (int) EnderWidget.DOWN_ARROW_OFF.height), (int) EnderWidget.DOWN_ARROW_OFF.width,
|
||||
(int) EnderWidget.DOWN_ARROW_OFF.height);
|
||||
thumbArea = new Rectangle(xPosition, yPosition + btnUp.height, (int) EnderWidget.VSCROLL_THUMB_OFF.width, Math.max(0, height
|
||||
- (btnUp.height + btnDown.height)));
|
||||
}
|
||||
|
||||
public int getScrollPos() {
|
||||
@@ -75,32 +76,32 @@ public class VScrollbarEIO {
|
||||
}
|
||||
|
||||
public void drawScrollbar(int mouseX, int mouseY) {
|
||||
boolean hoverUp = btnUp.contains(mouseX, mouseY);
|
||||
boolean hoverUp = btnUp.contains(mouseX, mouseY);
|
||||
boolean hoverDown = btnDown.contains(mouseX, mouseY);
|
||||
|
||||
IconEIO iconUp;
|
||||
if(pressedUp) {
|
||||
iconUp = hoverUp ? IconEIO.UP_ARROW_HOVER_ON : IconEIO.UP_ARROW_ON;
|
||||
IWidgetIcon iconUp;
|
||||
if (pressedUp) {
|
||||
iconUp = hoverUp ? EnderWidget.UP_ARROW_HOVER_ON : EnderWidget.UP_ARROW_ON;
|
||||
} else {
|
||||
iconUp = hoverUp ? IconEIO.UP_ARROW_HOVER_OFF : IconEIO.UP_ARROW_OFF;
|
||||
iconUp = hoverUp ? EnderWidget.UP_ARROW_HOVER_OFF : EnderWidget.UP_ARROW_OFF;
|
||||
}
|
||||
|
||||
IconEIO iconDown;
|
||||
if(pressedDown) {
|
||||
iconDown = hoverDown ? IconEIO.DOWN_ARROW_HOVER_ON : IconEIO.DOWN_ARROW_ON;
|
||||
IWidgetIcon iconDown;
|
||||
if (pressedDown) {
|
||||
iconDown = hoverDown ? EnderWidget.DOWN_ARROW_HOVER_ON : EnderWidget.DOWN_ARROW_ON;
|
||||
} else {
|
||||
iconDown = hoverDown ? IconEIO.DOWN_ARROW_HOVER_OFF : IconEIO.DOWN_ARROW_OFF;
|
||||
iconDown = hoverDown ? EnderWidget.DOWN_ARROW_HOVER_OFF : EnderWidget.DOWN_ARROW_OFF;
|
||||
}
|
||||
|
||||
if(scrollDir != 0) {
|
||||
if (scrollDir != 0) {
|
||||
long time = Minecraft.getSystemTime();
|
||||
if((timeNextScroll - time) <= 0) {
|
||||
if ((timeNextScroll - time) <= 0) {
|
||||
timeNextScroll = time + 100;
|
||||
scrollBy(scrollDir);
|
||||
}
|
||||
}
|
||||
|
||||
RenderUtil.bindTexture(IconEIO.TEXTURE);
|
||||
RenderUtil.bindTexture(EnderWidget.TEXTURE);
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
@@ -109,20 +110,20 @@ public class VScrollbarEIO {
|
||||
Tessellator tes = Tessellator.instance;
|
||||
tes.startDrawingQuads();
|
||||
|
||||
iconUp.renderIcon(btnUp.x, btnUp.y, false);
|
||||
iconDown.renderIcon(btnDown.x, btnDown.y, false);
|
||||
iconUp.getMap().render(iconUp, btnUp.x, btnUp.y, false);
|
||||
iconDown.getMap().render(iconDown, btnDown.x, btnDown.y, false);
|
||||
|
||||
if(scrollMax > 0) {
|
||||
if (scrollMax > 0) {
|
||||
int thumbPos = getThumbPosition();
|
||||
boolean hoverThumb = thumbArea.contains(mouseX, mouseY) && mouseY >= thumbPos && mouseY < thumbPos + (int) IconEIO.VSCROLL_THUMB_OFF.height;
|
||||
|
||||
IconEIO iconThumb;
|
||||
if(pressedThumb) {
|
||||
iconThumb = IconEIO.VSCROLL_THUMB_HOVER_ON;
|
||||
boolean hoverThumb = thumbArea.contains(mouseX, mouseY) && mouseY >= thumbPos && mouseY < thumbPos + (int) EnderWidget.VSCROLL_THUMB_OFF.height;
|
||||
|
||||
EnderWidget iconThumb;
|
||||
if (pressedThumb) {
|
||||
iconThumb = EnderWidget.VSCROLL_THUMB_HOVER_ON;
|
||||
} else {
|
||||
iconThumb = hoverThumb ? IconEIO.VSCROLL_THUMB_HOVER_OFF : IconEIO.VSCROLL_THUMB_OFF;
|
||||
iconThumb = hoverThumb ? EnderWidget.VSCROLL_THUMB_HOVER_OFF : EnderWidget.VSCROLL_THUMB_OFF;
|
||||
}
|
||||
iconThumb.renderIcon(thumbArea.x, thumbPos, false);
|
||||
iconThumb.getMap().render(iconThumb, thumbArea.x, thumbPos, false);
|
||||
}
|
||||
|
||||
tes.draw();
|
||||
@@ -130,20 +131,20 @@ public class VScrollbarEIO {
|
||||
}
|
||||
|
||||
public boolean mouseClicked(int x, int y, int button) {
|
||||
if(button == 0) {
|
||||
if(scrollMax > 0 && thumbArea.contains(x, y)) {
|
||||
if (button == 0) {
|
||||
if (scrollMax > 0 && thumbArea.contains(x, y)) {
|
||||
int thumbPos = getThumbPosition();
|
||||
pressedUp = y < thumbPos;
|
||||
pressedDown = y >= thumbPos + (int)IconEIO.VSCROLL_THUMB_OFF.height;
|
||||
pressedUp = y < thumbPos;
|
||||
pressedDown = y >= thumbPos + (int) EnderWidget.VSCROLL_THUMB_OFF.height;
|
||||
pressedThumb = !pressedUp && !pressedDown;
|
||||
} else {
|
||||
pressedUp = btnUp.contains(x, y);
|
||||
pressedDown = btnDown.contains(x, y);
|
||||
pressedUp = btnUp.contains(x, y);
|
||||
pressedDown = btnDown.contains(x, y);
|
||||
pressedThumb = false;
|
||||
}
|
||||
|
||||
scrollDir = (pressedDown ? 1 : 0) - (pressedUp ? 1 : 0);
|
||||
if(scrollDir != 0) {
|
||||
if (scrollDir != 0) {
|
||||
timeNextScroll = Minecraft.getSystemTime() + 200;
|
||||
scrollBy(scrollDir);
|
||||
}
|
||||
@@ -152,11 +153,11 @@ public class VScrollbarEIO {
|
||||
}
|
||||
|
||||
public boolean mouseClickMove(int x, int y, int button, long time) {
|
||||
if(pressedThumb) {
|
||||
int pos = y - (thumbArea.y + (int)IconEIO.VSCROLL_THUMB_OFF.height/2);
|
||||
int len = thumbArea.height - (int)IconEIO.VSCROLL_THUMB_OFF.height;
|
||||
if(len > 0) {
|
||||
setScrollPos(Math.round(pos * (float)scrollMax / (float)len));
|
||||
if (pressedThumb) {
|
||||
int pos = y - (thumbArea.y + (int) EnderWidget.VSCROLL_THUMB_OFF.height / 2);
|
||||
int len = thumbArea.height - (int) EnderWidget.VSCROLL_THUMB_OFF.height;
|
||||
if (len > 0) {
|
||||
setScrollPos(Math.round(pos * (float) scrollMax / (float) len));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -164,14 +165,14 @@ public class VScrollbarEIO {
|
||||
}
|
||||
|
||||
public void mouseMovedOrUp(int x, int y, int button) {
|
||||
pressedUp = false;
|
||||
pressedDown = false;
|
||||
pressedUp = false;
|
||||
pressedDown = false;
|
||||
pressedThumb = false;
|
||||
scrollDir = 0;
|
||||
scrollDir = 0;
|
||||
}
|
||||
|
||||
public void mouseWheel(int x, int y, int delta) {
|
||||
if(!isDragActive() && wholeArea.contains(x, y)) {
|
||||
if (!isDragActive() && wholeArea.contains(x, y)) {
|
||||
scrollBy(-Integer.signum(delta));
|
||||
}
|
||||
}
|
||||
@@ -181,7 +182,7 @@ public class VScrollbarEIO {
|
||||
}
|
||||
|
||||
protected int getThumbPosition() {
|
||||
return thumbArea.y + (thumbArea.height - (int)IconEIO.VSCROLL_THUMB_OFF.height) * scrollPos / scrollMax;
|
||||
return thumbArea.y + (thumbArea.height - (int) EnderWidget.VSCROLL_THUMB_OFF.height) * scrollPos / scrollMax;
|
||||
}
|
||||
|
||||
protected int limitPos(int pos) {
|
||||
@@ -3,6 +3,7 @@ package com.enderio.core.client.render;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.enderio.core.api.client.render.VertexTransform;
|
||||
import com.enderio.core.common.util.BlockCoord;
|
||||
import com.enderio.core.common.vecmath.Vector2f;
|
||||
import com.enderio.core.common.vecmath.Vector3d;
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.enderio.core.client.render;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.enderio.core.common.vecmath.Vector3f;
|
||||
import com.enderio.core.common.vecmath.Vector4f;
|
||||
|
||||
@@ -40,9 +42,9 @@ public final class ColorUtil {
|
||||
}
|
||||
|
||||
public static int getRGBA(Vector4f col) {
|
||||
return getRGBA(col.x, col.y,col.z,col.w);
|
||||
return getRGBA(col.x, col.y, col.z, col.w);
|
||||
}
|
||||
|
||||
|
||||
public static int getRGBA(float r, float g, float b, float a) {
|
||||
return getRGBA((int) (r * 255), (int) (g * 255), (int) (b * 255), (int) (a * 255));
|
||||
}
|
||||
@@ -63,6 +65,26 @@ public final class ColorUtil {
|
||||
return (r & 0xFF) << 24 | (g & 0xFF) << 16 | (b & 0xFF) << 8 | (a & 0xFF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns an int into a glColor4f function
|
||||
*
|
||||
* @author Buildcraft team
|
||||
*/
|
||||
public static void setGLColorFromInt(int color) {
|
||||
float red = (color >> 16 & 255) / 255.0F;
|
||||
float green = (color >> 8 & 255) / 255.0F;
|
||||
float blue = (color & 255) / 255.0F;
|
||||
GL11.glColor4f(red, green, blue, 1.0F);
|
||||
}
|
||||
|
||||
public static int toHex(int r, int g, int b) {
|
||||
int hex = 0;
|
||||
hex = hex | ((r) << 16);
|
||||
hex = hex | ((g) << 8);
|
||||
hex = hex | ((b));
|
||||
return hex;
|
||||
}
|
||||
|
||||
private ColorUtil() {
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import com.enderio.core.api.client.render.IConnectedTextureRenderer;
|
||||
import com.enderio.core.api.client.render.IRenderFace;
|
||||
import com.enderio.core.common.util.BlockCoord;
|
||||
import com.enderio.core.common.util.ForgeDirectionOffsets;
|
||||
import com.enderio.core.common.vecmath.Vector2f;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.enderio.core.client.render;
|
||||
|
||||
import com.enderio.core.api.client.render.VertexTransform;
|
||||
import com.enderio.core.common.vecmath.Vector3d;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.enderio.core.client.render;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import com.enderio.core.api.client.render.IRenderFace;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.enderio.core.api.client.render.IRenderFace;
|
||||
import com.enderio.core.common.vecmath.Vertex;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
@@ -12,7 +12,7 @@ import net.minecraftforge.client.model.IModelCustom;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.enderio.core.api.client.model.IEnderModel;
|
||||
import com.enderio.core.common.util.EnderItemUtils;
|
||||
import com.enderio.core.common.util.ItemUtil;
|
||||
|
||||
/**
|
||||
* Renders a model with directional placement
|
||||
@@ -151,7 +151,7 @@ public class DirectionalModelRenderer<T extends TileEntity> extends TileEntitySp
|
||||
break;
|
||||
}
|
||||
|
||||
renderDirectionalTileEntityAt(null, 0, 0, 0, EnderItemUtils.getNBTTag(item).getInteger("storedMetaData"));
|
||||
renderDirectionalTileEntityAt(null, 0, 0, 0, ItemUtil.getNBTTag(item).getInteger("storedMetaData"));
|
||||
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.enderio.core.client.render;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import com.enderio.core.EnderCore;
|
||||
import com.enderio.core.api.client.render.IWidgetIcon;
|
||||
import com.enderio.core.api.client.render.IWidgetMap;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum EnderWidget implements IWidgetIcon {
|
||||
|
||||
BUTTON_BASE(0, 0),
|
||||
UP_ARROW_OFF(212, 64, 11, 8),
|
||||
UP_ARROW_ON(223, 64, 11, 8),
|
||||
UP_ARROW_HOVER_OFF(234, 64, 11, 8),
|
||||
UP_ARROW_HOVER_ON(245, 64, 11, 8),
|
||||
DOWN_ARROW_OFF(212, 72, 11, 8),
|
||||
DOWN_ARROW_ON(223, 72, 11, 8),
|
||||
DOWN_ARROW_HOVER_OFF(234, 72, 11, 8),
|
||||
DOWN_ARROW_HOVER_ON(245, 72, 11, 8),
|
||||
|
||||
VSCROLL_THUMB_OFF(234, 80, 11, 8),
|
||||
VSCROLL_THUMB_HOVER_OFF(234, 88, 11, 8),
|
||||
VSCROLL_THUMB_ON(245, 80, 11, 8),
|
||||
VSCROLL_THUMB_HOVER_ON(245, 88, 11, 8),
|
||||
|
||||
BUTTON(0, 208),
|
||||
BUTTON_HIGHLIGHT(16, 208),
|
||||
BUTTON_DISABLED(32, 208),
|
||||
BUTTON_DOWN(48, 208),
|
||||
BUTTON_DOWN_HIGHLIGHT(64, 208),
|
||||
BUTTON_CHECKED(112, 208),
|
||||
|
||||
LEFT_ARROW(224, 32, 8, 16),
|
||||
LEFT_ARROW_PRESSED(240, 32, 8, 16),
|
||||
LEFT_ARROW_HOVER(224, 48, 8, 16),
|
||||
LEFT_ARROW_HOVER_PRESSED(240, 48, 8, 16),
|
||||
|
||||
RIGHT_ARROW(232, 32, 8, 16),
|
||||
RIGHT_ARROW_PRESSED(248, 32, 8, 16),
|
||||
RIGHT_ARROW_HOVER(232, 48, 8, 16),
|
||||
RIGHT_ARROW_HOVER_PRESSED(248, 48, 8, 16),
|
||||
|
||||
ADD_BUT(208, 32, 8, 8),
|
||||
ADD_BUT_PRESSED(216, 32, 8, 8),
|
||||
ADD_BUT_HOVER(208, 48, 8, 8),
|
||||
ADD_BUT_HOVER_PRESSED(216, 48, 8, 8),
|
||||
|
||||
MINUS_BUT(208, 40, 8, 8),
|
||||
MINUS_BUT_PRESSED(216, 40, 8, 8),
|
||||
MINUS_BUT_HOVER(208, 56, 8, 8),
|
||||
MINUS_BUT_HOVER_PRESSED(216, 56, 8, 8),
|
||||
|
||||
X_BUT(200, 32, 8, 8),
|
||||
X_BUT_PRESSED(200, 40, 8, 8),
|
||||
X_BUT_HOVER(200, 48, 8, 8),
|
||||
X_BUT_HOVER_PRESSED(200, 56, 8, 8);
|
||||
|
||||
public static final ResourceLocation TEXTURE = new ResourceLocation(EnderCore.MODID, "textures/gui/widgets.png");
|
||||
|
||||
public static final IWidgetMap map = new IWidgetMap.WidgetMapImpl(256, TEXTURE);
|
||||
|
||||
public final int x;
|
||||
public final int y;
|
||||
public final int width;
|
||||
public final int height;
|
||||
public final IWidgetIcon overlay;
|
||||
|
||||
EnderWidget(int x, int y) {
|
||||
this(x, y, null);
|
||||
}
|
||||
|
||||
EnderWidget(int x, int y, IWidgetIcon overlay) {
|
||||
this(x, y, 16, 16, overlay);
|
||||
}
|
||||
|
||||
EnderWidget(int x, int y, int width, int height) {
|
||||
this(x, y, width, height, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWidgetMap getMap() {
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.client.resources.IReloadableResourceManager;
|
||||
import net.minecraft.client.resources.IResourceManagerReloadListener;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
@@ -28,12 +29,18 @@ import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.Timer;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.model.obj.Face;
|
||||
import net.minecraftforge.client.model.obj.GroupObject;
|
||||
import net.minecraftforge.client.model.obj.TextureCoordinate;
|
||||
import net.minecraftforge.client.model.obj.WavefrontObject;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.enderio.core.api.client.render.IConnectedTextureRenderer;
|
||||
import com.enderio.core.client.handlers.ClientHandler;
|
||||
import com.enderio.core.common.util.BlockCoord;
|
||||
import com.enderio.core.common.util.Log;
|
||||
import com.enderio.core.common.vecmath.Matrix4d;
|
||||
@@ -45,8 +52,9 @@ import com.enderio.core.common.vecmath.Vector4d;
|
||||
import com.enderio.core.common.vecmath.Vector4f;
|
||||
import com.enderio.core.common.vecmath.Vertex;
|
||||
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
import static net.minecraftforge.common.util.ForgeDirection.*;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
@@ -116,7 +124,7 @@ public class RenderUtil {
|
||||
|
||||
@Nullable
|
||||
public static Timer getTimer() {
|
||||
if(timerField == null) {
|
||||
if (timerField == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
@@ -209,13 +217,13 @@ public class RenderUtil {
|
||||
}
|
||||
|
||||
public static float getColorMultiplierForFace(ForgeDirection face) {
|
||||
if(face == ForgeDirection.UP) {
|
||||
if (face == ForgeDirection.UP) {
|
||||
return 1;
|
||||
}
|
||||
if(face == ForgeDirection.DOWN) {
|
||||
if (face == ForgeDirection.DOWN) {
|
||||
return 0.5f;
|
||||
}
|
||||
if(face.offsetX != 0) {
|
||||
if (face.offsetX != 0) {
|
||||
return 0.6f;
|
||||
}
|
||||
return 0.8f; // z
|
||||
@@ -299,13 +307,13 @@ public class RenderUtil {
|
||||
*/
|
||||
public static List<ForgeDirection> getEdgesForFace(ForgeDirection face) {
|
||||
List<ForgeDirection> result = new ArrayList<ForgeDirection>(4);
|
||||
if(face.offsetY != 0) {
|
||||
if (face.offsetY != 0) {
|
||||
result.add(NORTH);
|
||||
result.add(EAST);
|
||||
result.add(SOUTH);
|
||||
result.add(WEST);
|
||||
|
||||
} else if(face.offsetX != 0) {
|
||||
} else if (face.offsetX != 0) {
|
||||
result.add(DOWN);
|
||||
result.add(SOUTH);
|
||||
result.add(UP);
|
||||
@@ -325,16 +333,16 @@ public class RenderUtil {
|
||||
|
||||
public static void addVerticesToTessellator(List<Vertex> vertices, Tessellator tes) {
|
||||
for (Vertex v : vertices) {
|
||||
if(v.brightness != -1) {
|
||||
if (v.brightness != -1) {
|
||||
tes.setBrightness(v.brightness);
|
||||
}
|
||||
if(v.color != null) {
|
||||
if (v.color != null) {
|
||||
tes.setColorRGBA_F(v.r(), v.g(), v.b(), v.a());
|
||||
}
|
||||
if(v.uv != null) {
|
||||
if (v.uv != null) {
|
||||
tes.setTextureUV(v.u(), v.v());
|
||||
}
|
||||
if(v.normal != null) {
|
||||
if (v.normal != null) {
|
||||
tes.setNormal(v.nx(), v.ny(), v.nz());
|
||||
}
|
||||
tes.addVertex(v.x(), v.y(), v.z());
|
||||
@@ -349,16 +357,16 @@ public class RenderUtil {
|
||||
public static void renderConnectedTextureFace(IBlockAccess blockAccess, Block block, int x, int y, int z, ForgeDirection face, IIcon texture,
|
||||
boolean forceAllEdges, boolean translateToXYZ, boolean applyFaceShading) {
|
||||
|
||||
if((blockAccess == null && !forceAllEdges) || face == null || texture == null) {
|
||||
if ((blockAccess == null && !forceAllEdges) || face == null || texture == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!forceAllEdges) {
|
||||
if (!forceAllEdges) {
|
||||
Block check = blockAccess.getBlock(x, y, z);
|
||||
if(check == null) {
|
||||
if (check == null) {
|
||||
return;
|
||||
}
|
||||
if(!check.shouldSideBeRendered(blockAccess, x + face.offsetX, y + face.offsetY, z + face.offsetZ, face.ordinal())) {
|
||||
if (!check.shouldSideBeRendered(blockAccess, x + face.offsetX, y + face.offsetY, z + face.offsetZ, face.ordinal())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -366,7 +374,7 @@ public class RenderUtil {
|
||||
BlockCoord bc = new BlockCoord(x, y, z);
|
||||
|
||||
List<ForgeDirection> edges;
|
||||
if(forceAllEdges) {
|
||||
if (forceAllEdges) {
|
||||
edges = RenderUtil.getEdgesForFace(face);
|
||||
} else {
|
||||
edges = RenderUtil.getNonConectedEdgesForFace(blockAccess, x, y, z, face);
|
||||
@@ -374,7 +382,7 @@ public class RenderUtil {
|
||||
|
||||
Tessellator tes = Tessellator.instance;
|
||||
tes.setNormal(face.offsetX, face.offsetY, face.offsetZ);
|
||||
if(applyFaceShading) {
|
||||
if (applyFaceShading) {
|
||||
float cm = RenderUtil.getColorMultiplierForFace(face);
|
||||
tes.setColorOpaque_F(cm, cm, cm);
|
||||
}
|
||||
@@ -397,7 +405,7 @@ public class RenderUtil {
|
||||
|
||||
for (Vector3f unitCorn : corners) {
|
||||
Vector3d corner = new Vector3d(unitCorn);
|
||||
if(translateToXYZ) {
|
||||
if (translateToXYZ) {
|
||||
corner.x += x;
|
||||
corner.y += y;
|
||||
corner.z += z;
|
||||
@@ -407,7 +415,7 @@ public class RenderUtil {
|
||||
corner.y += (float) (edge.offsetY * 0.5) - Math.signum(edge.offsetY) * yLen / 2f;
|
||||
corner.z += (float) (edge.offsetZ * 0.5) - Math.signum(edge.offsetZ) * zLen / 2f;
|
||||
|
||||
if(translateToXYZ) {
|
||||
if (translateToXYZ) {
|
||||
RenderUtil.getUvForCorner(uv, corner, x, y, z, face, texture);
|
||||
} else {
|
||||
RenderUtil.getUvForCorner(uv, corner, 0, 0, 0, face, texture);
|
||||
@@ -427,10 +435,10 @@ public class RenderUtil {
|
||||
IConnectedTextureRenderer render) {
|
||||
|
||||
Block block = blockAccess.getBlock(x, y, z);
|
||||
if(block == null) {
|
||||
if (block == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
if(!block.shouldSideBeRendered(blockAccess, x + face.offsetX, y + face.offsetY, z + face.offsetZ, face.ordinal())) {
|
||||
if (!block.shouldSideBeRendered(blockAccess, x + face.offsetX, y + face.offsetY, z + face.offsetZ, face.ordinal())) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
BlockCoord bc = new BlockCoord(x, y, z);
|
||||
@@ -442,10 +450,10 @@ public class RenderUtil {
|
||||
List<ForgeDirection> result = new ArrayList<ForgeDirection>(4);
|
||||
for (EdgeNeighbour edge : edges) {
|
||||
boolean matchingNeighbour = blockAccess.getBlock(edge.bc.x, edge.bc.y, edge.bc.z) == block;
|
||||
if(matchingNeighbour && render != null) {
|
||||
if (matchingNeighbour && render != null) {
|
||||
matchingNeighbour = render.matchesMetadata(blockAccess.getBlockMetadata(x, y, z), blockAccess.getBlockMetadata(edge.bc.x, edge.bc.y, edge.bc.z));
|
||||
}
|
||||
if(!matchingNeighbour) {
|
||||
if (!matchingNeighbour) {
|
||||
result.add(edge.dir);
|
||||
}
|
||||
|
||||
@@ -454,7 +462,7 @@ public class RenderUtil {
|
||||
}
|
||||
|
||||
public static void getUvForCorner(Vector2f uv, Vector3d corner, int x, int y, int z, ForgeDirection face, IIcon icon) {
|
||||
if(icon == null) {
|
||||
if (icon == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -465,7 +473,7 @@ public class RenderUtil {
|
||||
|
||||
float uWidth = 1;
|
||||
float vWidth = 1;
|
||||
if(icon != null) {
|
||||
if (icon != null) {
|
||||
uWidth = icon.getMaxU() - icon.getMinU();
|
||||
vWidth = icon.getMaxV() - icon.getMinV();
|
||||
}
|
||||
@@ -473,7 +481,7 @@ public class RenderUtil {
|
||||
uv.x = (float) VecmathUtil.distanceFromPointToPlane(getUPlaneForFace(face), p);
|
||||
uv.y = (float) VecmathUtil.distanceFromPointToPlane(getVPlaneForFace(face), p);
|
||||
|
||||
if(icon != null) {
|
||||
if (icon != null) {
|
||||
uv.x = icon.getMinU() + (uv.x * uWidth);
|
||||
uv.y = icon.getMinV() + (uv.y * vWidth);
|
||||
}
|
||||
@@ -559,14 +567,14 @@ public class RenderUtil {
|
||||
}
|
||||
|
||||
public static void renderGuiTank(FluidStack fluid, int capacity, int amount, double x, double y, double zLevel, double width, double height) {
|
||||
if(fluid == null || fluid.getFluid() == null || fluid.amount <= 0) {
|
||||
if (fluid == null || fluid.getFluid() == null || fluid.amount <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
IIcon icon = fluid.getFluid().getStillIcon();
|
||||
if(icon == null) {
|
||||
if (icon == null) {
|
||||
icon = fluid.getFluid().getIcon();
|
||||
if(icon == null) {
|
||||
if (icon == null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -625,11 +633,11 @@ public class RenderUtil {
|
||||
glRotatef(-RenderManager.instance.playerViewX, 1.0F, 0.0F, 0.0F);
|
||||
|
||||
glTranslatef(-fnt.getStringWidth(text) / 2, 0, 0);
|
||||
if(drawBackground) {
|
||||
if (drawBackground) {
|
||||
renderBackground(fnt, text, bgCol);
|
||||
}
|
||||
fnt.drawString(text, 0, 0, ColorUtil.getRGBA(txtCol));
|
||||
if(drawShadow) {
|
||||
if (drawShadow) {
|
||||
glTranslatef(0.5f, 0.5f, 0.1f);
|
||||
fnt.drawString(text, 0, 0, ColorUtil.getRGBA(shadowCol));
|
||||
}
|
||||
@@ -664,6 +672,63 @@ public class RenderUtil {
|
||||
glPopAttrib();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders an item entity in 3D
|
||||
*
|
||||
* @param item
|
||||
* The item to render
|
||||
* @param rotate
|
||||
* Whether to "spin" the item like it would if it were a real dropped
|
||||
* entity
|
||||
*/
|
||||
public static void render3DItem(EntityItem item, boolean rotate) {
|
||||
float rot = getRotation(1.0f);
|
||||
|
||||
glPushMatrix();
|
||||
glDepthMask(true);
|
||||
rotate &= Minecraft.getMinecraft().gameSettings.fancyGraphics;
|
||||
|
||||
if (rotate) {
|
||||
glRotatef(rot, 0, 1, 0);
|
||||
}
|
||||
|
||||
item.hoverStart = 0.0F;
|
||||
RenderManager.instance.renderEntityWithPosYaw(item, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F);
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
public static float getRotation(float mult) {
|
||||
return ClientHandler.getTicksElapsed() * mult;
|
||||
}
|
||||
|
||||
public static void renderBillboardQuad(float rot, double scale) {
|
||||
glPushMatrix();
|
||||
|
||||
rotateToPlayer();
|
||||
|
||||
glPushMatrix();
|
||||
|
||||
glRotatef(rot, 0, 0, 1);
|
||||
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
tessellator.startDrawingQuads();
|
||||
glColor3f(1, 1, 1);
|
||||
tessellator.setColorRGBA(255, 255, 255, 255);
|
||||
tessellator.addVertexWithUV(-scale, -scale, 0, 0, 0);
|
||||
tessellator.addVertexWithUV(-scale, scale, 0, 0, 1);
|
||||
tessellator.addVertexWithUV(scale, scale, 0, 1, 1);
|
||||
tessellator.addVertexWithUV(scale, -scale, 0, 1, 0);
|
||||
tessellator.draw();
|
||||
glPopMatrix();
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
public static void rotateToPlayer() {
|
||||
glRotatef(-RenderManager.instance.playerViewY, 0.0F, 1.0F, 0.0F);
|
||||
glRotatef(RenderManager.instance.playerViewX, 1.0F, 0.0F, 0.0F);
|
||||
}
|
||||
|
||||
private static class EdgeNeighbour {
|
||||
final ForgeDirection dir;
|
||||
final BlockCoord bc;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.enderio.core.client.render;
|
||||
|
||||
import com.enderio.core.client.util.RenderingUtils;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.block.Block;
|
||||
@@ -13,40 +11,36 @@ import net.minecraftforge.client.model.obj.WavefrontObject;
|
||||
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class SimpleModelRenderer implements ISimpleBlockRenderingHandler
|
||||
{
|
||||
private final Tessellator tes = Tessellator.instance;
|
||||
public class SimpleModelRenderer implements ISimpleBlockRenderingHandler {
|
||||
private final Tessellator tes = Tessellator.instance;
|
||||
|
||||
private final WavefrontObject model;
|
||||
private final WavefrontObject model;
|
||||
|
||||
@Getter
|
||||
private final int renderId;
|
||||
@Getter
|
||||
private final int renderId;
|
||||
|
||||
@Override
|
||||
public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer)
|
||||
{
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
tes.startDrawingQuads();
|
||||
tes.setColorOpaque_F(1, 1, 1);
|
||||
RenderingUtils.renderWithIcon(model, block.getIcon(0, metadata), tes);
|
||||
tes.draw();
|
||||
RenderHelper.enableStandardItemLighting();
|
||||
}
|
||||
@Override
|
||||
public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) {
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
tes.startDrawingQuads();
|
||||
tes.setColorOpaque_F(1, 1, 1);
|
||||
TechneUtil.renderWithIcon(model, block.getIcon(0, metadata), tes);
|
||||
tes.draw();
|
||||
RenderHelper.enableStandardItemLighting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer)
|
||||
{
|
||||
tes.setBrightness(block.getMixedBrightnessForBlock(world, x, y, z));
|
||||
tes.setColorOpaque_F(1, 1, 1);
|
||||
tes.addTranslation(x + .5F, y + .5F, z + .5F);
|
||||
RenderingUtils.renderWithIcon(model, block.getIcon(0, world.getBlockMetadata(x, y, z)), tes);
|
||||
tes.addTranslation(-x - .5F, -y - .5F, -z - .5F);
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
|
||||
tes.setBrightness(block.getMixedBrightnessForBlock(world, x, y, z));
|
||||
tes.setColorOpaque_F(1, 1, 1);
|
||||
tes.addTranslation(x + .5F, y + .5F, z + .5F);
|
||||
TechneUtil.renderWithIcon(model, block.getIcon(0, world.getBlockMetadata(x, y, z)), tes);
|
||||
tes.addTranslation(-x - .5F, -y - .5F, -z - .5F);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRender3DInInventory(int modelId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean shouldRender3DInInventory(int modelId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@ package com.enderio.core.client.render;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import com.enderio.core.api.client.render.VertexTransform;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
@@ -53,6 +53,7 @@ import net.minecraftforge.client.model.obj.Face;
|
||||
import net.minecraftforge.client.model.obj.GroupObject;
|
||||
import net.minecraftforge.client.model.obj.TextureCoordinate;
|
||||
import net.minecraftforge.client.model.obj.Vertex;
|
||||
import net.minecraftforge.client.model.obj.WavefrontObject;
|
||||
import net.minecraftforge.client.model.techne.TechneModel;
|
||||
import net.minecraftforge.client.model.techne.TechneModelLoader;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
@@ -62,6 +63,7 @@ import org.lwjgl.util.vector.Matrix4f;
|
||||
import org.lwjgl.util.vector.Vector3f;
|
||||
import org.lwjgl.util.vector.Vector4f;
|
||||
|
||||
import com.enderio.core.api.client.render.VertexTransform;
|
||||
import com.enderio.core.common.vecmath.Vector3d;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
@@ -115,13 +117,13 @@ public class TechneUtil {
|
||||
m.translate(new Vector3f(model.offsetX + model.rotationPointX * scale, model.offsetY + model.rotationPointY * scale, model.offsetZ + model.rotationPointZ
|
||||
* scale));
|
||||
|
||||
if(!rotateYFirst) {
|
||||
if (!rotateYFirst) {
|
||||
m.rotate(model.rotateAngleZ, new Vector3f(0, 0, 1));
|
||||
}
|
||||
m.rotate(model.rotateAngleY, new Vector3f(0, 1, 0));
|
||||
m.rotate(model.rotateAngleX, new Vector3f(1, 0, 0));
|
||||
|
||||
if(rotateYFirst) {
|
||||
if (rotateYFirst) {
|
||||
m.rotate(model.rotateAngleZ, new Vector3f(0, 0, 1));
|
||||
}
|
||||
|
||||
@@ -195,7 +197,7 @@ public class TechneUtil {
|
||||
}
|
||||
|
||||
// Second pass, adjust the UVs to be on a 0-1 interpolation scale
|
||||
if(uMult + vMult != 2) {
|
||||
if (uMult + vMult != 2) {
|
||||
for (GroupObject go : res.values()) {
|
||||
for (Face f : go.faces) {
|
||||
for (TextureCoordinate tc : f.textureCoordinates) {
|
||||
@@ -221,6 +223,10 @@ public class TechneUtil {
|
||||
return TechneUtil.bakeModel(tm, 1f / 16, new Matrix4f().scale(new Vector3f(-1, -1, 1))).values();
|
||||
}
|
||||
|
||||
public static void renderWithIcon(WavefrontObject model, IIcon icon, Tessellator tes) {
|
||||
renderWithIcon(model.groupObjects, icon, null, tes);
|
||||
}
|
||||
|
||||
public static void renderWithIcon(Collection<GroupObject> model, IIcon icon, IIcon override, Tessellator tes) {
|
||||
renderWithIcon(model, icon, override, tes, null);
|
||||
}
|
||||
@@ -252,12 +258,12 @@ public class TechneUtil {
|
||||
tes.setNormal(n.x, n.y, n.z);
|
||||
ForgeDirection normal = getNormalFor(n);
|
||||
ForgeDirection right = normal.getRotation(ForgeDirection.DOWN);
|
||||
if(normal == right) {
|
||||
if (normal == right) {
|
||||
right = ForgeDirection.EAST;
|
||||
}
|
||||
ForgeDirection down = normal.getRotation(right.getOpposite());
|
||||
|
||||
if(isbrh && world != null && world.getBlock(x, y, z).getLightOpacity() > 0) {
|
||||
if (isbrh && world != null && world.getBlock(x, y, z).getLightOpacity() > 0) {
|
||||
int bx = x + normal.offsetX;
|
||||
int by = y + normal.offsetY;
|
||||
int bz = z + normal.offsetZ;
|
||||
@@ -269,18 +275,18 @@ public class TechneUtil {
|
||||
Vector3d v = new Vector3d(vert);
|
||||
Vector3d tv = new Vector3d(v);
|
||||
tv.add(0.5, 0, 0.5);
|
||||
if(vt != null) {
|
||||
if (vt != null) {
|
||||
vt.apply(v);
|
||||
}
|
||||
|
||||
if(isbrh) {
|
||||
if (isbrh) {
|
||||
float factor = normal.offsetX != 0 ? 0.8f : normal.offsetZ != 0 ? 0.6f : normal.offsetY < 0 ? 0.5f : 1;
|
||||
int c = (int) (0xFF * factor);
|
||||
|
||||
tes.setColorOpaque(c, c, c);
|
||||
}
|
||||
|
||||
if(override != null) {
|
||||
if (override != null) {
|
||||
|
||||
double interpX = Math.abs(tv.x * right.offsetX + tv.y * right.offsetY + tv.z * right.offsetZ);
|
||||
double interpY = Math.abs(tv.x * down.offsetX + tv.y * down.offsetY + tv.z * down.offsetZ);
|
||||
@@ -293,10 +299,10 @@ public class TechneUtil {
|
||||
interpY--;
|
||||
}
|
||||
|
||||
if(normal == ForgeDirection.SOUTH || normal == ForgeDirection.WEST) {
|
||||
if (normal == ForgeDirection.SOUTH || normal == ForgeDirection.WEST) {
|
||||
interpX = 1 - interpX;
|
||||
}
|
||||
if(normal != ForgeDirection.UP && normal != ForgeDirection.DOWN) {
|
||||
if (normal != ForgeDirection.UP && normal != ForgeDirection.DOWN) {
|
||||
interpY = 1 - interpY;
|
||||
}
|
||||
tes.addVertexWithUV(v.x, v.y, v.z, override.getInterpolatedU(interpX * 16), override.getInterpolatedV(interpY * 16));
|
||||
@@ -309,9 +315,9 @@ public class TechneUtil {
|
||||
}
|
||||
|
||||
private static ForgeDirection getNormalFor(Vertex n) {
|
||||
if(n.x != 0) {
|
||||
if (n.x != 0) {
|
||||
return n.x > 0 ? ForgeDirection.EAST : ForgeDirection.WEST;
|
||||
} else if(n.y != 0) {
|
||||
} else if (n.y != 0) {
|
||||
return n.y > 0 ? ForgeDirection.UP : ForgeDirection.DOWN;
|
||||
} else {
|
||||
return n.z > 0 ? ForgeDirection.SOUTH : ForgeDirection.NORTH;
|
||||
@@ -351,17 +357,18 @@ public class TechneUtil {
|
||||
vt = null;
|
||||
}
|
||||
|
||||
// TODO
|
||||
private static IIcon getIconFor(Block block, IBlockAccess world, int x, int y, int z) {
|
||||
if(block instanceof AbstractMachineBlock<?>) {
|
||||
return ((AbstractMachineBlock<?>) block).getModelIcon(world, x, y, z);
|
||||
}
|
||||
// if(block instanceof AbstractMachineBlock<?>) {
|
||||
// return ((AbstractMachineBlock<?>) block).getModelIcon(world, x, y, z);
|
||||
// }
|
||||
return block.getIcon(world, x, y, z, 0);
|
||||
}
|
||||
|
||||
private static IIcon getIconFor(Block block, int metadata) {
|
||||
if(block instanceof AbstractMachineBlock<?>) {
|
||||
return ((AbstractMachineBlock<?>) block).getModelIcon();
|
||||
}
|
||||
// if(block instanceof AbstractMachineBlock<?>) {
|
||||
// return ((AbstractMachineBlock<?>) block).getModelIcon();
|
||||
// }
|
||||
return block.getIcon(0, metadata);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.enderio.core.client.render;
|
||||
|
||||
import com.enderio.core.api.client.render.VertexTransform;
|
||||
import com.enderio.core.common.vecmath.Quat4d;
|
||||
import com.enderio.core.common.vecmath.Vector3d;
|
||||
import com.enderio.core.common.vecmath.Vector3f;
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.enderio.core.client.render;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import com.enderio.core.api.client.render.VertexTransform;
|
||||
import com.enderio.core.common.vecmath.Vector3d;
|
||||
import com.enderio.core.common.vecmath.Vector3f;
|
||||
import com.enderio.core.common.vecmath.Vertex;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.enderio.core.client.render;
|
||||
|
||||
import com.enderio.core.api.client.render.VertexTransform;
|
||||
import com.enderio.core.common.vecmath.Vector3d;
|
||||
import com.enderio.core.common.vecmath.Vector3f;
|
||||
import com.enderio.core.common.vecmath.Vertex;
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
package com.enderio.core.client.util;
|
||||
|
||||
import com.enderio.core.client.handlers.ClientHandler;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.client.model.obj.Face;
|
||||
import net.minecraftforge.client.model.obj.GroupObject;
|
||||
import net.minecraftforge.client.model.obj.TextureCoordinate;
|
||||
import net.minecraftforge.client.model.obj.Vertex;
|
||||
import net.minecraftforge.client.model.obj.WavefrontObject;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
@UtilityClass
|
||||
public class RenderingUtils
|
||||
{
|
||||
public void renderWithIcon(WavefrontObject model, IIcon icon, Tessellator tes)
|
||||
{
|
||||
for (GroupObject go : model.groupObjects)
|
||||
{
|
||||
for (Face f : go.faces)
|
||||
{
|
||||
Vertex n = f.faceNormal;
|
||||
tes.setNormal(n.x, n.y, n.z);
|
||||
for (int i = 0; i < f.vertices.length; i++)
|
||||
{
|
||||
Vertex v = f.vertices[i];
|
||||
TextureCoordinate t = f.textureCoordinates[i];
|
||||
tes.addVertexWithUV(v.x, v.y, v.z, icon.getInterpolatedU(t.u * 16), icon.getInterpolatedV(t.v * 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders an item entity in 3D
|
||||
*
|
||||
* @param item
|
||||
* The item to render
|
||||
* @param rotate
|
||||
* Whether to "spin" the item like it would if it were a real dropped entity
|
||||
*/
|
||||
public void render3DItem(EntityItem item, boolean rotate)
|
||||
{
|
||||
float rot = getRotation(1.0f);
|
||||
|
||||
glPushMatrix();
|
||||
glDepthMask(true);
|
||||
rotate &= Minecraft.getMinecraft().gameSettings.fancyGraphics;
|
||||
|
||||
if (rotate)
|
||||
{
|
||||
glRotatef(rot, 0, 1, 0);
|
||||
}
|
||||
|
||||
item.hoverStart = 0.0F;
|
||||
RenderManager.instance.renderEntityWithPosYaw(item, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F);
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
public float getRotation(float mult)
|
||||
{
|
||||
return ClientHandler.getTicksElapsed() * mult;
|
||||
}
|
||||
|
||||
public void renderBillboardQuad(float rot, double scale)
|
||||
{
|
||||
glPushMatrix();
|
||||
|
||||
glRotatef(-RenderManager.instance.playerViewY, 0.0F, 1.0F, 0.0F);
|
||||
glRotatef(RenderManager.instance.playerViewX, 1.0F, 0.0F, 0.0F);
|
||||
|
||||
glPushMatrix();
|
||||
|
||||
glRotatef(rot, 0, 0, 1);
|
||||
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
tessellator.startDrawingQuads();
|
||||
glColor3f(1, 1, 1);
|
||||
tessellator.setColorRGBA(255, 255, 255, 255);
|
||||
tessellator.addVertexWithUV(-scale, -scale, 0, 0, 0);
|
||||
tessellator.addVertexWithUV(-scale, scale, 0, 0, 1);
|
||||
tessellator.addVertexWithUV(scale, scale, 0, 1, 1);
|
||||
tessellator.addVertexWithUV(scale, -scale, 0, 1, 0);
|
||||
tessellator.draw();
|
||||
glPopMatrix();
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
public void rotateToPlayer()
|
||||
{
|
||||
glRotatef(-RenderManager.instance.playerViewY, 0.0F, 1.0F, 0.0F);
|
||||
glRotatef(RenderManager.instance.playerViewX, 1.0F, 0.0F, 0.0F);
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,6 @@ package com.enderio.core.common.handlers;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
import com.enderio.core.EnderCore;
|
||||
import com.enderio.core.common.Handlers.Handler;
|
||||
import com.enderio.core.common.config.ConfigHandler;
|
||||
import com.enderio.core.common.util.BlockCoord;
|
||||
import com.enderio.core.common.util.EnderEntityUtils;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -15,9 +9,17 @@ import net.minecraft.stats.StatisticsFile;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraftforge.event.entity.player.AchievementEvent;
|
||||
|
||||
import com.enderio.core.EnderCore;
|
||||
import com.enderio.core.common.Handlers.Handler;
|
||||
import com.enderio.core.common.config.ConfigHandler;
|
||||
import com.enderio.core.common.util.BlockCoord;
|
||||
import com.enderio.core.common.util.EntityUtil;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.PlayerTickEvent;
|
||||
|
||||
import static java.util.Calendar.*;
|
||||
|
||||
@Handler
|
||||
@@ -61,7 +63,7 @@ public class FireworkHandler
|
||||
{
|
||||
BlockCoord pos = getBlockCoord(player);
|
||||
pos = pos.withY(pos.y + 2);
|
||||
EnderEntityUtils.spawnFirework(pos, player.worldObj.provider.dimensionId, 12);
|
||||
EntityUtil.spawnFirework(pos, player.worldObj.provider.dimensionId, 12);
|
||||
player.getEntityData().setInteger("fireworksLeft", fireworksLeft - 1);
|
||||
|
||||
if (fireworksLeft > 5)
|
||||
|
||||
@@ -13,7 +13,7 @@ import net.minecraftforge.oredict.OreDictionary;
|
||||
import com.enderio.core.common.Handlers.Handler;
|
||||
import com.enderio.core.common.Handlers.Handler.HandlerType;
|
||||
import com.enderio.core.common.config.ConfigHandler;
|
||||
import com.enderio.core.common.util.EnderItemUtils;
|
||||
import com.enderio.core.common.util.ItemUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
@@ -43,7 +43,7 @@ public class RightClickCropHandler
|
||||
|
||||
public void init()
|
||||
{
|
||||
seedStack = EnderItemUtils.parseStringIntoItemStack(seed);
|
||||
seedStack = ItemUtil.parseStringIntoItemStack(seed);
|
||||
String[] blockinfo = block.split(":");
|
||||
blockInst = GameRegistry.findBlock(blockinfo[0], blockinfo[1]);
|
||||
}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
package com.enderio.core.common.util;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
@UtilityClass
|
||||
public class EnderColorUtils
|
||||
{
|
||||
/**
|
||||
* Turns an int into a glColor4f function
|
||||
*
|
||||
* @author Buildcraft team
|
||||
*/
|
||||
public void setGLColorFromInt(int color)
|
||||
{
|
||||
float red = (color >> 16 & 255) / 255.0F;
|
||||
float green = (color >> 8 & 255) / 255.0F;
|
||||
float blue = (color & 255) / 255.0F;
|
||||
GL11.glColor4f(red, green, blue, 1.0F);
|
||||
}
|
||||
|
||||
public int toHex(int r, int g, int b)
|
||||
{
|
||||
int hex = 0;
|
||||
hex = hex | ((r) << 16);
|
||||
hex = hex | ((g) << 8);
|
||||
hex = hex | ((b));
|
||||
return hex;
|
||||
}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
package com.enderio.core.common.util;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityFireworkRocket;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemDye;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
|
||||
@UtilityClass
|
||||
public class EnderEntityUtils
|
||||
{
|
||||
private static final Random rand = new Random();
|
||||
|
||||
public void setEntityVelocity(Entity entity, double velX, double velY, double velZ)
|
||||
{
|
||||
entity.motionX = velX;
|
||||
entity.motionY = velY;
|
||||
entity.motionZ = velZ;
|
||||
}
|
||||
|
||||
public EntityFireworkRocket getRandomFirework(World world)
|
||||
{
|
||||
return getRandomFirework(world, new BlockCoord(0, 0, 0));
|
||||
}
|
||||
|
||||
public EntityFireworkRocket getRandomFirework(World world, BlockCoord pos)
|
||||
{
|
||||
ItemStack firework = new ItemStack(Items.fireworks);
|
||||
firework.stackTagCompound = new NBTTagCompound();
|
||||
NBTTagCompound expl = new NBTTagCompound();
|
||||
expl.setBoolean("Flicker", true);
|
||||
expl.setBoolean("Trail", true);
|
||||
|
||||
int[] colors = new int[rand.nextInt(8) + 1];
|
||||
for (int i = 0; i < colors.length; i++)
|
||||
{
|
||||
colors[i] = ItemDye.field_150922_c[rand.nextInt(16)];
|
||||
}
|
||||
expl.setIntArray("Colors", colors);
|
||||
byte type = (byte) (rand.nextInt(3) + 1);
|
||||
type = type == 3 ? 4 : type;
|
||||
expl.setByte("Type", type);
|
||||
|
||||
NBTTagList explosions = new NBTTagList();
|
||||
explosions.appendTag(expl);
|
||||
|
||||
NBTTagCompound fireworkTag = new NBTTagCompound();
|
||||
fireworkTag.setTag("Explosions", explosions);
|
||||
fireworkTag.setByte("Flight", (byte) 1);
|
||||
firework.stackTagCompound.setTag("Fireworks", fireworkTag);
|
||||
|
||||
EntityFireworkRocket e = new EntityFireworkRocket(world, pos.x + 0.5, pos.y + 0.5, pos.z + 0.5, firework);
|
||||
return e;
|
||||
}
|
||||
|
||||
public void spawnFirework(BlockCoord block, int dimID)
|
||||
{
|
||||
spawnFirework(block, dimID, 0);
|
||||
}
|
||||
|
||||
public void spawnFirework(BlockCoord block, int dimID, int range)
|
||||
{
|
||||
World world = DimensionManager.getWorld(dimID);
|
||||
|
||||
BlockCoord pos = new BlockCoord(block.x, block.y, block.z);
|
||||
|
||||
// don't bother if there's no randomness at all
|
||||
if (range > 0)
|
||||
{
|
||||
pos = new BlockCoord(moveRandomly(block.x, range), block.y, moveRandomly(block.z, range));
|
||||
|
||||
int tries = -1;
|
||||
while (!world.isAirBlock(pos.x, pos.y, pos.z) && !world.getBlock(pos.x, pos.y, pos.z).isReplaceable(world, pos.x, pos.y, pos.z))
|
||||
{
|
||||
tries++;
|
||||
if (tries > 100)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
world.spawnEntityInWorld(getRandomFirework(world, pos));
|
||||
}
|
||||
|
||||
private double moveRandomly(double base, double range)
|
||||
{
|
||||
return base + 0.5 + rand.nextDouble() * range - (range / 2);
|
||||
}
|
||||
}
|
||||
@@ -1,292 +0,0 @@
|
||||
package com.enderio.core.common.util;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
||||
|
||||
@UtilityClass
|
||||
public class EnderItemUtils
|
||||
{
|
||||
private final Random rand = new Random();
|
||||
|
||||
/**
|
||||
* Turns a String into an item that can be used in a recipe. This is one of:
|
||||
* <ul>
|
||||
* <li>String</li>
|
||||
* <li>Item</li>
|
||||
* <li>Block</li>
|
||||
* <li>ItemStack</li>
|
||||
* </ul>
|
||||
* Because this method can return a String, it is highly recommended that you use the result in a {@link ShapedOreRecipe} or
|
||||
* {@link ShapelessOreRecipe}.
|
||||
*
|
||||
* @param string
|
||||
* The String to parse.
|
||||
* @return An object for use in recipes.
|
||||
*/
|
||||
public Object parseStringIntoRecipeItem(String string)
|
||||
{
|
||||
return parseStringIntoRecipeItem(string, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns a String into an item that can be used in a recipe. This is one of:
|
||||
* <ul>
|
||||
* <li>String</li>
|
||||
* <li>Item</li>
|
||||
* <li>Block</li>
|
||||
* <li>ItemStack</li>
|
||||
* </ul>
|
||||
* Because this method can return a String, it is highly recommended that you use the result in a {@link ShapedOreRecipe} or
|
||||
* {@link ShapelessOreRecipe}.
|
||||
*
|
||||
* @see #parseStringIntoItemStack(String)
|
||||
* @param string
|
||||
* The String to parse.
|
||||
* @param forceItemStack
|
||||
* True if the result should be forced to be an ItemStack.
|
||||
* @return AN object for use in recipes.
|
||||
*/
|
||||
public Object parseStringIntoRecipeItem(String string, boolean forceItemStack)
|
||||
{
|
||||
if ("null".equals(string))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else if (OreDictionary.getOres(string).isEmpty())
|
||||
{
|
||||
ItemStack stack = null;
|
||||
|
||||
String[] info = string.split(";");
|
||||
Object temp = null;
|
||||
int damage = OreDictionary.WILDCARD_VALUE;
|
||||
temp = Item.itemRegistry.getObject(info[0]);
|
||||
if (info.length > 1)
|
||||
{
|
||||
damage = Integer.parseInt(info[1]);
|
||||
}
|
||||
|
||||
if (temp instanceof Item)
|
||||
{
|
||||
stack = new ItemStack((Item) temp, 1, damage);
|
||||
}
|
||||
else if (temp instanceof Block)
|
||||
{
|
||||
stack = new ItemStack((Block) temp, 1, damage);
|
||||
}
|
||||
else if (temp instanceof ItemStack)
|
||||
{
|
||||
stack = ((ItemStack) temp).copy();
|
||||
stack.setItemDamage(damage);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException(string
|
||||
+ " is not a vaild string. Strings should be either an oredict name, or in the format objectname;damage (damage is optional)");
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
else if (forceItemStack)
|
||||
{
|
||||
return OreDictionary.getOres(string).get(0).copy();
|
||||
}
|
||||
else
|
||||
{
|
||||
return string;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns a string into an ItemStack.
|
||||
* <p>
|
||||
* This is basically a convenience method that casts the result of {@link #parseStringIntoRecipeItem(String, boolean)}, but with one extra
|
||||
* feature.
|
||||
* <p>
|
||||
* A '#' character may be used at the end of the string to signify stack size, e.g. "minecraft:diamond#2" would be a stack of 2 diamonds.
|
||||
* <p>
|
||||
* The stack size will automatically be clamped to be below the give Item's max stack size.
|
||||
*
|
||||
* @param string
|
||||
* The String to parse.
|
||||
* @return An ItemStack the string represents.
|
||||
*/
|
||||
public ItemStack parseStringIntoItemStack(String string)
|
||||
{
|
||||
int size = 1;
|
||||
int idx = string.indexOf('#');
|
||||
|
||||
if (idx != -1)
|
||||
{
|
||||
String num = string.substring(idx + 1);
|
||||
|
||||
try
|
||||
{
|
||||
size = Integer.parseInt(num);
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
throw new IllegalArgumentException(num + " is not a valid stack size");
|
||||
}
|
||||
|
||||
string = string.substring(0, idx);
|
||||
}
|
||||
|
||||
ItemStack stack = (ItemStack) parseStringIntoRecipeItem(string, true);
|
||||
stack.stackSize = MathHelper.clamp_int(size, 1, stack.getMaxStackSize());
|
||||
return stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the appropriate config string for the given {@link ItemStack}
|
||||
* <p>
|
||||
* This does not take into account ore dict.
|
||||
*
|
||||
* @param stack
|
||||
* The {@link ItemStack} to serialize
|
||||
* @param damage
|
||||
* If damage should be taken into account
|
||||
* @param size
|
||||
* If stack size should be taken into account
|
||||
* @return A string that will be the equivalent of if {@link ItemStack stack} was constructed from it using
|
||||
* {@link #parseStringIntoItemStack(String)}
|
||||
*/
|
||||
public String getStringForItemStack(ItemStack stack, boolean damage, boolean size)
|
||||
{
|
||||
if (stack == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
String base = Item.itemRegistry.getNameForObject(stack.getItem());
|
||||
|
||||
if (damage)
|
||||
{
|
||||
base += ";" + stack.getItemDamage();
|
||||
}
|
||||
|
||||
if (size)
|
||||
{
|
||||
base += "#" + stack.stackSize;
|
||||
}
|
||||
|
||||
return base;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if two {@link ItemStack}s are completely equal, forgoing stack size. This means that for this method to return true, Item type, damage
|
||||
* value, and NBT data of both ItemStacks must be identical.
|
||||
*
|
||||
* @param s1
|
||||
* The first ItemStack to compare.
|
||||
* @param s2
|
||||
* The second ItemStack to compare.
|
||||
* @author powercrystals
|
||||
*/
|
||||
public boolean stacksEqual(ItemStack s1, ItemStack s2)
|
||||
{
|
||||
if (s1 == null && s2 == null)
|
||||
return true;
|
||||
if (s1 == null || s2 == null)
|
||||
return false;
|
||||
if (!s1.isItemEqual(s2))
|
||||
return false;
|
||||
if (s1.getTagCompound() == null && s2.getTagCompound() == null)
|
||||
return true;
|
||||
if (s1.getTagCompound() == null || s2.getTagCompound() == null)
|
||||
return false;
|
||||
return s1.getTagCompound().equals(s2.getTagCompound());
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawns an ItemStack into the world with motion that simulates a normal block drop.
|
||||
*
|
||||
* @param world
|
||||
* The world object.
|
||||
* @param item
|
||||
* The ItemStack to spawn.
|
||||
* @param x
|
||||
* X coordinate of the block in which to spawn the entity.
|
||||
* @param y
|
||||
* Y coordinate of the block in which to spawn the entity.
|
||||
* @param z
|
||||
* Z coordinate of the block in which to spawn the entity.
|
||||
*/
|
||||
public void spawnItemInWorldWithRandomMotion(World world, ItemStack item, int x, int y, int z)
|
||||
{
|
||||
if (item != null)
|
||||
{
|
||||
spawnItemInWorldWithRandomMotion(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, item));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawns an EntityItem into the world with motion that simulates a normal block drop.
|
||||
*
|
||||
* @param entity
|
||||
* The entity to spawn.
|
||||
*/
|
||||
public void spawnItemInWorldWithRandomMotion(EntityItem entity)
|
||||
{
|
||||
entity.delayBeforeCanPickup = 10;
|
||||
|
||||
float f = (rand.nextFloat() * 0.1f) - 0.05f;
|
||||
float f1 = (rand.nextFloat() * 0.1f) - 0.05f;
|
||||
float f2 = (rand.nextFloat() * 0.1f) - 0.05f;
|
||||
|
||||
entity.motionX += f;
|
||||
entity.motionY += f1;
|
||||
entity.motionZ += f2;
|
||||
|
||||
entity.worldObj.spawnEntityInWorld(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given stack has the given Ore Dictionary name applied to it.
|
||||
*
|
||||
* @param stack
|
||||
* The ItemStack to check.
|
||||
* @param oredict
|
||||
* The oredict name.
|
||||
* @return True if the ItemStack matches the name passed.
|
||||
*/
|
||||
public boolean itemStackMatchesOredict(ItemStack stack, String oredict)
|
||||
{
|
||||
int[] ids = OreDictionary.getOreIDs(stack);
|
||||
for (int i : ids)
|
||||
{
|
||||
String name = OreDictionary.getOreName(i);
|
||||
if (name.equals(oredict))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an NBT tag from an ItemStack, creating it if needed. The tag returned will always be the same as the one on the stack.
|
||||
*
|
||||
* @param stack
|
||||
* The ItemStack to get the tag from.
|
||||
* @return An NBTTagCompound from the stack.
|
||||
*/
|
||||
public NBTTagCompound getNBTTag(ItemStack stack)
|
||||
{
|
||||
if (!stack.hasTagCompound())
|
||||
{
|
||||
stack.stackTagCompound = new NBTTagCompound();
|
||||
}
|
||||
return stack.stackTagCompound;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.enderio.core.common.util;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
@@ -10,55 +11,130 @@ import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.boss.IBossDisplayData;
|
||||
import net.minecraft.entity.item.EntityFireworkRocket;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemDye;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
|
||||
import com.enderio.core.common.vecmath.Vector3d;
|
||||
|
||||
public class EntityUtil {
|
||||
|
||||
private static final Random rand = new Random();
|
||||
|
||||
public static void setEntityVelocity(Entity entity, double velX, double velY, double velZ) {
|
||||
entity.motionX = velX;
|
||||
entity.motionY = velY;
|
||||
entity.motionZ = velZ;
|
||||
}
|
||||
|
||||
public static EntityFireworkRocket getRandomFirework(World world) {
|
||||
return getRandomFirework(world, new BlockCoord(0, 0, 0));
|
||||
}
|
||||
|
||||
public static EntityFireworkRocket getRandomFirework(World world, BlockCoord pos) {
|
||||
ItemStack firework = new ItemStack(Items.fireworks);
|
||||
firework.stackTagCompound = new NBTTagCompound();
|
||||
NBTTagCompound expl = new NBTTagCompound();
|
||||
expl.setBoolean("Flicker", true);
|
||||
expl.setBoolean("Trail", true);
|
||||
|
||||
int[] colors = new int[rand.nextInt(8) + 1];
|
||||
for (int i = 0; i < colors.length; i++) {
|
||||
colors[i] = ItemDye.field_150922_c[rand.nextInt(16)];
|
||||
}
|
||||
expl.setIntArray("Colors", colors);
|
||||
byte type = (byte) (rand.nextInt(3) + 1);
|
||||
type = type == 3 ? 4 : type;
|
||||
expl.setByte("Type", type);
|
||||
|
||||
NBTTagList explosions = new NBTTagList();
|
||||
explosions.appendTag(expl);
|
||||
|
||||
NBTTagCompound fireworkTag = new NBTTagCompound();
|
||||
fireworkTag.setTag("Explosions", explosions);
|
||||
fireworkTag.setByte("Flight", (byte) 1);
|
||||
firework.stackTagCompound.setTag("Fireworks", fireworkTag);
|
||||
|
||||
EntityFireworkRocket e = new EntityFireworkRocket(world, pos.x + 0.5, pos.y + 0.5, pos.z + 0.5, firework);
|
||||
return e;
|
||||
}
|
||||
|
||||
public static void spawnFirework(BlockCoord block, int dimID) {
|
||||
spawnFirework(block, dimID, 0);
|
||||
}
|
||||
|
||||
public static void spawnFirework(BlockCoord block, int dimID, int range) {
|
||||
World world = DimensionManager.getWorld(dimID);
|
||||
|
||||
BlockCoord pos = new BlockCoord(block.x, block.y, block.z);
|
||||
|
||||
// don't bother if there's no randomness at all
|
||||
if (range > 0) {
|
||||
pos = new BlockCoord(moveRandomly(block.x, range), block.y, moveRandomly(block.z, range));
|
||||
|
||||
int tries = -1;
|
||||
while (!world.isAirBlock(pos.x, pos.y, pos.z) && !world.getBlock(pos.x, pos.y, pos.z).isReplaceable(world, pos.x, pos.y, pos.z)) {
|
||||
tries++;
|
||||
if (tries > 100) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
world.spawnEntityInWorld(getRandomFirework(world, pos));
|
||||
}
|
||||
|
||||
private static double moveRandomly(double base, double range) {
|
||||
return base + 0.5 + rand.nextDouble() * range - (range / 2);
|
||||
}
|
||||
|
||||
public static String getDisplayNameForEntity(String mobName) {
|
||||
return StatCollector.translateToLocal("entity." + mobName + ".name");
|
||||
}
|
||||
|
||||
|
||||
public static List<String> getAllRegisteredMobNames(boolean excludeBosses) {
|
||||
List<String> result = new ArrayList<String>();
|
||||
List<String> result = new ArrayList<String>();
|
||||
Set<Map.Entry<Class, String>> entries = EntityList.classToStringMapping.entrySet();
|
||||
for(Map.Entry<Class, String> entry : entries) {
|
||||
if(EntityLiving.class.isAssignableFrom(entry.getKey()) ) {
|
||||
if(!excludeBosses || !IBossDisplayData.class.isAssignableFrom(entry.getKey())) {
|
||||
for (Map.Entry<Class, String> entry : entries) {
|
||||
if (EntityLiving.class.isAssignableFrom(entry.getKey())) {
|
||||
if (!excludeBosses || !IBossDisplayData.class.isAssignableFrom(entry.getKey())) {
|
||||
result.add(entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private EntityUtil() {
|
||||
|
||||
private EntityUtil() {
|
||||
}
|
||||
|
||||
public static Vector3d getEntityPosition(Entity ent) {
|
||||
return new Vector3d(ent.posX, ent.posY, ent.posZ);
|
||||
}
|
||||
|
||||
|
||||
public static List<AxisAlignedBB> getCollidingBlockGeometry(World world, Entity entity) {
|
||||
AxisAlignedBB entityBounds = entity.boundingBox;
|
||||
ArrayList collidingBoundingBoxes = new ArrayList();
|
||||
int minX = MathHelper.floor_double(entityBounds.minX);
|
||||
int minY = MathHelper.floor_double(entityBounds.minY);
|
||||
int minZ = MathHelper.floor_double(entityBounds.minZ);
|
||||
int maxX = MathHelper.floor_double(entityBounds.maxX + 1.0D);
|
||||
int maxY = MathHelper.floor_double(entityBounds.maxY + 1.0D);
|
||||
int maxX = MathHelper.floor_double(entityBounds.maxX + 1.0D);
|
||||
int maxY = MathHelper.floor_double(entityBounds.maxY + 1.0D);
|
||||
int maxZ = MathHelper.floor_double(entityBounds.maxZ + 1.0D);
|
||||
for (int x = minX; x < maxX; x++) {
|
||||
for (int z = minZ; z < maxZ; z++) {
|
||||
for (int y = minY; y < maxY; y++) {
|
||||
Block block = world.getBlock(x, y, z);
|
||||
if(block != null) {
|
||||
if (block != null) {
|
||||
block.addCollisionBoxesToList(world, x, y, z, entityBounds, collidingBoundingBoxes, entity);
|
||||
}
|
||||
}
|
||||
@@ -68,13 +144,13 @@ public class EntityUtil {
|
||||
}
|
||||
|
||||
public static void spawnItemInWorldWithRandomMotion(World world, ItemStack item, int x, int y, int z) {
|
||||
if(item != null) {
|
||||
if (item != null) {
|
||||
spawnItemInWorldWithRandomMotion(world, item, x + 0.5, y + 0.5, z + 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
public static void spawnItemInWorldWithRandomMotion(World world, ItemStack item, double x, double y, double z) {
|
||||
if(item != null) {
|
||||
if (item != null) {
|
||||
spawnItemInWorldWithRandomMotion(new EntityItem(world, x, y, z, item));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,59 +2,314 @@ package com.enderio.core.common.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.inventory.InventoryLargeChest;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntityChest;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
||||
import cofh.api.transport.IItemDuct;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
|
||||
public class ItemUtil {
|
||||
|
||||
public static final List<IItemReceptor> receptors = new ArrayList<IItemReceptor>();
|
||||
private static final Random rand = new Random();
|
||||
|
||||
static {
|
||||
try {
|
||||
Class.forName("crazypants.util.BuildcraftUtil");
|
||||
} catch (Exception e) {
|
||||
if(Loader.isModLoaded("BuildCraft|Transport")) {
|
||||
if (Loader.isModLoaded("BuildCraft|Transport")) {
|
||||
Log.warn("ItemUtil: Could not register Build Craft pipe handler. Machines will not be able to output to BC pipes.");
|
||||
} //Don't log if BC isn't installed, but we still check in case another mod is using their API
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns a String into an item that can be used in a recipe. This is one of:
|
||||
* <ul>
|
||||
* <li>String</li>
|
||||
* <li>Item</li>
|
||||
* <li>Block</li>
|
||||
* <li>ItemStack</li>
|
||||
* </ul>
|
||||
* Because this method can return a String, it is highly recommended that you
|
||||
* use the result in a {@link ShapedOreRecipe} or {@link ShapelessOreRecipe}.
|
||||
*
|
||||
* @param string
|
||||
* The String to parse.
|
||||
* @return An object for use in recipes.
|
||||
*/
|
||||
public static Object parseStringIntoRecipeItem(String string) {
|
||||
return parseStringIntoRecipeItem(string, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns a String into an item that can be used in a recipe. This is one of:
|
||||
* <ul>
|
||||
* <li>String</li>
|
||||
* <li>Item</li>
|
||||
* <li>Block</li>
|
||||
* <li>ItemStack</li>
|
||||
* </ul>
|
||||
* Because this method can return a String, it is highly recommended that you
|
||||
* use the result in a {@link ShapedOreRecipe} or {@link ShapelessOreRecipe}.
|
||||
*
|
||||
* @see #parseStringIntoItemStack(String)
|
||||
* @param string
|
||||
* The String to parse.
|
||||
* @param forceItemStack
|
||||
* True if the result should be forced to be an ItemStack.
|
||||
* @return AN object for use in recipes.
|
||||
*/
|
||||
public static Object parseStringIntoRecipeItem(String string, boolean forceItemStack) {
|
||||
if ("null".equals(string)) {
|
||||
return null;
|
||||
} else if (OreDictionary.getOres(string).isEmpty()) {
|
||||
ItemStack stack = null;
|
||||
|
||||
String[] info = string.split(";");
|
||||
Object temp = null;
|
||||
int damage = OreDictionary.WILDCARD_VALUE;
|
||||
temp = Item.itemRegistry.getObject(info[0]);
|
||||
if (info.length > 1) {
|
||||
damage = Integer.parseInt(info[1]);
|
||||
}
|
||||
|
||||
if (temp instanceof Item) {
|
||||
stack = new ItemStack((Item) temp, 1, damage);
|
||||
} else if (temp instanceof Block) {
|
||||
stack = new ItemStack((Block) temp, 1, damage);
|
||||
} else if (temp instanceof ItemStack) {
|
||||
stack = ((ItemStack) temp).copy();
|
||||
stack.setItemDamage(damage);
|
||||
} else {
|
||||
throw new IllegalArgumentException(string
|
||||
+ " is not a vaild string. Strings should be either an oredict name, or in the format objectname;damage (damage is optional)");
|
||||
}
|
||||
|
||||
return stack;
|
||||
} else if (forceItemStack) {
|
||||
return OreDictionary.getOres(string).get(0).copy();
|
||||
} else {
|
||||
return string;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns a string into an ItemStack.
|
||||
* <p>
|
||||
* This is basically a convenience method that casts the result of
|
||||
* {@link #parseStringIntoRecipeItem(String, boolean)}, but with one extra
|
||||
* feature.
|
||||
* <p>
|
||||
* A '#' character may be used at the end of the string to signify stack size,
|
||||
* e.g. "minecraft:diamond#2" would be a stack of 2 diamonds.
|
||||
* <p>
|
||||
* The stack size will automatically be clamped to be below the give Item's
|
||||
* max stack size.
|
||||
*
|
||||
* @param string
|
||||
* The String to parse.
|
||||
* @return An ItemStack the string represents.
|
||||
*/
|
||||
public static ItemStack parseStringIntoItemStack(String string) {
|
||||
int size = 1;
|
||||
int idx = string.indexOf('#');
|
||||
|
||||
if (idx != -1) {
|
||||
String num = string.substring(idx + 1);
|
||||
|
||||
try {
|
||||
size = Integer.parseInt(num);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new IllegalArgumentException(num + " is not a valid stack size");
|
||||
}
|
||||
|
||||
string = string.substring(0, idx);
|
||||
}
|
||||
|
||||
ItemStack stack = (ItemStack) parseStringIntoRecipeItem(string, true);
|
||||
stack.stackSize = MathHelper.clamp_int(size, 1, stack.getMaxStackSize());
|
||||
return stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the appropriate config string for the given {@link ItemStack}
|
||||
* <p>
|
||||
* This does not take into account ore dict.
|
||||
*
|
||||
* @param stack
|
||||
* The {@link ItemStack} to serialize
|
||||
* @param damage
|
||||
* If damage should be taken into account
|
||||
* @param size
|
||||
* If stack size should be taken into account
|
||||
* @return A string that will be the equivalent of if {@link ItemStack stack}
|
||||
* was constructed from it using
|
||||
* {@link #parseStringIntoItemStack(String)}
|
||||
*/
|
||||
public static String getStringForItemStack(ItemStack stack, boolean damage, boolean size) {
|
||||
if (stack == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String base = Item.itemRegistry.getNameForObject(stack.getItem());
|
||||
|
||||
if (damage) {
|
||||
base += ";" + stack.getItemDamage();
|
||||
}
|
||||
|
||||
if (size) {
|
||||
base += "#" + stack.stackSize;
|
||||
}
|
||||
|
||||
return base;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if two {@link ItemStack}s are completely equal, forgoing stack size.
|
||||
* This means that for this method to return true, Item type, damage value,
|
||||
* and NBT data of both ItemStacks must be identical.
|
||||
*
|
||||
* @param s1
|
||||
* The first ItemStack to compare.
|
||||
* @param s2
|
||||
* The second ItemStack to compare.
|
||||
* @author powercrystals
|
||||
*/
|
||||
public static boolean stacksEqual(ItemStack s1, ItemStack s2) {
|
||||
if (s1 == null && s2 == null)
|
||||
return true;
|
||||
if (s1 == null || s2 == null)
|
||||
return false;
|
||||
if (!s1.isItemEqual(s2))
|
||||
return false;
|
||||
if (s1.getTagCompound() == null && s2.getTagCompound() == null)
|
||||
return true;
|
||||
if (s1.getTagCompound() == null || s2.getTagCompound() == null)
|
||||
return false;
|
||||
return s1.getTagCompound().equals(s2.getTagCompound());
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawns an ItemStack into the world with motion that simulates a normal
|
||||
* block drop.
|
||||
*
|
||||
* @param world
|
||||
* The world object.
|
||||
* @param item
|
||||
* The ItemStack to spawn.
|
||||
* @param x
|
||||
* X coordinate of the block in which to spawn the entity.
|
||||
* @param y
|
||||
* Y coordinate of the block in which to spawn the entity.
|
||||
* @param z
|
||||
* Z coordinate of the block in which to spawn the entity.
|
||||
*/
|
||||
public static void spawnItemInWorldWithRandomMotion(World world, ItemStack item, int x, int y, int z) {
|
||||
if (item != null) {
|
||||
spawnItemInWorldWithRandomMotion(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, item));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawns an EntityItem into the world with motion that simulates a normal
|
||||
* block drop.
|
||||
*
|
||||
* @param entity
|
||||
* The entity to spawn.
|
||||
*/
|
||||
public static void spawnItemInWorldWithRandomMotion(EntityItem entity) {
|
||||
entity.delayBeforeCanPickup = 10;
|
||||
|
||||
float f = (rand.nextFloat() * 0.1f) - 0.05f;
|
||||
float f1 = (rand.nextFloat() * 0.1f) - 0.05f;
|
||||
float f2 = (rand.nextFloat() * 0.1f) - 0.05f;
|
||||
|
||||
entity.motionX += f;
|
||||
entity.motionY += f1;
|
||||
entity.motionZ += f2;
|
||||
|
||||
entity.worldObj.spawnEntityInWorld(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given stack has the given Ore Dictionary name applied
|
||||
* to it.
|
||||
*
|
||||
* @param stack
|
||||
* The ItemStack to check.
|
||||
* @param oredict
|
||||
* The oredict name.
|
||||
* @return True if the ItemStack matches the name passed.
|
||||
*/
|
||||
public static boolean itemStackMatchesOredict(ItemStack stack, String oredict) {
|
||||
int[] ids = OreDictionary.getOreIDs(stack);
|
||||
for (int i : ids) {
|
||||
String name = OreDictionary.getOreName(i);
|
||||
if (name.equals(oredict)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an NBT tag from an ItemStack, creating it if needed. The tag returned
|
||||
* will always be the same as the one on the stack.
|
||||
*
|
||||
* @param stack
|
||||
* The ItemStack to get the tag from.
|
||||
* @return An NBTTagCompound from the stack.
|
||||
*/
|
||||
public static NBTTagCompound getNBTTag(ItemStack stack) {
|
||||
if (!stack.hasTagCompound()) {
|
||||
stack.stackTagCompound = new NBTTagCompound();
|
||||
}
|
||||
return stack.stackTagCompound;
|
||||
}
|
||||
|
||||
public static String getDurabilityString(ItemStack item) {
|
||||
if(item == null) {
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
return Lang.localize("item.darkSteel.tooltip.durability") + " " + (item.getMaxDamage() - item.getItemDamage()) + "/" + item.getMaxDamage();
|
||||
}
|
||||
|
||||
public static NBTTagCompound getOrCreateNBT(ItemStack stack) {
|
||||
if(stack.stackTagCompound == null) {
|
||||
if (stack.stackTagCompound == null) {
|
||||
stack.stackTagCompound = new NBTTagCompound();
|
||||
}
|
||||
return stack.stackTagCompound;
|
||||
}
|
||||
|
||||
public static int doInsertItem(Object into, ItemStack item, ForgeDirection side) {
|
||||
if(into == null || item == null) {
|
||||
if (into == null || item == null) {
|
||||
return 0;
|
||||
}
|
||||
if(into instanceof ISidedInventory) {
|
||||
if (into instanceof ISidedInventory) {
|
||||
return ItemUtil.doInsertItemInv((ISidedInventory) into, item, side);
|
||||
} else if(into instanceof IInventory) {
|
||||
} else if (into instanceof IInventory) {
|
||||
return ItemUtil.doInsertItemInv(getInventory((IInventory) into), item, side);
|
||||
} else if(into instanceof IItemDuct) {
|
||||
} else if (into instanceof IItemDuct) {
|
||||
return ItemUtil.doInsertItem((IItemDuct) into, item, side);
|
||||
}
|
||||
|
||||
for (IItemReceptor rec : receptors) {
|
||||
if(rec.canInsertIntoObject(into, side)) {
|
||||
if (rec.canInsertIntoObject(into, side)) {
|
||||
return rec.doInsertItem(into, item, side);
|
||||
}
|
||||
}
|
||||
@@ -65,7 +320,7 @@ public class ItemUtil {
|
||||
public static int doInsertItem(IItemDuct con, ItemStack item, ForgeDirection inventorySide) {
|
||||
int startedWith = item.stackSize;
|
||||
ItemStack remaining = con.insertItem(inventorySide, item);
|
||||
if(remaining == null) {
|
||||
if (remaining == null) {
|
||||
return startedWith;
|
||||
}
|
||||
return startedWith - remaining.stackSize;
|
||||
@@ -83,7 +338,7 @@ public class ItemUtil {
|
||||
ISlotIterator slots;
|
||||
|
||||
if (sidedInv != null) {
|
||||
if(inventorySide == null) {
|
||||
if (inventorySide == null) {
|
||||
inventorySide = ForgeDirection.UNKNOWN;
|
||||
}
|
||||
// Note: This is not thread-safe. Change to getInstance() to constructor when needed (1.8++?).
|
||||
@@ -103,9 +358,9 @@ public class ItemUtil {
|
||||
// PASS1: Try to add to an existing stack
|
||||
while (numToInsert > 0 && slots.hasNext()) {
|
||||
final int slot = slots.nextSlot();
|
||||
if(sidedInv == null || sidedInv.canInsertItem(slot, item, inventorySide.ordinal())) {
|
||||
if (sidedInv == null || sidedInv.canInsertItem(slot, item, inventorySide.ordinal())) {
|
||||
final ItemStack contents = inv.getStackInSlot(slot);
|
||||
if(contents != null) {
|
||||
if (contents != null) {
|
||||
if (areStackMergable(contents, item)) {
|
||||
final int freeSpace = Math.min(inv.getInventoryStackLimit(), contents.getMaxStackSize()) - contents.stackSize; // some inventories like using itemstacks with invalid stack sizes
|
||||
if (freeSpace > 0) {
|
||||
@@ -114,7 +369,7 @@ public class ItemUtil {
|
||||
toInsert.stackSize = contents.stackSize + noToInsert;
|
||||
// isItemValidForSlot() may check the stacksize, so give it the number the stack would have in the end.
|
||||
// If it does something funny, like "only even numbers", we are screwed.
|
||||
if(sidedInv != null || inv.isItemValidForSlot(slot, toInsert)) {
|
||||
if (sidedInv != null || inv.isItemValidForSlot(slot, toInsert)) {
|
||||
numInserted += noToInsert;
|
||||
numToInsert -= noToInsert;
|
||||
inv.setInventorySlotContents(slot, toInsert);
|
||||
@@ -131,14 +386,14 @@ public class ItemUtil {
|
||||
if (numToInsert > 0 && firstFreeSlot != -1) {
|
||||
final ItemStack toInsert = item.copy();
|
||||
toInsert.stackSize = min(numToInsert, inv.getInventoryStackLimit(), toInsert.getMaxStackSize()); // some inventories like using itemstacks with invalid stack sizes
|
||||
if(sidedInv != null || inv.isItemValidForSlot(firstFreeSlot, toInsert)) {
|
||||
if (sidedInv != null || inv.isItemValidForSlot(firstFreeSlot, toInsert)) {
|
||||
numInserted += toInsert.stackSize;
|
||||
numToInsert -= toInsert.stackSize;
|
||||
inv.setInventorySlotContents(firstFreeSlot, toInsert);
|
||||
}
|
||||
}
|
||||
|
||||
if(numInserted > 0) {
|
||||
if (numInserted > 0) {
|
||||
inv.markDirty();
|
||||
}
|
||||
return numInserted;
|
||||
@@ -147,28 +402,28 @@ public class ItemUtil {
|
||||
private final static int min(int i1, int i2, int i3) {
|
||||
return i1 < i2 ? (i1 < i3 ? i1 : i3) : (i2 < i3 ? i2 : i3);
|
||||
}
|
||||
|
||||
|
||||
public static boolean isStackFull(ItemStack contents) {
|
||||
if(contents == null) {
|
||||
if (contents == null) {
|
||||
return false;
|
||||
}
|
||||
return contents.stackSize >= contents.getMaxStackSize();
|
||||
}
|
||||
|
||||
public static IInventory getInventory(IInventory inv) {
|
||||
if(inv instanceof TileEntityChest) {
|
||||
if (inv instanceof TileEntityChest) {
|
||||
TileEntityChest chest = (TileEntityChest) inv;
|
||||
TileEntityChest neighbour = null;
|
||||
if(chest.adjacentChestXNeg != null) {
|
||||
if (chest.adjacentChestXNeg != null) {
|
||||
neighbour = chest.adjacentChestXNeg;
|
||||
} else if(chest.adjacentChestXPos != null) {
|
||||
} else if (chest.adjacentChestXPos != null) {
|
||||
neighbour = chest.adjacentChestXPos;
|
||||
} else if(chest.adjacentChestZNeg != null) {
|
||||
} else if (chest.adjacentChestZNeg != null) {
|
||||
neighbour = chest.adjacentChestZNeg;
|
||||
} else if(chest.adjacentChestZPos != null) {
|
||||
} else if (chest.adjacentChestZPos != null) {
|
||||
neighbour = chest.adjacentChestZPos;
|
||||
}
|
||||
if(neighbour != null) {
|
||||
if (neighbour != null) {
|
||||
return new InventoryLargeChest("", inv, neighbour);
|
||||
}
|
||||
return inv;
|
||||
@@ -184,10 +439,10 @@ public class ItemUtil {
|
||||
* @return
|
||||
*/
|
||||
public static boolean areStackMergable(ItemStack s1, ItemStack s2) {
|
||||
if(s1 == null || s2 == null || !s1.isStackable() || !s2.isStackable()) {
|
||||
if (s1 == null || s2 == null || !s1.isStackable() || !s2.isStackable()) {
|
||||
return false;
|
||||
}
|
||||
if(!s1.isItemEqual(s2)) {
|
||||
if (!s1.isItemEqual(s2)) {
|
||||
return false;
|
||||
}
|
||||
return ItemStack.areItemStackTagsEqual(s1, s2);
|
||||
@@ -201,10 +456,10 @@ public class ItemUtil {
|
||||
* @return
|
||||
*/
|
||||
public static boolean areStacksEqual(ItemStack s1, ItemStack s2) {
|
||||
if(s1 == null || s2 == null) {
|
||||
if (s1 == null || s2 == null) {
|
||||
return false;
|
||||
}
|
||||
if(!s1.isItemEqual(s2)) {
|
||||
if (!s1.isItemEqual(s2)) {
|
||||
return false;
|
||||
}
|
||||
return ItemStack.areItemStackTagsEqual(s1, s2);
|
||||
@@ -212,45 +467,52 @@ public class ItemUtil {
|
||||
|
||||
private interface ISlotIterator {
|
||||
int nextSlot();
|
||||
|
||||
boolean hasNext();
|
||||
}
|
||||
|
||||
|
||||
private final static class invSlotter implements ISlotIterator {
|
||||
private static final invSlotter me = new invSlotter();
|
||||
private int end;
|
||||
private int current;
|
||||
|
||||
public final static invSlotter getInstance(int start, int end) {
|
||||
me.end = end;
|
||||
me.current = start;
|
||||
return me;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int nextSlot() {
|
||||
return current++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean hasNext() {
|
||||
return current < end;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private final static class sidedSlotter implements ISlotIterator {
|
||||
private static final sidedSlotter me = new sidedSlotter();
|
||||
private int[] slots;
|
||||
private int current;
|
||||
|
||||
public final static sidedSlotter getInstance(int[] slots) {
|
||||
me.slots = slots;
|
||||
me.current = 0;
|
||||
return me;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int nextSlot() {
|
||||
return slots[current++];
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean hasNext() {
|
||||
return slots != null && current < slots.length;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user