WCTBase->AEBase Gui,Container

This commit is contained in:
Raven Szewczyk committed 2022-08-24 18:38:42 +01:00
1 parent 71c0304f09
commit b8a15b7ee4
22 files changed
+256 -4109

No files matched your search

@@ -1,820 +0,0 @@
package net.p455w0rd.wirelesscraftingterminal.client.gui;
import appeng.api.storage.data.IAEItemStack;
import appeng.client.gui.widgets.ITooltip;
import appeng.container.slot.SlotRestrictedInput;
import appeng.helpers.InventoryAction;
import com.google.common.base.Joiner;
import com.google.common.base.Stopwatch;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.ObfuscationReflectionHelper;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.p455w0rd.wirelesscraftingterminal.client.gui.widgets.GuiScrollbar;
import net.p455w0rd.wirelesscraftingterminal.client.me.InternalSlotME;
import net.p455w0rd.wirelesscraftingterminal.client.me.SlotDisconnected;
import net.p455w0rd.wirelesscraftingterminal.client.me.SlotME;
import net.p455w0rd.wirelesscraftingterminal.client.me.WCTRenderItem;
import net.p455w0rd.wirelesscraftingterminal.common.container.WCTBaseContainer;
import net.p455w0rd.wirelesscraftingterminal.common.container.slot.AppEngCraftingSlot;
import net.p455w0rd.wirelesscraftingterminal.common.container.slot.AppEngSlot;
import net.p455w0rd.wirelesscraftingterminal.common.container.slot.AppEngSlot.hasCalculatedValidness;
import net.p455w0rd.wirelesscraftingterminal.common.container.slot.OptionalSlotFake;
import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotCraftingTerm;
import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotDisabled;
import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotFake;
import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotInaccessible;
import net.p455w0rd.wirelesscraftingterminal.common.container.slot.SlotOutput;
import net.p455w0rd.wirelesscraftingterminal.common.utils.WCTLog;
import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler;
import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketInventoryAction;
import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSwapSlots;
import net.p455w0rd.wirelesscraftingterminal.integration.IntegrationRegistry;
import net.p455w0rd.wirelesscraftingterminal.integration.IntegrationType;
import net.p455w0rd.wirelesscraftingterminal.integration.abstraction.INEI;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
public abstract class WCTBaseGui extends GuiContainer {
private static boolean switchingGuis;
private final List<InternalSlotME> meSlots = new LinkedList<InternalSlotME>();
// drag y
private final Set<Slot> drag_click = new HashSet<Slot>();
private final WCTRenderItem aeRenderItem = new WCTRenderItem();
private GuiScrollbar scrollBar = null;
private boolean disableShiftClick = false;
private Stopwatch dbl_clickTimer = Stopwatch.createStarted();
private ItemStack dbl_whichItem;
private Slot bl_clicked;
private boolean subGui;
public WCTBaseGui(final Container container) {
super(container);
this.subGui = switchingGuis;
switchingGuis = false;
}
protected static String join(final Collection<String> toolTip, final String delimiter) {
final Joiner joiner = Joiner.on(delimiter);
return joiner.join(toolTip);
}
protected int getQty(final GuiButton btn) {
try {
final DecimalFormat df = new DecimalFormat("+#;-#");
return df.parse(btn.displayString).intValue();
} catch (final ParseException e) {
return 0;
}
}
public boolean isSubGui() {
return this.subGui;
}
@Override
public void initGui() {
super.initGui();
final List<Slot> slots = this.getInventorySlots();
final Iterator<Slot> i = slots.iterator();
while (i.hasNext()) {
if (i.next() instanceof SlotME) {
i.remove();
}
}
for (final InternalSlotME me : this.meSlots) {
slots.add(new SlotME(me));
}
}
@SuppressWarnings("unchecked")
private List<Slot> getInventorySlots() {
return this.inventorySlots.inventorySlots;
}
@Override
public void drawScreen(final int mouseX, final int mouseY, final float btn) {
super.drawScreen(mouseX, mouseY, btn);
final boolean hasClicked = Mouse.isButtonDown(0);
if (hasClicked && this.scrollBar != null) {
this.scrollBar.click(this, mouseX - this.guiLeft, mouseY - this.guiTop);
}
for (final Object c : this.buttonList) {
if (c instanceof ITooltip) {
final ITooltip tooltip = (ITooltip) c;
final int x = tooltip.xPos(); // ((GuiImgButton) c).xPosition;
int y = tooltip.yPos(); // ((GuiImgButton) c).yPosition;
if (x < mouseX && x + tooltip.getWidth() > mouseX && tooltip.isVisible()) {
if (y < mouseY && y + tooltip.getHeight() > mouseY) {
if (y < 15) {
y = 15;
}
final String msg = tooltip.getMessage();
if (msg != null) {
this.drawTooltip(x + 11, y + 4, 0, msg);
}
}
}
}
}
}
public void drawTooltip(final int par2, final int par3, final int forceWidth, final String message) {
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
RenderHelper.disableStandardItemLighting();
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_DEPTH_TEST);
final String[] var4 = message.split("\n");
if (var4.length > 0) {
int var5 = 0;
int var6;
int var7;
for (var6 = 0; var6 < var4.length; ++var6) {
var7 = this.fontRendererObj.getStringWidth(var4[var6]);
if (var7 > var5) {
var5 = var7;
}
}
var6 = par2 + 12;
var7 = par3 - 12;
int var9 = 8;
if (var4.length > 1) {
var9 += 2 + (var4.length - 1) * 10;
}
if (this.guiTop + var7 + var9 + 6 > this.height) {
var7 = this.height - var9 - this.guiTop - 6;
}
if (forceWidth > 0) {
var5 = forceWidth;
}
this.zLevel = 300.0F;
itemRender.zLevel = 300.0F;
final int var10 = -267386864;
this.drawGradientRect(var6 - 3, var7 - 4, var6 + var5 + 3, var7 - 3, var10, var10);
this.drawGradientRect(var6 - 3, var7 + var9 + 3, var6 + var5 + 3, var7 + var9 + 4, var10, var10);
this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 + var9 + 3, var10, var10);
this.drawGradientRect(var6 - 4, var7 - 3, var6 - 3, var7 + var9 + 3, var10, var10);
this.drawGradientRect(var6 + var5 + 3, var7 - 3, var6 + var5 + 4, var7 + var9 + 3, var10, var10);
final int var11 = 1347420415;
final int var12 = (var11 & 16711422) >> 1 | var11 & -16777216;
this.drawGradientRect(var6 - 3, var7 - 3 + 1, var6 - 3 + 1, var7 + var9 + 3 - 1, var11, var12);
this.drawGradientRect(var6 + var5 + 2, var7 - 3 + 1, var6 + var5 + 3, var7 + var9 + 3 - 1, var11, var12);
this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 - 3 + 1, var11, var11);
this.drawGradientRect(var6 - 3, var7 + var9 + 2, var6 + var5 + 3, var7 + var9 + 3, var12, var12);
for (int var13 = 0; var13 < var4.length; ++var13) {
String var14 = var4[var13];
if (var13 == 0) {
var14 = '\u00a7' + Integer.toHexString(15) + var14;
} else {
var14 = "\u00a77" + var14;
}
this.fontRendererObj.drawStringWithShadow(var14, var6, var7, -1);
if (var13 == 0) {
var7 += 2;
}
var7 += 10;
}
this.zLevel = 0.0F;
itemRender.zLevel = 0.0F;
}
GL11.glPopAttrib();
}
@Override
protected final void drawGuiContainerForegroundLayer(final int x, final int y) {
final int ox = this.guiLeft; // (width - xSize) / 2;
final int oy = this.guiTop; // (height - ySize) / 2;
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
if (this.scrollBar != null) {
this.scrollBar.draw(this);
}
this.drawFG(ox, oy, x, y);
}
public abstract void drawFG(int offsetX, int offsetY, int mouseX, int mouseY);
@Override
protected final void drawGuiContainerBackgroundLayer(final float f, final int x, final int y) {
final int ox = this.guiLeft; // (width - xSize) / 2;
final int oy = this.guiTop; // (height - ySize) / 2;
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.drawBG(ox, oy, x, y);
final List<Slot> slots = this.getInventorySlots();
for (final Slot slot : slots) {
if (slot instanceof OptionalSlotFake) {
final OptionalSlotFake fs = (OptionalSlotFake) slot;
if (fs.renderDisabled()) {
if (fs.isEnabled()) {
this.drawTexturedModalRect(
ox + fs.xDisplayPosition - 1,
oy + fs.yDisplayPosition - 1,
fs.getSourceX() - 1,
fs.getSourceY() - 1,
18,
18);
} else {
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 0.4F);
GL11.glEnable(GL11.GL_BLEND);
this.drawTexturedModalRect(
ox + fs.xDisplayPosition - 1,
oy + fs.yDisplayPosition - 1,
fs.getSourceX() - 1,
fs.getSourceY() - 1,
18,
18);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glPopAttrib();
}
}
}
}
}
@Override
protected void mouseClicked(final int xCoord, final int yCoord, final int btn) {
this.drag_click.clear();
if (btn == 1) {
for (final Object o : this.buttonList) {
final GuiButton guibutton = (GuiButton) o;
if (guibutton.mousePressed(this.mc, xCoord, yCoord)) {
super.mouseClicked(xCoord, yCoord, 0);
return;
}
}
}
super.mouseClicked(xCoord, yCoord, btn);
}
@Override
protected void mouseClickMove(final int x, final int y, final int c, final long d) {
final Slot slot = this.getSlot(x, y);
final ItemStack itemstack = this.mc.thePlayer.inventory.getItemStack();
if (slot instanceof SlotFake && itemstack != null) {
this.drag_click.add(slot);
if (this.drag_click.size() > 1) {
for (final Slot dr : this.drag_click) {
final PacketInventoryAction p = new PacketInventoryAction(
c == 0 ? InventoryAction.PICKUP_OR_SET_DOWN : InventoryAction.PLACE_SINGLE,
dr.slotNumber,
0);
NetworkHandler.instance.sendToServer(p);
}
}
} else {
super.mouseClickMove(x, y, c, d);
}
}
@Override
protected void handleMouseClick(final Slot slot, final int slotIdx, final int ctrlDown, final int key) {
final EntityPlayer player = Minecraft.getMinecraft().thePlayer;
if (slot instanceof SlotFake) {
final InventoryAction action =
ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN;
if (this.drag_click.size() > 1) {
return;
}
final PacketInventoryAction p = new PacketInventoryAction(action, slotIdx, 0);
NetworkHandler.instance.sendToServer(p);
return;
}
if (slot instanceof SlotCraftingTerm) {
if (key == 6) {
return; // prevent weird double clicks..
}
InventoryAction action = null;
if (key == 1) {
action = InventoryAction.CRAFT_SHIFT;
} else {
action = ctrlDown == 1 ? InventoryAction.CRAFT_STACK : InventoryAction.CRAFT_ITEM;
}
final PacketInventoryAction p = new PacketInventoryAction(action, slotIdx, 0);
NetworkHandler.instance.sendToServer(p);
return;
}
if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
if (this.enableSpaceClicking()) {
IAEItemStack stack = null;
if (slot instanceof SlotME) {
stack = ((SlotME) slot).getAEStack();
}
int slotNum = this.getInventorySlots().size();
if (!(slot instanceof SlotME) && slot != null) {
slotNum = slot.slotNumber;
}
((WCTBaseContainer) this.inventorySlots).setTargetStack(stack);
final PacketInventoryAction p = new PacketInventoryAction(InventoryAction.MOVE_REGION, slotNum, 0);
NetworkHandler.instance.sendToServer(p);
return;
}
}
if (slot instanceof SlotDisconnected) {
InventoryAction action = null;
switch (key) {
case 0: // pickup / set-down.
action = ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN;
break;
case 1:
action = ctrlDown == 1 ? InventoryAction.PICKUP_SINGLE : InventoryAction.SHIFT_CLICK;
break;
case 3: // creative dupe:
if (player.capabilities.isCreativeMode) {
action = InventoryAction.CREATIVE_DUPLICATE;
}
break;
default:
case 4: // drop item:
case 6:
}
if (action != null) {
final PacketInventoryAction p = new PacketInventoryAction(
action,
slot.getSlotIndex(),
((SlotDisconnected) slot).getSlot().getId());
NetworkHandler.instance.sendToServer(p);
}
return;
}
if (slot instanceof SlotME) {
InventoryAction action = null;
IAEItemStack stack = null;
switch (key) {
case 0: // pickup / set-down.
action = ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN;
stack = ((SlotME) slot).getAEStack();
if (stack != null
&& action == InventoryAction.PICKUP_OR_SET_DOWN
&& stack.getStackSize() == 0
&& player.inventory.getItemStack() == null) {
action = InventoryAction.AUTO_CRAFT;
}
break;
case 1:
action = ctrlDown == 1 ? InventoryAction.PICKUP_SINGLE : InventoryAction.SHIFT_CLICK;
stack = ((SlotME) slot).getAEStack();
break;
case 3: // creative dupe:
stack = ((SlotME) slot).getAEStack();
if (stack != null && stack.isCraftable()) {
action = InventoryAction.AUTO_CRAFT;
} else if (player.capabilities.isCreativeMode) {
final IAEItemStack slotItem = ((SlotME) slot).getAEStack();
if (slotItem != null) {
action = InventoryAction.CREATIVE_DUPLICATE;
}
}
break;
default:
case 4: // drop item:
case 6:
}
if (action != null) {
((WCTBaseContainer) this.inventorySlots).setTargetStack(stack);
final PacketInventoryAction p = new PacketInventoryAction(
action, this.getInventorySlots().size(), 0);
NetworkHandler.instance.sendToServer(p);
}
return;
}
if (!this.disableShiftClick && isShiftKeyDown()) {
this.disableShiftClick = true;
if (this.dbl_whichItem == null
|| this.bl_clicked != slot
|| this.dbl_clickTimer.elapsed(TimeUnit.MILLISECONDS) > 150) {
// some simple double click logic.
this.bl_clicked = slot;
this.dbl_clickTimer = Stopwatch.createStarted();
if (slot != null) {
this.dbl_whichItem = slot.getHasStack() ? slot.getStack().copy() : null;
} else {
this.dbl_whichItem = null;
}
} else if (this.dbl_whichItem != null) {
// a replica of the weird broken vanilla feature.
final List<Slot> slots = this.getInventorySlots();
for (final Slot inventorySlot : slots) {
if (inventorySlot != null
&& inventorySlot.canTakeStack(this.mc.thePlayer)
&& inventorySlot.getHasStack()
&& inventorySlot.inventory == slot.inventory
&& Container.func_94527_a(inventorySlot, this.dbl_whichItem, true)) {
this.handleMouseClick(inventorySlot, inventorySlot.slotNumber, ctrlDown, 1);
}
}
}
this.disableShiftClick = false;
}
super.handleMouseClick(slot, slotIdx, ctrlDown, key);
}
@Override
protected boolean checkHotbarKeys(final int keyCode) {
final Slot theSlot;
try {
theSlot = ObfuscationReflectionHelper.getPrivateValue(
GuiContainer.class, this, "theSlot", "field_147006_u", "f");
} catch (final Throwable t) {
return false;
}
if (this.mc.thePlayer.inventory.getItemStack() == null && theSlot != null) {
for (int j = 0; j < 9; ++j) {
if (keyCode == this.mc.gameSettings.keyBindsHotbar[j].getKeyCode()) {
final List<Slot> slots = this.getInventorySlots();
for (final Slot s : slots) {
if (s.getSlotIndex() == j
&& s.inventory == ((WCTBaseContainer) this.inventorySlots).getPlayerInv()) {
if (!s.canTakeStack(((WCTBaseContainer) this.inventorySlots).getPlayerInv().player)) {
return false;
}
}
}
if (theSlot.getSlotStackLimit() == 64) {
this.handleMouseClick(theSlot, theSlot.slotNumber, j, 2);
return true;
} else {
for (final Slot s : slots) {
if (s.getSlotIndex() == j
&& s.inventory == ((WCTBaseContainer) this.inventorySlots).getPlayerInv()) {
NetworkHandler.instance.sendToServer(
new PacketSwapSlots(s.slotNumber, theSlot.slotNumber));
return true;
}
}
}
}
}
}
return false;
}
@Override
public void onGuiClosed() {
super.onGuiClosed();
this.subGui = true; // in case the gui is reopened later ( i'm looking at you NEI )
}
protected Slot getSlot(final int mouseX, final int mouseY) {
final List<Slot> slots = this.getInventorySlots();
for (final Slot slot : slots) {
// isPointInRegion
if (this.func_146978_c(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, mouseX, mouseY)) {
return slot;
}
}
return null;
}
public abstract void drawBG(int offsetX, int offsetY, int mouseX, int mouseY);
@Override
public void handleMouseInput() {
super.handleMouseInput();
final int i = Mouse.getEventDWheel();
if (i != 0 && isShiftKeyDown()) {
final int x = Mouse.getEventX() * this.width / this.mc.displayWidth;
final int y = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1;
this.mouseWheelEvent(x, y, i / Math.abs(i));
} else if (i != 0 && this.scrollBar != null) {
this.scrollBar.wheel(i);
}
}
private void mouseWheelEvent(final int x, final int y, final int wheel) {
final Slot slot = this.getSlot(x, y);
if (slot instanceof SlotME) {
final IAEItemStack item = ((SlotME) slot).getAEStack();
if (item != null) {
((WCTBaseContainer) this.inventorySlots).setTargetStack(item);
final InventoryAction direction = wheel > 0 ? InventoryAction.ROLL_DOWN : InventoryAction.ROLL_UP;
final int times = Math.abs(wheel);
final int inventorySize = this.getInventorySlots().size();
for (int h = 0; h < times; h++) {
final PacketInventoryAction p = new PacketInventoryAction(direction, inventorySize, 0);
NetworkHandler.instance.sendToServer(p);
}
}
}
}
protected boolean enableSpaceClicking() {
return true;
}
public void bindTexture(final String base, final String file) {
final ResourceLocation loc = new ResourceLocation(base, "textures/" + file);
this.mc.getTextureManager().bindTexture(loc);
}
protected void drawItem(final int x, final int y, final ItemStack is) {
this.zLevel = 100.0F;
itemRender.zLevel = 100.0F;
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
GL11.glEnable(GL11.GL_DEPTH_TEST);
RenderHelper.enableGUIStandardItemLighting();
itemRender.renderItemAndEffectIntoGUI(this.fontRendererObj, this.mc.renderEngine, is, x, y);
GL11.glPopAttrib();
itemRender.zLevel = 0.0F;
this.zLevel = 0.0F;
}
protected String getGuiDisplayName(final String in) {
return this.hasCustomInventoryName() ? this.getInventoryName() : in;
}
private boolean hasCustomInventoryName() {
if (this.inventorySlots instanceof WCTBaseContainer) {
return ((WCTBaseContainer) this.inventorySlots).getCustomName() != null;
}
return false;
}
private String getInventoryName() {
return ((WCTBaseContainer) this.inventorySlots).getCustomName();
}
private void drawSlot(final Slot s) {
if (s instanceof SlotME) {
final RenderItem pIR = this.setItemRender(this.aeRenderItem);
try {
this.zLevel = 100.0F;
itemRender.zLevel = 100.0F;
if (!this.isPowered()) {
GL11.glDisable(GL11.GL_LIGHTING);
drawRect(
s.xDisplayPosition,
s.yDisplayPosition,
16 + s.xDisplayPosition,
16 + s.yDisplayPosition,
0x66111111);
GL11.glEnable(GL11.GL_LIGHTING);
}
this.zLevel = 0.0F;
itemRender.zLevel = 0.0F;
this.aeRenderItem.setAeStack(((SlotME) s).getAEStack());
this.safeDrawSlot(s);
} catch (final Exception err) {
WCTLog.warning("WCT prevented crash while drawing slot: " + err.toString());
}
this.setItemRender(pIR);
return;
} else {
try {
final ItemStack is = s.getStack();
if (s instanceof AppEngSlot
&& (((AppEngSlot) s).renderIconWithItem() || is == null)
&& (((AppEngSlot) s).shouldDisplay())) {
final AppEngSlot aes = (AppEngSlot) s;
if (aes.getIcon() >= 0) {
this.bindTexture("guis/states.png");
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
final Tessellator tessellator = Tessellator.instance;
try {
final int uv_y = (int) Math.floor(aes.getIcon() / 16);
final int uv_x = aes.getIcon() - uv_y * 16;
GL11.glEnable(GL11.GL_BLEND);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
final float par1 = aes.xDisplayPosition;
final float par2 = aes.yDisplayPosition;
final float par3 = uv_x * 16;
final float par4 = uv_y * 16;
tessellator.startDrawingQuads();
tessellator.setColorRGBA_F(1.0f, 1.0f, 1.0f, aes.getOpacityOfIcon());
final float f1 = 0.00390625F;
final float f = 0.00390625F;
final float par6 = 16;
tessellator.addVertexWithUV(
par1 + 0, par2 + par6, this.zLevel, (par3 + 0) * f, (par4 + par6) * f1);
final float par5 = 16;
tessellator.addVertexWithUV(
par1 + par5, par2 + par6, this.zLevel, (par3 + par5) * f, (par4 + par6) * f1);
tessellator.addVertexWithUV(
par1 + par5, par2 + 0, this.zLevel, (par3 + par5) * f, (par4 + 0) * f1);
tessellator.addVertexWithUV(
par1 + 0, par2 + 0, this.zLevel, (par3 + 0) * f, (par4 + 0) * f1);
tessellator.setColorRGBA_F(1.0f, 1.0f, 1.0f, 1.0f);
tessellator.draw();
} catch (final Exception err) {
}
GL11.glPopAttrib();
}
}
if (is != null && s instanceof AppEngSlot) {
if (((AppEngSlot) s).getIsValid() == hasCalculatedValidness.NotAvailable) {
boolean isValid = s.isItemValid(is)
|| s instanceof SlotOutput
|| s instanceof AppEngCraftingSlot
|| s instanceof SlotDisabled
|| s instanceof SlotInaccessible
|| s instanceof SlotFake
|| s instanceof SlotRestrictedInput
|| s instanceof SlotDisconnected;
if (isValid && s instanceof SlotRestrictedInput) {
try {
isValid = ((SlotRestrictedInput) s).isValid(is, this.mc.theWorld);
} catch (final Exception err) {
WCTLog.debug(err.getMessage());
}
}
((AppEngSlot) s)
.setIsValid(isValid ? hasCalculatedValidness.Valid : hasCalculatedValidness.Invalid);
}
if (((AppEngSlot) s).getIsValid() == hasCalculatedValidness.Invalid) {
this.zLevel = 100.0F;
itemRender.zLevel = 100.0F;
GL11.glDisable(GL11.GL_LIGHTING);
drawRect(
s.xDisplayPosition,
s.yDisplayPosition,
16 + s.xDisplayPosition,
16 + s.yDisplayPosition,
0x66ff6666);
GL11.glEnable(GL11.GL_LIGHTING);
this.zLevel = 0.0F;
itemRender.zLevel = 0.0F;
}
}
if (s instanceof AppEngSlot) {
((AppEngSlot) s).setDisplay(true);
this.safeDrawSlot(s);
} else {
this.safeDrawSlot(s);
}
return;
} catch (final Exception err) {
WCTLog.warning("WCT prevented crash while drawing slot: " + err.toString());
}
}
// do the usual for non-ME Slots.
this.safeDrawSlot(s);
}
private RenderItem setItemRender(final RenderItem item) {
if (Loader.isModLoaded("NotEnoughItems")) {
return ((INEI) IntegrationRegistry.INSTANCE.getInstance(IntegrationType.NEI)).setItemRender(item);
} else {
final RenderItem ri = itemRender;
itemRender = item;
return ri;
}
}
protected boolean isPowered() {
return true;
}
private void safeDrawSlot(final Slot s) {
try {
GuiContainer.class
.getDeclaredMethod("func_146977_a_original", Slot.class)
.invoke(this, s);
} catch (final Exception err) {
}
}
public void bindTexture(final String file) {
final ResourceLocation loc = new ResourceLocation("appliedenergistics2", "textures/" + file);
this.mc.getTextureManager().bindTexture(loc);
}
public void func_146977_a(final Slot s) {
this.drawSlot(s);
}
protected GuiScrollbar getScrollBar() {
return this.scrollBar;
}
protected void setScrollBar(final GuiScrollbar myScrollBar) {
this.scrollBar = myScrollBar;
}
protected List<InternalSlotME> getMeSlots() {
return this.meSlots;
}
public static final synchronized boolean isSwitchingGuis() {
return switchingGuis;
}
public static final synchronized void setSwitchingGuis(final boolean switchingGuis) {
WCTBaseGui.switchingGuis = switchingGuis;
}
protected void addItemTooltip(ItemStack is, List<String> lineList) {
if (isShiftKeyDown()) {
List l = is.getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips);
if (!l.isEmpty()) l.remove(0);
lineList.addAll(l);
} else {
// TODO: update AE2 on maven and dependency in build gradle
// lineList.add(GuiText.HoldShiftForTooltip.getLocal());
}
}
}
@@ -1,119 +0,0 @@
package net.p455w0rd.wirelesscraftingterminal.client.gui.widgets;
import appeng.client.gui.widgets.IScrollSource;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.p455w0rd.wirelesscraftingterminal.client.gui.GuiWirelessCraftingTerminal;
import net.p455w0rd.wirelesscraftingterminal.client.gui.WCTBaseGui;
import org.lwjgl.opengl.GL11;
public class GuiScrollbar implements IScrollSource {
private int displayX = 0;
private int displayY = 0;
private int width = 12;
private int height = 16;
private int pageSize = 1;
private int maxScroll = 0;
private int minScroll = 0;
private int currentScroll = 0;
public void draw(final GuiContainer g) {
if (g instanceof GuiWirelessCraftingTerminal) {
((GuiWirelessCraftingTerminal) g).bindTexture("minecraft", "gui/container/creative_inventory/tabs.png");
} else if (g instanceof WCTBaseGui) {
((WCTBaseGui) g).bindTexture("minecraft", "gui/container/creative_inventory/tabs.png");
}
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
if (this.getRange() == 0) {
g.drawTexturedModalRect(this.displayX, this.displayY, 232 + this.width, 0, this.width, 15);
} else {
final int offset = (this.currentScroll - this.minScroll) * (this.height - 15) / this.getRange();
g.drawTexturedModalRect(this.displayX, offset + this.displayY, 232, 0, this.width, 15);
}
}
private int getRange() {
return this.maxScroll - this.minScroll;
}
public int getLeft() {
return this.displayX;
}
public GuiScrollbar setLeft(final int v) {
this.displayX = v;
return this;
}
public int getTop() {
return this.displayY;
}
public GuiScrollbar setTop(final int v) {
this.displayY = v;
return this;
}
public int getWidth() {
return this.width;
}
public GuiScrollbar setWidth(final int v) {
this.width = v;
return this;
}
public int getHeight() {
return this.height;
}
public GuiScrollbar setHeight(final int v) {
this.height = v;
return this;
}
public void setRange(final int min, final int max, final int pageSize) {
this.minScroll = min;
this.maxScroll = max;
this.pageSize = pageSize;
if (this.minScroll > this.maxScroll) {
this.maxScroll = this.minScroll;
}
this.applyRange();
}
private void applyRange() {
this.currentScroll = Math.max(Math.min(this.currentScroll, this.maxScroll), this.minScroll);
}
@Override
public int getCurrentScroll() {
return this.currentScroll;
}
public void click(final GuiContainer aeBaseGui, final int x, final int y) {
if (this.getRange() == 0) {
return;
}
if (x > this.displayX && x <= this.displayX + this.width) {
if (y > this.displayY && y <= this.displayY + this.height) {
this.currentScroll = (y - this.displayY);
this.currentScroll = this.minScroll + ((this.currentScroll * 2 * this.getRange() / this.height));
this.currentScroll = (this.currentScroll + 1) >> 1;
this.applyRange();
}
}
}
public void wheel(int delta) {
delta = Math.max(Math.min(-delta, 1), -1);
this.currentScroll += delta * this.pageSize;
this.applyRange();
}
}
@@ -1,68 +0,0 @@
package net.p455w0rd.wirelesscraftingterminal.common.container;
import appeng.api.parts.IPart;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public class ContainerOpenContext {
private final boolean isItem;
private World w;
private int x;
private int y;
private int z;
private ForgeDirection side;
public ContainerOpenContext(final Object myItem) {
final boolean isWorld = myItem instanceof IPart || myItem instanceof TileEntity;
this.isItem = !isWorld;
}
public TileEntity getTile() {
if (this.isItem) {
return null;
}
return this.getWorld().getTileEntity(this.getX(), this.getY(), this.getZ());
}
public ForgeDirection getSide() {
return this.side;
}
public void setSide(final ForgeDirection side) {
this.side = side;
}
private int getZ() {
return this.z;
}
public void setZ(final int z) {
this.z = z;
}
private int getY() {
return this.y;
}
public void setY(final int y) {
this.y = y;
}
private int getX() {
return this.x;
}
public void setX(final int x) {
this.x = x;
}
private World getWorld() {
return this.w;
}
public void setWorld(final World w) {
this.w = w;
}
}
@@ -1,17 +0,0 @@
package net.p455w0rd.wirelesscraftingterminal.common.container.guisync;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotates that this field should be synchronized between the server and client.
* Requires the field to be public.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface GuiSync {
int value();
}
@@ -1,140 +0,0 @@
package net.p455w0rd.wirelesscraftingterminal.common.container.guisync;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.EnumSet;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal;
import net.p455w0rd.wirelesscraftingterminal.common.container.WCTBaseContainer;
import net.p455w0rd.wirelesscraftingterminal.common.utils.WCTLog;
import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler;
import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketValueConfig;
public class SyncData {
private final Container source;
private final Field field;
private final int channel;
private Object clientVersion;
public SyncData(final Container container, final Field field, final GuiSync annotation) {
if (container instanceof ContainerWirelessCraftingTerminal) {
this.source = (ContainerWirelessCraftingTerminal) container;
} else if (container instanceof WCTBaseContainer) {
this.source = (WCTBaseContainer) container;
} else {
this.source = container;
}
this.clientVersion = null;
this.field = field;
this.channel = annotation.value();
}
public int getChannel() {
return this.channel;
}
public void tick(final ICrafting c) {
try {
final Object val = this.field.get(this.source);
if (val != null && this.clientVersion == null) {
this.send(c, val);
} else if (!val.equals(this.clientVersion)) {
this.send(c, val);
}
} catch (final IllegalArgumentException e) {
WCTLog.debug(e.getMessage());
} catch (final IllegalAccessException e) {
WCTLog.debug(e.getMessage());
} catch (final IOException e) {
WCTLog.debug(e.getMessage());
}
}
@SuppressWarnings("rawtypes")
private void send(final ICrafting o, final Object val) throws IOException {
if (val instanceof String) {
if (o instanceof EntityPlayerMP) {
NetworkHandler.instance.sendTo(
new PacketValueConfig("SyncDat." + this.channel, (String) val), (EntityPlayerMP) o);
}
} else if (this.field.getType().isEnum()) {
o.sendProgressBarUpdate(this.source, this.channel, ((Enum) val).ordinal());
} else if (val instanceof Long || val.getClass() == long.class) {
// NetworkHandler.instance.sendTo( new PacketProgressBar( this.channel, (Long) val ), (EntityPlayerMP) o );
} else if (val instanceof Boolean || val.getClass() == boolean.class) {
o.sendProgressBarUpdate(this.source, this.channel, ((Boolean) val) ? 1 : 0);
} else {
o.sendProgressBarUpdate(this.source, this.channel, (Integer) val);
}
this.clientVersion = val;
}
public void update(final Object val) {
try {
final Object oldValue = this.field.get(this.source);
if (val instanceof String) {
this.updateString(oldValue, (String) val);
} else {
this.updateValue(oldValue, (Long) val);
}
} catch (final IllegalArgumentException e) {
WCTLog.debug(e.getMessage());
} catch (final IllegalAccessException e) {
WCTLog.debug(e.getMessage());
}
}
private void updateString(final Object oldValue, final String val) {
try {
this.field.set(this.source, val);
} catch (final IllegalArgumentException e) {
WCTLog.debug(e.getMessage());
} catch (final IllegalAccessException e) {
WCTLog.debug(e.getMessage());
}
}
@SuppressWarnings({"unchecked", "rawtypes"})
private void updateValue(final Object oldValue, final long val) {
try {
if (this.field.getType().isEnum()) {
final EnumSet<? extends Enum> valList = EnumSet.allOf((Class<? extends Enum>) this.field.getType());
for (final Enum e : valList) {
if (e.ordinal() == val) {
this.field.set(this.source, e);
break;
}
}
} else {
if (this.field.getType().equals(int.class)) {
this.field.set(this.source, (int) val);
} else if (this.field.getType().equals(long.class)) {
this.field.set(this.source, val);
} else if (this.field.getType().equals(boolean.class)) {
this.field.set(this.source, val == 1);
} else if (this.field.getType().equals(Integer.class)) {
this.field.set(this.source, (int) val);
} else if (this.field.getType().equals(Long.class)) {
this.field.set(this.source, val);
} else if (this.field.getType().equals(Boolean.class)) {
this.field.set(this.source, val == 1);
}
}
if (this.source instanceof ContainerWirelessCraftingTerminal) {
((ContainerWirelessCraftingTerminal) this.source)
.onUpdate(this.field.getName(), oldValue, this.field.get(this.source));
}
if (this.source instanceof WCTBaseContainer) {
((WCTBaseContainer) this.source).onUpdate(this.field.getName(), oldValue, this.field.get(this.source));
}
} catch (final IllegalArgumentException e) {
WCTLog.debug(e.getMessage());
} catch (final IllegalAccessException e) {
WCTLog.debug(e.getMessage());
}
}
}
@@ -1,210 +1,10 @@
package net.p455w0rd.wirelesscraftingterminal.common.container.slot;
import appeng.tile.inventory.AppEngInternalInventory;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal;
import net.p455w0rd.wirelesscraftingterminal.common.container.WCTBaseContainer;
public class AppEngSlot extends Slot {
private final int defX;
private final int defY;
private boolean isDraggable = true;
private boolean isPlayerSide = false;
private Container myContainer = null;
private int IIcon = -1;
private hasCalculatedValidness isValid;
private boolean isDisplay = false;
public class AppEngSlot extends appeng.container.slot.AppEngSlot {
public AppEngSlot(final IInventory inv, final int idx, final int x, final int y) {
super(inv, idx, x, y);
this.defX = x;
this.defY = y;
this.setIsValid(hasCalculatedValidness.NotAvailable);
}
public Slot setNotDraggable() {
this.setDraggable(false);
return this;
}
public Slot setPlayerSide() {
this.isPlayerSide = true;
return this;
}
public String getTooltip() {
return null;
}
public void clearStack() {
super.putStack(null);
}
@Override
public boolean isItemValid(final ItemStack par1ItemStack) {
if (this.isEnabled()) {
return super.isItemValid(par1ItemStack);
}
return false;
}
@Override
public ItemStack getStack() {
if (!this.isEnabled()) {
return null;
}
if (this.inventory.getSizeInventory() <= this.getSlotIndex()) {
return null;
}
if (this.isDisplay()) {
this.setDisplay(false);
return this.getDisplayStack();
}
return super.getStack();
}
@Override
public void putStack(final ItemStack par1ItemStack) {
if (this.isEnabled()) {
super.putStack(par1ItemStack);
if (this.getContainer() != null) {
if (this.getContainer() instanceof ContainerWirelessCraftingTerminal) {
((ContainerWirelessCraftingTerminal) this.getContainer()).onSlotChange(this);
}
if (this.getContainer() instanceof WCTBaseContainer) {
((WCTBaseContainer) this.getContainer()).onSlotChange(this);
}
}
}
}
@Override
public void onSlotChanged() {
if (this.inventory instanceof AppEngInternalInventory) {
((AppEngInternalInventory) this.inventory).markDirty(this.getSlotIndex());
} else {
super.onSlotChanged();
}
this.setIsValid(hasCalculatedValidness.NotAvailable);
}
@Override
public boolean canTakeStack(final EntityPlayer par1EntityPlayer) {
if (this.isEnabled()) {
return super.canTakeStack(par1EntityPlayer);
}
return false;
}
@Override
public boolean func_111238_b() {
return this.isEnabled();
}
public ItemStack getDisplayStack() {
return super.getStack();
}
public boolean isEnabled() {
return true;
}
public float getOpacityOfIcon() {
return 0.4f;
}
public boolean renderIconWithItem() {
return false;
}
public int getIcon() {
return this.getIIcon();
}
public boolean isPlayerSide() {
return this.isPlayerSide;
}
public boolean shouldDisplay() {
return this.isEnabled();
}
public int getX() {
return this.defX;
}
public int getY() {
return this.defY;
}
private int getIIcon() {
return this.IIcon;
}
public void setIIcon(final int iIcon) {
this.IIcon = iIcon;
}
private boolean isDisplay() {
return this.isDisplay;
}
public void setDisplay(final boolean isDisplay) {
this.isDisplay = isDisplay;
}
public boolean isDraggable() {
return this.isDraggable;
}
private void setDraggable(final boolean isDraggable) {
this.isDraggable = isDraggable;
}
void setPlayerSide(final boolean isPlayerSide) {
this.isPlayerSide = isPlayerSide;
}
public hasCalculatedValidness getIsValid() {
return this.isValid;
}
public void setIsValid(final hasCalculatedValidness isValid) {
this.isValid = isValid;
}
Container getContainer() {
if (this.myContainer instanceof ContainerWirelessCraftingTerminal) {
return (ContainerWirelessCraftingTerminal) this.myContainer;
}
if (this.myContainer instanceof WCTBaseContainer) {
return (WCTBaseContainer) this.myContainer;
}
return this.myContainer;
}
public void setContainer(final Container myContainer) {
if (this.myContainer instanceof ContainerWirelessCraftingTerminal) {
this.myContainer = (ContainerWirelessCraftingTerminal) myContainer;
} else if (this.myContainer instanceof WCTBaseContainer) {
this.myContainer = (WCTBaseContainer) myContainer;
} else {
this.myContainer = myContainer;
}
}
public enum hasCalculatedValidness {
NotAvailable,
Valid,
Invalid
}
}
@@ -2,10 +2,9 @@ package net.p455w0rd.wirelesscraftingterminal.common.container.slot;
import net.minecraft.inventory.IInventory;
public class SlotPlayerHotBar extends AppEngSlot {
public class SlotPlayerHotBar extends appeng.container.slot.SlotPlayerHotBar {
public SlotPlayerHotBar(final IInventory par1iInventory, final int par2, final int par3, final int par4) {
super(par1iInventory, par2, par3, par4);
this.setPlayerSide(true);
}
}
@@ -4,11 +4,9 @@ import net.minecraft.inventory.IInventory;
// there is nothing special about this slot, its simply used to represent the players inventory, vs a container slot.
public class SlotPlayerInv extends AppEngSlot {
public class SlotPlayerInv extends appeng.container.slot.SlotPlayerInv {
public SlotPlayerInv(final IInventory par1iInventory, final int par2, final int par3, final int par4) {
super(par1iInventory, par2, par3, par4);
this.setPlayerSide(true);
}
}
@@ -14,9 +14,7 @@ import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketMEInventory
import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketMagnetFilter;
import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketNEIRecipe;
import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketOpenGui;
import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketPartialItem;
import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSetMagnet;
import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSwapSlots;
import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSwitchGuis;
import net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketValueConfig;
@@ -33,12 +31,8 @@ public class WCTPacketHandlerBase {
PACKET_SWITCH_GUIS(PacketSwitchGuis.class),
PACKET_SWAP_SLOTS(PacketSwapSlots.class),
PACKET_RECIPE_NEI(PacketNEIRecipe.class),
PACKET_PARTIAL_ITEM(PacketPartialItem.class),
PACKET_CRAFTING_REQUEST(PacketCraftRequest.class),
PACKET_MAGNETFILTER_MODE(PacketMagnetFilter.class),
@@ -2,6 +2,8 @@ package net.p455w0rd.wirelesscraftingterminal.core.sync.packets;
import appeng.api.storage.data.IAEItemStack;
import appeng.client.ClientHelper;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerOpenContext;
import appeng.container.implementations.ContainerCraftAmount;
import appeng.helpers.InventoryAction;
import appeng.util.Platform;
@@ -13,9 +15,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
import net.p455w0rd.wirelesscraftingterminal.common.WCTGuiHandler;
import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerOpenContext;
import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal;
import net.p455w0rd.wirelesscraftingterminal.common.container.WCTBaseContainer;
import net.p455w0rd.wirelesscraftingterminal.common.utils.RandomUtils;
import net.p455w0rd.wirelesscraftingterminal.core.sync.WCTPacket;
import net.p455w0rd.wirelesscraftingterminal.core.sync.network.INetworkInfo;
@@ -95,15 +95,10 @@ public class PacketInventoryAction extends WCTPacket {
final EntityPlayerMP sender = (EntityPlayerMP) player;
Container baseContainer = sender.openContainer;
ContainerOpenContext context = null;
if (sender.openContainer instanceof ContainerWirelessCraftingTerminal) {
baseContainer = (ContainerWirelessCraftingTerminal) sender.openContainer;
context = ((ContainerWirelessCraftingTerminal) baseContainer).getOpenContext();
if (baseContainer instanceof AEBaseContainer) {
context = ((AEBaseContainer) baseContainer).getOpenContext();
}
if (sender.openContainer instanceof WCTBaseContainer) {
baseContainer = (WCTBaseContainer) sender.openContainer;
context = ((WCTBaseContainer) baseContainer).getOpenContext();
}
if (this.action == InventoryAction.AUTO_CRAFT) {
// if( context != null )
@@ -129,13 +124,13 @@ public class PacketInventoryAction extends WCTPacket {
}
}
if (baseContainer instanceof WCTBaseContainer) {
if (((WCTBaseContainer) baseContainer).getTargetStack() != null) {
if (baseContainer instanceof AEBaseContainer) {
if (((AEBaseContainer) baseContainer).getTargetStack() != null) {
cca.getCraftingItem()
.putStack(((WCTBaseContainer) baseContainer)
.putStack(((AEBaseContainer) baseContainer)
.getTargetStack()
.getItemStack());
cca.setItemToCraft(((WCTBaseContainer) baseContainer).getTargetStack());
cca.setItemToCraft(((AEBaseContainer) baseContainer).getTargetStack());
}
}
@@ -150,8 +145,8 @@ public class PacketInventoryAction extends WCTPacket {
((ContainerWirelessCraftingTerminal) baseContainer)
.doAction(sender, this.action, this.slot, this.id);
}
if (baseContainer instanceof WCTBaseContainer) {
((WCTBaseContainer) baseContainer).doAction(sender, this.action, this.slot, this.id);
if (baseContainer instanceof AEBaseContainer) {
((AEBaseContainer) baseContainer).doAction(sender, this.action, this.slot, this.id);
}
}
}
@@ -39,6 +39,7 @@ import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.oredict.OreDictionary;
import net.p455w0rd.wirelesscraftingterminal.api.IWirelessCraftingTermHandler;
import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal;
import net.p455w0rd.wirelesscraftingterminal.common.utils.RandomUtils;
import net.p455w0rd.wirelesscraftingterminal.core.sync.WCTPacket;
import net.p455w0rd.wirelesscraftingterminal.core.sync.network.INetworkInfo;
@@ -82,19 +83,6 @@ public class PacketNEIRecipe extends WCTPacket {
configureWrite(data);
}
private WirelessTerminalGuiObject getGuiObject(
final ItemStack it, final EntityPlayer player, final World w, final int x, final int y, final int z) {
if (it != null) {
final IWirelessCraftingTermHandler wh = (IWirelessCraftingTermHandler)
AEApi.instance().registries().wireless().getWirelessTerminalHandler(it);
if (wh != null) {
return new WirelessTerminalGuiObject(wh, it, player, w, x, y, z);
}
}
return null;
}
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public void serverPacketData(final INetworkInfo manager, final WCTPacket packet, final EntityPlayer player) {
@@ -106,7 +94,7 @@ public class PacketNEIRecipe extends WCTPacket {
IGridNode node = cct.getNetworkNode();
if (node == null) {
WirelessTerminalGuiObject obj = getGuiObject(
WirelessTerminalGuiObject obj = ContainerWirelessCraftingTerminal.getGuiObject(
RandomUtils.getWirelessTerm(player.inventory),
player,
player.worldObj,
@@ -1,58 +0,0 @@
package net.p455w0rd.wirelesscraftingterminal.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import net.minecraft.entity.player.EntityPlayer;
import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal;
import net.p455w0rd.wirelesscraftingterminal.common.container.WCTBaseContainer;
import net.p455w0rd.wirelesscraftingterminal.core.sync.WCTPacket;
import net.p455w0rd.wirelesscraftingterminal.core.sync.network.INetworkInfo;
public class PacketPartialItem extends WCTPacket {
private final short pageNum;
private final byte[] data;
// automatic.
public PacketPartialItem(final ByteBuf stream) {
this.pageNum = stream.readShort();
stream.readBytes(this.data = new byte[stream.readableBytes()]);
}
// api
public PacketPartialItem(final int page, final int maxPages, final byte[] buf) {
final ByteBuf data = Unpooled.buffer();
this.pageNum = (short) (page | (maxPages << 8));
this.data = buf;
data.writeInt(this.getPacketID());
data.writeShort(this.pageNum);
data.writeBytes(buf);
this.configureWrite(data);
}
@Override
public void serverPacketData(final INetworkInfo manager, final WCTPacket packet, final EntityPlayer player) {
if (player.openContainer instanceof ContainerWirelessCraftingTerminal) {
((ContainerWirelessCraftingTerminal) player.openContainer).postPartial(this);
}
if (player.openContainer instanceof WCTBaseContainer) {
((WCTBaseContainer) player.openContainer).postPartial(this);
}
}
public int getPageCount() {
return this.pageNum >> 8;
}
public int getSize() {
return this.data.length;
}
public int write(final byte[] buffer, final int cursor) {
System.arraycopy(this.data, 0, buffer, cursor, this.data.length);
return cursor + this.data.length;
}
}
@@ -1,58 +0,0 @@
package net.p455w0rd.wirelesscraftingterminal.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal;
import net.p455w0rd.wirelesscraftingterminal.common.container.WCTBaseContainer;
import net.p455w0rd.wirelesscraftingterminal.core.sync.WCTPacket;
import net.p455w0rd.wirelesscraftingterminal.core.sync.network.INetworkInfo;
public class PacketProgressBar extends WCTPacket {
private final short id;
private final long value;
// automatic.
public PacketProgressBar(final ByteBuf stream) {
this.id = stream.readShort();
this.value = stream.readLong();
}
// api
public PacketProgressBar(final int shortID, final long value) {
this.id = (short) shortID;
this.value = value;
final ByteBuf data = Unpooled.buffer();
data.writeInt(this.getPacketID());
data.writeShort(shortID);
data.writeLong(value);
this.configureWrite(data);
}
@Override
public void serverPacketData(final INetworkInfo manager, final WCTPacket packet, final EntityPlayer player) {
final Container c = player.openContainer;
if (c instanceof ContainerWirelessCraftingTerminal) {
((ContainerWirelessCraftingTerminal) c).updateFullProgressBar(this.id, this.value);
}
if (c instanceof WCTBaseContainer) {
((WCTBaseContainer) c).updateFullProgressBar(this.id, this.value);
}
}
@Override
public void clientPacketData(final INetworkInfo network, final WCTPacket packet, final EntityPlayer player) {
final Container c = player.openContainer;
if (c instanceof ContainerWirelessCraftingTerminal) {
((ContainerWirelessCraftingTerminal) c).updateFullProgressBar(this.id, this.value);
}
if (c instanceof WCTBaseContainer) {
((WCTBaseContainer) c).updateFullProgressBar(this.id, this.value);
}
}
}
@@ -1,44 +0,0 @@
package net.p455w0rd.wirelesscraftingterminal.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import net.minecraft.entity.player.EntityPlayer;
import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal;
import net.p455w0rd.wirelesscraftingterminal.common.container.WCTBaseContainer;
import net.p455w0rd.wirelesscraftingterminal.core.sync.WCTPacket;
import net.p455w0rd.wirelesscraftingterminal.core.sync.network.INetworkInfo;
public class PacketSwapSlots extends WCTPacket {
private final int slotA;
private final int slotB;
// automatic.
public PacketSwapSlots(final ByteBuf stream) {
this.slotA = stream.readInt();
this.slotB = stream.readInt();
}
// api
public PacketSwapSlots(final int slotA, final int slotB) {
final ByteBuf data = Unpooled.buffer();
data.writeInt(this.getPacketID());
data.writeInt(this.slotA = slotA);
data.writeInt(this.slotB = slotB);
this.configureWrite(data);
}
@Override
public void serverPacketData(final INetworkInfo manager, final WCTPacket packet, final EntityPlayer player) {
if (player != null) {
if (player.openContainer instanceof ContainerWirelessCraftingTerminal) {
((ContainerWirelessCraftingTerminal) player.openContainer).swapSlotContents(this.slotA, this.slotB);
}
if (player.openContainer instanceof WCTBaseContainer) {
((WCTBaseContainer) player.openContainer).swapSlotContents(this.slotA, this.slotB);
}
}
}
}
@@ -3,6 +3,7 @@ package net.p455w0rd.wirelesscraftingterminal.core.sync.packets;
import appeng.api.config.Settings;
import appeng.api.util.IConfigManager;
import appeng.api.util.IConfigurableObject;
import appeng.container.AEBaseContainer;
import appeng.helpers.IMouseWheelItem;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
@@ -15,7 +16,6 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal;
import net.p455w0rd.wirelesscraftingterminal.common.container.WCTBaseContainer;
import net.p455w0rd.wirelesscraftingterminal.common.utils.RandomUtils;
import net.p455w0rd.wirelesscraftingterminal.core.sync.WCTPacket;
import net.p455w0rd.wirelesscraftingterminal.core.sync.network.INetworkInfo;
@@ -85,19 +85,12 @@ public class PacketValueConfig extends WCTPacket {
final Container c = player.openContainer;
if (this.Name.equals("CustomName")) {
if (c instanceof ContainerWirelessCraftingTerminal) {
((ContainerWirelessCraftingTerminal) c).setCustomName(this.Value);
}
if (c instanceof WCTBaseContainer) {
((WCTBaseContainer) c).setCustomName(this.Value);
if (c instanceof AEBaseContainer) {
((AEBaseContainer) c).setCustomName(this.Value);
}
} else if (this.Name.startsWith("SyncDat.")) {
if (c instanceof ContainerWirelessCraftingTerminal) {
((ContainerWirelessCraftingTerminal) c)
.stringSync(Integer.parseInt(this.Name.substring(8)), this.Value);
}
if (c instanceof WCTBaseContainer) {
((WCTBaseContainer) c).stringSync(Integer.parseInt(this.Name.substring(8)), this.Value);
if (c instanceof AEBaseContainer) {
((AEBaseContainer) c).stringSync(Integer.parseInt(this.Name.substring(8)), this.Value);
}
} else if (c instanceof IConfigurableObject) {
final IConfigManager cm = ((IConfigurableObject) c).getConfigManager();
@@ -6,6 +6,7 @@ import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
import appeng.api.features.ILocatable;
import appeng.api.features.IWirelessTermHandler;
import appeng.api.implementations.guiobjects.IGuiItemObject;
import appeng.api.implementations.guiobjects.IPortableCell;
import appeng.api.implementations.tiles.IWirelessAccessPoint;
import appeng.api.networking.IGrid;
@@ -33,7 +34,7 @@ import net.minecraftforge.common.util.ForgeDirection;
import net.p455w0rd.wirelesscraftingterminal.api.IWirelessCraftingTerminalItem;
import net.p455w0rd.wirelesscraftingterminal.api.networking.security.WCTIActionHost;
public class WirelessTerminalGuiObject implements IActionHost, IPortableCell, IInventorySlotAware, WCTIActionHost {
public class WirelessTerminalGuiObject implements IActionHost, IPortableCell, IInventorySlotAware, WCTIActionHost, IGuiItemObject {
private final ItemStack effectiveItem;
private final IWirelessTermHandler wth;
@@ -477,19 +477,6 @@ public class ItemMagnet extends Item {
return true;
}
public WirelessTerminalGuiObject getGuiObject(
final ItemStack it, final EntityPlayer player, final World w, final int x, final int y, final int z) {
if (it != null) {
final IWirelessCraftingTermHandler wh = (IWirelessCraftingTermHandler)
AEApi.instance().registries().wireless().getWirelessTerminalHandler(it);
if (wh != null) {
return new WirelessTerminalGuiObject(wh, it, player, w, x, y, z);
}
}
return null;
}
public static List<? extends Entity> getEntitiesInRange(
Class<?> entityType, World world, int x, int y, int z, int distance) {
return world.getEntitiesWithinAABB(
@@ -1,6 +1,7 @@
package net.p455w0rd.wirelesscraftingterminal.items;
import appeng.api.config.*;
import appeng.api.features.IWirelessTermHandler;
import appeng.api.util.IConfigManager;
import appeng.items.tools.powered.powersink.AERootPoweredItem;
import appeng.util.ConfigManager;
@@ -32,7 +33,7 @@ import net.p455w0rd.wirelesscraftingterminal.integration.EnderIO;
import net.p455w0rd.wirelesscraftingterminal.reference.Reference;
import org.lwjgl.input.Keyboard;
public class ItemWirelessCraftingTerminal extends AERootPoweredItem implements IWirelessCraftingTerminalItem, IBauble {
public class ItemWirelessCraftingTerminal extends AERootPoweredItem implements IWirelessCraftingTerminalItem, IWirelessTermHandler, IBauble {
public static final String LINK_KEY_STRING = "key";
public static double GLOBAL_POWER_MULTIPLIER = PowerMultiplier.CONFIG.multiplier;
@@ -31,6 +31,7 @@ import net.minecraftforge.event.entity.living.LivingDropsEvent;
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
import net.p455w0rd.wirelesscraftingterminal.api.IWirelessCraftingTerminalItem;
import net.p455w0rd.wirelesscraftingterminal.api.networking.security.WCTPlayerSource;
import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal;
import net.p455w0rd.wirelesscraftingterminal.common.utils.RandomUtils;
import net.p455w0rd.wirelesscraftingterminal.core.sync.WCTPacket;
import net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler;
@@ -225,7 +226,7 @@ public class CommonProxy {
if (magnetStack.getItem() instanceof ItemMagnet) {
ItemMagnet magnet = (ItemMagnet) magnetStack.getItem();
magnet.obj = magnet.getGuiObject(
magnet.obj = ContainerWirelessCraftingTerminal.getGuiObject(
WCTStack, player, world, (int) player.posX, (int) player.posY, (int) player.posZ);
magnet.civ = magnet.obj;
magnet.powerSrc = magnet.civ;