mirror of
https://github.com/GTNewHorizons/EnderCore.git
synced 2026-11-21 12:32:15 +00:00
commit
6f772aa1d9
11 files changed
+502
-101
No files matched your search
@@ -15,6 +15,12 @@ public interface IWidgetMap {
|
||||
|
||||
void render(IWidgetIcon widget, double x, double y, boolean doDraw);
|
||||
|
||||
void render(IWidgetIcon widget, double x, double y, boolean doDraw, boolean flipY);
|
||||
|
||||
void render(IWidgetIcon widget, double x, double y, double zLevel, boolean doDraw);
|
||||
|
||||
void render(IWidgetIcon widget, double x, double y, double zLevel, boolean doDraw, boolean flipY);
|
||||
|
||||
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);
|
||||
@@ -49,6 +55,21 @@ public interface IWidgetMap {
|
||||
render(widget, x, y, widget.getWidth(), widget.getHeight(), 0, doDraw);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(IWidgetIcon widget, double x, double y, boolean doDraw, boolean flipY) {
|
||||
render(widget, x, y, widget.getWidth(), widget.getHeight(), 0, doDraw, flipY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(IWidgetIcon widget, double x, double y, double zLevel, boolean doDraw) {
|
||||
render(widget, x, y, widget.getWidth(), widget.getHeight(), zLevel, doDraw);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(IWidgetIcon widget, double x, double y, double zLevel, boolean doDraw, boolean flipY) {
|
||||
render(widget, x, y, widget.getWidth(), widget.getHeight(), zLevel, doDraw, flipY);
|
||||
}
|
||||
|
||||
@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);
|
||||
|
||||
@@ -0,0 +1,230 @@
|
||||
package com.enderio.core.client.gui;
|
||||
|
||||
import static com.enderio.core.client.render.EnderWidget.NEUTRAL_SLOT_BACKGROUND;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import com.enderio.core.client.gui.widget.GhostSlot;
|
||||
import com.enderio.core.client.render.RenderUtil;
|
||||
import com.enderio.core.common.util.ItemUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public class GhostSlotHandler {
|
||||
|
||||
protected List<GhostSlot> ghostSlots = Lists.newArrayList();
|
||||
protected GhostSlot hoverGhostSlot;
|
||||
|
||||
public GhostSlotHandler() {
|
||||
}
|
||||
|
||||
// GhostSlot managing
|
||||
|
||||
protected List<GhostSlot> getGhostSlots() {
|
||||
return ghostSlots;
|
||||
}
|
||||
|
||||
protected GhostSlot getGhostSlot(GuiContainerBase guiContainerBase, int mouseX, int mouseY) {
|
||||
mouseX -= guiContainerBase.getGuiLeft();
|
||||
mouseY -= guiContainerBase.getGuiTop();
|
||||
for (GhostSlot slot : ghostSlots) {
|
||||
if (slot.isVisible() && slot.isMouseOver(mouseX, mouseY)) {
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Slot interaction
|
||||
|
||||
/**
|
||||
* Called when a ghost slot is clicked or mouse wheeled.
|
||||
*
|
||||
* @param gui
|
||||
* The GUI the GhostSlot is in
|
||||
* @param slot
|
||||
* The GhostSlot
|
||||
* @param x
|
||||
* Mouse position x
|
||||
* @param y
|
||||
* Mouse position y
|
||||
* @param button
|
||||
* The button used (0=left, 1=right). The mouse wheel is mapped to
|
||||
* -1=down and -2=up.
|
||||
*/
|
||||
protected void ghostSlotClicked(GuiContainerBase gui, GhostSlot slot, int x, int y, int button) {
|
||||
ItemStack handStack = Minecraft.getMinecraft().thePlayer.inventory.getItemStack();
|
||||
ItemStack existingStack = slot.getStack();
|
||||
if (button == 0) { // left
|
||||
ghostSlotClickedPrimaryMouseButton(slot, handStack, existingStack);
|
||||
} else if (button == 1) { // right
|
||||
ghostSlotClickedSecondaryMouseButton(slot, handStack, existingStack);
|
||||
} else if (button == -2) { // wheel up
|
||||
ghostSlotClickedMouseWheelUp(slot, handStack, existingStack);
|
||||
} else if (button == -1) { // wheel down
|
||||
ghostSlotClickedMouseWheelDown(slot, handStack, existingStack);
|
||||
}
|
||||
}
|
||||
|
||||
protected void ghostSlotClickedPrimaryMouseButton(GhostSlot slot, ItemStack handStack, ItemStack existingStack) {
|
||||
if (handStack == null || handStack.getItem() == null || handStack.stackSize == 0) { // empty hand
|
||||
slot.putStack(null);
|
||||
} else { // item in hand
|
||||
if (existingStack == null || existingStack.getItem() == null || existingStack.stackSize == 0) { // empty slot
|
||||
replaceSlot(slot, handStack);
|
||||
} else { // filled slot
|
||||
if (ItemUtil.areStackMergable(existingStack, handStack)) { // same item
|
||||
if (existingStack.stackSize < existingStack.getMaxStackSize() && existingStack.stackSize < slot.getStackSizeLimit()) {
|
||||
increaseSlot(slot, existingStack);
|
||||
} else {
|
||||
// NOP
|
||||
}
|
||||
} else { // different item
|
||||
replaceSlot(slot, handStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void ghostSlotClickedSecondaryMouseButton(GhostSlot slot, ItemStack handStack, ItemStack existingStack) {
|
||||
if (handStack == null || handStack.getItem() == null || handStack.stackSize == 0) { // empty hand
|
||||
slot.putStack(null);
|
||||
} else { // item in hand
|
||||
if (existingStack == null || existingStack.getItem() == null || existingStack.stackSize == 0) { // empty slot
|
||||
replaceSlot1Item(slot, handStack);
|
||||
} else { // filled slot
|
||||
if (ItemUtil.areStackMergable(existingStack, handStack)) { // same item
|
||||
descreaseSlot(slot, existingStack);
|
||||
} else { // different item
|
||||
replaceSlot1Item(slot, handStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void ghostSlotClickedMouseWheelUp(GhostSlot slot, ItemStack handStack, ItemStack existingStack) {
|
||||
if (existingStack != null && existingStack.getItem() != null && existingStack.stackSize > 0 && existingStack.stackSize < existingStack.getMaxStackSize()
|
||||
&& existingStack.stackSize < slot.getStackSizeLimit()) {
|
||||
increaseSlot(slot, existingStack);
|
||||
}
|
||||
}
|
||||
|
||||
protected void ghostSlotClickedMouseWheelDown(GhostSlot slot, ItemStack handStack, ItemStack existingStack) {
|
||||
if (existingStack != null && existingStack.getItem() != null) {
|
||||
descreaseSlot(slot, existingStack);
|
||||
}
|
||||
}
|
||||
|
||||
// Slot interaction tools
|
||||
|
||||
protected void descreaseSlot(GhostSlot slot, ItemStack existingStack) {
|
||||
if (existingStack.stackSize > 1) {
|
||||
existingStack.stackSize--;
|
||||
slot.putStack(existingStack);
|
||||
} else {
|
||||
slot.putStack(null);
|
||||
}
|
||||
}
|
||||
|
||||
protected void increaseSlot(GhostSlot slot, ItemStack existingStack) {
|
||||
existingStack.stackSize++;
|
||||
slot.putStack(existingStack);
|
||||
}
|
||||
|
||||
protected void replaceSlot1Item(GhostSlot slot, ItemStack handStack) {
|
||||
ItemStack oneItem = handStack.copy();
|
||||
oneItem.stackSize = 1;
|
||||
slot.putStack(oneItem);
|
||||
}
|
||||
|
||||
protected void replaceSlot(GhostSlot slot, ItemStack handStack) {
|
||||
if (handStack.stackSize <= slot.getStackSizeLimit()) {
|
||||
slot.putStack(handStack);
|
||||
} else {
|
||||
ItemStack tmp = handStack.copy();
|
||||
tmp.stackSize = slot.getStackSizeLimit();
|
||||
slot.putStack(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
// Rendering
|
||||
|
||||
protected void startDrawing(GuiContainerBase gui) {
|
||||
gui.hoverGhostSlot = hoverGhostSlot = null;
|
||||
}
|
||||
|
||||
protected void drawGhostSlots(GuiContainerBase gui, int mouseX, int mouseY) {
|
||||
int sx = gui.getGuiLeft();
|
||||
int sy = gui.getGuiTop();
|
||||
gui.drawFakeItemsStart();
|
||||
try {
|
||||
gui.hoverGhostSlot = hoverGhostSlot = null;
|
||||
for (GhostSlot slot : ghostSlots) {
|
||||
ItemStack stack = slot.getStack();
|
||||
if (slot.isVisible()) {
|
||||
if (stack != null) {
|
||||
gui.drawFakeItemStack(slot.x + sx, slot.y + sy, stack);
|
||||
if (slot.shouldDisplayStdOverlay()) {
|
||||
gui.drawFakeItemStackStdOverlay(slot.x + sx, slot.y + sy, stack);
|
||||
}
|
||||
if (slot.shouldGrayOut()) {
|
||||
gui.ghostSlotHandler.drawGhostSlotGrayout(gui, slot);
|
||||
}
|
||||
}
|
||||
if (slot.isMouseOver(mouseX - sx, mouseY - sy)) {
|
||||
gui.hoverGhostSlot = hoverGhostSlot = slot;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hoverGhostSlot != null) {
|
||||
// draw hover last to prevent it from affecting rendering of other slots ...
|
||||
gui.drawFakeItemHover(hoverGhostSlot.x + sx, hoverGhostSlot.y + sy);
|
||||
}
|
||||
} finally {
|
||||
gui.drawFakeItemsEnd();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gray out the item that was just painted into a GhostSlot by overpainting it
|
||||
* with 50% transparent background. This gives the illusion that the item was
|
||||
* painted with 50% transparency. (100%*a ° 100%*b ° 50%*a == 100%*a ° 50%*b)
|
||||
*/
|
||||
protected void drawGhostSlotGrayout(GuiContainerBase gui, GhostSlot slot) {
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, slot.getGrayOutLevel());
|
||||
String guiTexture = gui.getGuiTexture();
|
||||
if (guiTexture == null) {
|
||||
NEUTRAL_SLOT_BACKGROUND.getMap().render(NEUTRAL_SLOT_BACKGROUND, gui.getGuiLeft() + slot.x, gui.getGuiTop() + slot.y, gui.getZlevel(), true);
|
||||
} else {
|
||||
RenderUtil.bindTexture(guiTexture);
|
||||
gui.drawTexturedModalRect(gui.getGuiLeft() + slot.x, gui.getGuiTop() + slot.y, slot.x, slot.y, 16, 16);
|
||||
}
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
}
|
||||
|
||||
|
||||
protected void drawGhostSlotTooltip(GuiContainerBase guiContainerBase, GhostSlot slot, int mouseX, int mouseY) {
|
||||
ItemStack stack = slot.getStack();
|
||||
if (stack != null) {
|
||||
guiContainerBase.renderToolTip(stack, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void drawGhostSlotToolTip(GuiContainerBase gui, int mouseX, int mouseY) {
|
||||
if (hoverGhostSlot != null && gui.mc.thePlayer.inventory.getItemStack() == null) {
|
||||
gui.drawGhostSlotTooltip(hoverGhostSlot, mouseX, mouseY);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -32,6 +32,7 @@ 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.EnderWidget;
|
||||
import com.enderio.core.client.render.RenderUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@@ -44,9 +45,13 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
protected List<IGuiOverlay> overlays = Lists.newArrayList();
|
||||
protected List<TextFieldEnder> textFields = Lists.newArrayList();
|
||||
protected List<VScrollbar> scrollbars = Lists.newArrayList();
|
||||
protected List<GhostSlot> ghostSlots = Lists.newArrayList();
|
||||
protected GhostSlotHandler ghostSlotHandler = new GhostSlotHandler();
|
||||
|
||||
@Deprecated
|
||||
protected List<GhostSlot> ghostSlots = ghostSlotHandler.getGhostSlots();
|
||||
@Deprecated
|
||||
protected GhostSlot hoverGhostSlot;
|
||||
|
||||
protected VScrollbar draggingScrollbar;
|
||||
|
||||
protected GuiContainerBase(Container par1Container) {
|
||||
@@ -198,12 +203,12 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
|
||||
@Override
|
||||
public List<GhostSlot> getGhostSlots() {
|
||||
return ghostSlots;
|
||||
return ghostSlotHandler.getGhostSlots();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
protected void ghostSlotClicked(GhostSlot slot, int x, int y, int button) {
|
||||
ItemStack st = Minecraft.getMinecraft().thePlayer.inventory.getItemStack();
|
||||
slot.putStack(st);
|
||||
ghostSlotHandler.ghostSlotClicked(this, slot, x, y, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -223,7 +228,7 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!ghostSlots.isEmpty()) {
|
||||
if (!ghostSlotHandler.getGhostSlots().isEmpty()) {
|
||||
GhostSlot slot = getGhostSlot(x, y);
|
||||
if (slot != null) {
|
||||
ghostSlotClicked(slot, x, y, button);
|
||||
@@ -277,6 +282,12 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
vs.mouseWheel(x, y, delta);
|
||||
}
|
||||
}
|
||||
if (!ghostSlotHandler.getGhostSlots().isEmpty()) {
|
||||
GhostSlot slot = getGhostSlot(x, y);
|
||||
if (slot != null) {
|
||||
ghostSlotClicked(slot, x, y, delta < 0 ? -1 : -2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void actionPerformedButton(IconButton btn, int mouseButton) {
|
||||
@@ -335,12 +346,13 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
vs.drawScrollbar(mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
drawGhostSlots(mouseX, mouseY);
|
||||
if (!ghostSlotHandler.getGhostSlots().isEmpty()) {
|
||||
drawGhostSlots(mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int par1, int par2, float par3) {
|
||||
hoverGhostSlot = null;
|
||||
int mx = realMx = par1;
|
||||
int my = realMy = par2;
|
||||
for (IGuiOverlay overlay : overlays) {
|
||||
@@ -354,10 +366,7 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
super.drawScreen(mx, my, par3);
|
||||
|
||||
if (draggingScrollbar == null) {
|
||||
if (hoverGhostSlot != null && mc.thePlayer.inventory.getItemStack() == null) {
|
||||
drawGhostSlotTooltip(hoverGhostSlot, par1, par2);
|
||||
}
|
||||
|
||||
ghostSlotHandler.drawGhostSlotToolTip(this, par1, par2);
|
||||
ttMan.drawTooltips(this, par1, par2);
|
||||
}
|
||||
}
|
||||
@@ -381,8 +390,8 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
}
|
||||
|
||||
protected void drawFakeItemsStart() {
|
||||
zLevel = 100.0F;
|
||||
itemRender.zLevel = 100.0F;
|
||||
zLevel = 0.0F;
|
||||
itemRender.zLevel = -25.0F;
|
||||
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
@@ -394,6 +403,10 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
itemRender.renderItemAndEffectIntoGUI(fontRendererObj, mc.renderEngine, stack, x, y);
|
||||
}
|
||||
|
||||
protected void drawFakeItemStackStdOverlay(int x, int y, ItemStack stack) {
|
||||
itemRender.renderItemOverlayIntoGUI(fontRendererObj, mc.renderEngine, stack, x, y, null);
|
||||
}
|
||||
|
||||
protected void drawFakeItemHover(int x, int y) {
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
@@ -410,53 +423,35 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
zLevel = 0.0F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderToolTip(ItemStack p_146285_1_, int p_146285_2_, int p_146285_3_) {
|
||||
super.renderToolTip(p_146285_1_, p_146285_2_, p_146285_3_);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
protected void drawGhostSlotTooltip(GhostSlot slot, int mouseX, int mouseY) {
|
||||
ItemStack stack = slot.getStack();
|
||||
if (stack != null) {
|
||||
renderToolTip(stack, mouseX, mouseY);
|
||||
}
|
||||
ghostSlotHandler.drawGhostSlotTooltip(this, slot, mouseX, mouseY);
|
||||
}
|
||||
|
||||
protected void drawGhostSlots(int mouseX, int mouseY) {
|
||||
if (ghostSlots.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
int sx = getGuiLeft();
|
||||
int sy = getGuiTop();
|
||||
drawFakeItemsStart();
|
||||
try {
|
||||
hoverGhostSlot = null;
|
||||
for (GhostSlot slot : ghostSlots) {
|
||||
ItemStack stack = slot.getStack();
|
||||
if (slot.isVisible()) {
|
||||
if (stack != null) {
|
||||
drawFakeItemStack(slot.x + sx, slot.y + sy, stack);
|
||||
}
|
||||
if (slot.isMouseOver(mouseX - sx, mouseY - sy)) {
|
||||
hoverGhostSlot = slot;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hoverGhostSlot != null) {
|
||||
// draw hover last to prevent it from affecting rendering of other slots ...
|
||||
drawFakeItemHover(hoverGhostSlot.x + sx, hoverGhostSlot.y + sy);
|
||||
}
|
||||
} finally {
|
||||
drawFakeItemsEnd();
|
||||
}
|
||||
}
|
||||
|
||||
protected GhostSlot getGhostSlot(int mouseX, int mouseY) {
|
||||
mouseX -= getGuiLeft();
|
||||
mouseY -= getGuiTop();
|
||||
for (GhostSlot slot : ghostSlots) {
|
||||
if (slot.isVisible() && slot.isMouseOver(mouseX, mouseY)) {
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Override this to allow GhostSlots to gray out with a custom background. Not
|
||||
* needed if the slot has the default "Minecraft-gray" background---but it may
|
||||
* be nicer to texture pack creators.
|
||||
*/
|
||||
protected String getGuiTexture() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
protected void drawGhostSlots(int mouseX, int mouseY) {
|
||||
ghostSlotHandler.drawGhostSlots(this, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
protected GhostSlot getGhostSlot(int mouseX, int mouseY) {
|
||||
return ghostSlotHandler.getGhostSlot(this, mouseX, mouseY);
|
||||
}
|
||||
|
||||
private boolean isMouseInOverlay(int mouseX, int mouseY, IGuiOverlay overlay) {
|
||||
int x = mouseX - getGuiLeft();
|
||||
int y = mouseY - getGuiTop();
|
||||
@@ -553,6 +548,10 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
}
|
||||
}
|
||||
|
||||
public float getZlevel() {
|
||||
return zLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGuiLeft() {
|
||||
return guiLeft;
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.enderio.core.client.gui.widget;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class GhostBackgroundItemSlot extends GhostSlot {
|
||||
|
||||
private final ItemStack stack;
|
||||
private final Slot parent;
|
||||
|
||||
public GhostBackgroundItemSlot(ItemStack stack, int x, int y) {
|
||||
this.stack = stack;
|
||||
this.parent = null;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.grayOut = true;
|
||||
this.grayOutLevel = .75f;
|
||||
}
|
||||
|
||||
public GhostBackgroundItemSlot(ItemStack stack, Slot parent) {
|
||||
this.stack = stack;
|
||||
this.parent = parent;
|
||||
this.x = parent.xDisplayPosition;
|
||||
this.y = parent.yDisplayPosition;
|
||||
this.grayOut = true;
|
||||
this.grayOutLevel = .75f;
|
||||
}
|
||||
|
||||
public GhostBackgroundItemSlot(Item item, int x, int y) {
|
||||
this(new ItemStack(item), x, y);
|
||||
}
|
||||
|
||||
public GhostBackgroundItemSlot(Block block, int x, int y) {
|
||||
this(new ItemStack(block), x, y);
|
||||
}
|
||||
|
||||
public GhostBackgroundItemSlot(Item item, Slot parent) {
|
||||
this(new ItemStack(item), parent);
|
||||
}
|
||||
|
||||
public GhostBackgroundItemSlot(Block block, Slot parent) {
|
||||
this(new ItemStack(block), parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMouseOver(int mx, int my) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStack() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putStack(ItemStack stack) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return parent != null ? parent.xDisplayPosition >= 0 && parent.yDisplayPosition >= 0 : super.isVisible();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,25 +2,68 @@ package com.enderio.core.client.gui.widget;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class GhostSlot {
|
||||
import com.enderio.core.common.TileEntityEnder;
|
||||
import com.enderio.core.common.network.EnderPacketHandler;
|
||||
import com.enderio.core.common.network.PacketGhostSlot;
|
||||
|
||||
public abstract class GhostSlot {
|
||||
|
||||
public TileEntityEnder te = null;
|
||||
public int slot = -1;
|
||||
public int x;
|
||||
public int y;
|
||||
|
||||
public boolean visible = true;
|
||||
public ItemStack stack;
|
||||
public boolean grayOut = true;
|
||||
public float grayOutLevel = 0.5f;
|
||||
public boolean displayStdOverlay = false;
|
||||
public int stackSizeLimit = 1;
|
||||
|
||||
public boolean isMouseOver(int mx, int my) {
|
||||
return mx >= x && mx < (x + 16) && my >= y && my < (y + 16);
|
||||
}
|
||||
|
||||
public abstract ItemStack getStack();
|
||||
|
||||
public void putStack(ItemStack stack) {
|
||||
if (te != null) {
|
||||
EnderPacketHandler.sendToServer(PacketGhostSlot.setGhostSlotContents(te, slot, stack));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the slot be displayed at all?
|
||||
*/
|
||||
public boolean isVisible() {
|
||||
return visible;
|
||||
}
|
||||
|
||||
public ItemStack getStack() {
|
||||
return stack;
|
||||
/**
|
||||
* Should the slot be grayed out?
|
||||
*/
|
||||
public boolean shouldGrayOut() {
|
||||
return grayOut;
|
||||
}
|
||||
|
||||
public void putStack(ItemStack stack) {
|
||||
/**
|
||||
* If it should be grayed out, how far? (1=no graying, 0=fully invisible)
|
||||
*/
|
||||
public float getGrayOutLevel() {
|
||||
return grayOutLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the items in the slot have their standard overlay (stacksize)?
|
||||
*/
|
||||
public boolean shouldDisplayStdOverlay() {
|
||||
return displayStdOverlay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Limit the stack size? (Enable the standard overlay if this is not 1.)
|
||||
*/
|
||||
public int getStackSizeLimit() {
|
||||
return stackSizeLimit;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package com.enderio.core.client.gui.widget;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class TemplateSlot extends Slot {
|
||||
|
||||
protected int slotIndex;
|
||||
|
||||
public TemplateSlot(IInventory inventory, int slotIndex, int x, int y) {
|
||||
super(inventory, slotIndex, x, y);
|
||||
this.slotIndex = slotIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeStack(EntityPlayer player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int par1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putStack(ItemStack par1ItemStack) {
|
||||
if (par1ItemStack != null) {
|
||||
par1ItemStack.stackSize = 0;
|
||||
}
|
||||
inventory.setInventorySlotContents(slotIndex, par1ItemStack);
|
||||
onSlotChanged();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -53,7 +53,9 @@ public enum EnderWidget implements IWidgetIcon {
|
||||
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);
|
||||
X_BUT_HOVER_PRESSED(200, 56, 8, 8),
|
||||
|
||||
NEUTRAL_SLOT_BACKGROUND(112, 176, 16, 16), ;
|
||||
|
||||
public static final ResourceLocation TEXTURE = new ResourceLocation(EnderCore.MODID, "textures/gui/widgets.png");
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.enderio.core.common;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
@@ -158,4 +159,16 @@ public abstract class TileEntityEnder extends TileEntity {
|
||||
protected boolean shouldDoWorkThisTick(int interval, int offset) {
|
||||
return (worldObj.getTotalWorldTime() + checkOffset + offset) % interval == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called server-side when a GhostSlot is changed. Check that the given slot
|
||||
* number really is a ghost slot before storing the given stack.
|
||||
*
|
||||
* @param slot
|
||||
* The slot number that was given to the ghost slot
|
||||
* @param stack
|
||||
* The stack that should be placed, null to clear
|
||||
*/
|
||||
public void setGhostSlotContents(int slot, ItemStack stack) {
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ public class EnderPacketHandler {
|
||||
INSTANCE.registerMessage(PacketConfigSync.Handler.class, PacketConfigSync.class, 0, Side.CLIENT);
|
||||
INSTANCE.registerMessage(PacketProgress.Handler.class, PacketProgress.class, 1, Side.CLIENT);
|
||||
INSTANCE.registerMessage(PacketNoSpamChat.Handler.class, PacketNoSpamChat.class, 2, Side.CLIENT);
|
||||
INSTANCE.registerMessage(PacketGhostSlot.Handler.class, PacketGhostSlot.class, 3, Side.SERVER);
|
||||
}
|
||||
|
||||
public static void sendToAllAround(IMessage message, TileEntity te, int range) {
|
||||
@@ -33,4 +34,8 @@ public class EnderPacketHandler {
|
||||
public static void sendTo(IMessage message, EntityPlayerMP player) {
|
||||
INSTANCE.sendTo(message, player);
|
||||
}
|
||||
|
||||
public static void sendToServer(IMessage message) {
|
||||
INSTANCE.sendToServer(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.enderio.core.common.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import com.enderio.core.EnderCore;
|
||||
import com.enderio.core.api.common.util.IProgressTile;
|
||||
import com.enderio.core.common.TileEntityEnder;
|
||||
import com.enderio.core.common.network.MessageTileEntity;
|
||||
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
public class PacketGhostSlot extends MessageTileEntity<TileEntityEnder> {
|
||||
|
||||
private int slot;
|
||||
private ItemStack stack;
|
||||
|
||||
public PacketGhostSlot() {
|
||||
}
|
||||
|
||||
private PacketGhostSlot(TileEntityEnder tile) {
|
||||
super(tile);
|
||||
}
|
||||
|
||||
public static PacketGhostSlot setGhostSlotContents(TileEntityEnder te, int slot, ItemStack stack) {
|
||||
PacketGhostSlot msg = new PacketGhostSlot(te);
|
||||
msg.slot = slot;
|
||||
msg.stack = stack;
|
||||
return msg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
super.fromBytes(buf);
|
||||
slot = buf.readShort();
|
||||
stack = ByteBufUtils.readItemStack(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
super.toBytes(buf);
|
||||
buf.writeShort(slot);
|
||||
ByteBufUtils.writeItemStack(buf, stack);
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<PacketGhostSlot, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketGhostSlot msg, MessageContext ctx) {
|
||||
TileEntityEnder te = msg.getTileEntity(ctx.getServerHandler().playerEntity.worldObj);
|
||||
if (te != null) {
|
||||
te.setGhostSlotContents(msg.slot, msg.stack);
|
||||
te.getWorldObj().markBlockForUpdate(msg.x, msg.y, msg.z);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user