More null annotations

This commit is contained in:
mezz committed 2017-02-07 00:05:24 -08:00
1 parent da8a833485
commit a5daa93bf1
163 files changed
+952 -849

No files matched your search

@@ -116,8 +116,8 @@ public class WindowFieldKit extends Window {
new ControlPlayerInventory(this);
final IPoint handGlass = new IPoint(16, 32);
this.GlassControl = new ControlImage(this, handGlass.x(), handGlass.y(), new StandardTexture(0, 160, 96, 96, ExtraBeeTexture.GUIPunnett));
new ControlSlot(this, handGlass.x() + 54, handGlass.y() + 26).assign(InventoryType.Window, 0);
new ControlSlot(this, 208, 8).assign(InventoryType.Window, 1);
new ControlSlot.Builder(this, handGlass.x() + 54, handGlass.y() + 26).assign(InventoryType.Window, 0);
new ControlSlot.Builder(this, 208, 8).assign(InventoryType.Window, 1);
(this.text = new ControlText(this, new IPoint(232, 13), "Paper")).setColour(2236962);
(this.text = new ControlText(this, new IArea(0, 120, this.w(), 24), "", TextJustification.MiddleCenter)).setColour(2236962);
this.chromo = new ControlChromosome(this, 150, 24);
@@ -10,6 +10,8 @@ import binnie.craftgui.core.geometry.IArea;
import binnie.craftgui.core.geometry.IPoint;
import binnie.craftgui.minecraft.Window;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
@@ -39,6 +41,13 @@ public class Control extends Widget implements ITooltipHelp, ITooltip {
public void onUpdateClient() {
}
@Nonnull
@Override
public IWidget getParent() {
//noinspection ConstantConditions
return super.getParent();
}
public void addHelp(final String string) {
this.helpStrings.add(string);
}
@@ -76,6 +85,6 @@ public class Control extends Widget implements ITooltipHelp, ITooltip {
}
public Window getWindow() {
return (Window) this.getSuperParent();
return (Window) this.getTopParent();
}
}
@@ -16,7 +16,7 @@ public interface IWidget {
void deleteAllChildren();
ITopLevelWidget getSuperParent();
ITopLevelWidget getTopParent();
boolean isTopLevel();
@@ -150,14 +150,8 @@ public abstract class TopLevelWidget extends Widget implements ITopLevelWidget {
final Deque<IWidget> queue = this.calculateMousedOverWidgets();
while (!queue.isEmpty()) {
final IWidget widget = queue.removeFirst();
if (widget.isEnabled() && widget.isVisible()) {
if (!widget.canMouseOver()) {
continue;
}
if (widget.isEnabled() && widget.isVisible() && widget.canMouseOver() && widget.calculateIsMouseOver()) {
return widget;
}
continue;
if (widget.isEnabled() && widget.isVisible() && widget.canMouseOver() && widget.calculateIsMouseOver()) {
return widget;
}
}
return null;
+15 -13
View File
@@ -9,7 +9,6 @@ import binnie.craftgui.events.EventWidget;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.ConcurrentModificationException;
import java.util.List;
public class Widget implements IWidget {
@@ -80,13 +79,17 @@ public class Widget implements IWidget {
@Override
@Nullable
public final IWidget getParent() {
public IWidget getParent() {
return this.parent;
}
@Override
public final ITopLevelWidget getSuperParent() {
return (ITopLevelWidget) (this.parent == null ? this : this.parent.getSuperParent());
public final ITopLevelWidget getTopParent() {
if (this.parent == null) {
return (ITopLevelWidget) this;
} else {
return this.parent.getTopParent();
}
}
@Override
@@ -237,7 +240,7 @@ public class Widget implements IWidget {
@Override
public final void callEvent(final Event event) {
this.getSuperParent().recieveEvent(event);
this.getTopParent().recieveEvent(event);
}
@Override
@@ -255,7 +258,7 @@ public class Widget implements IWidget {
@Override
public final IPoint getMousePosition() {
return this.getSuperParent().getAbsoluteMousePosition();
return this.getTopParent().getAbsoluteMousePosition();
}
@Override
@@ -297,7 +300,7 @@ public class Widget implements IWidget {
if (!this.isVisible()) {
return;
}
if (this.getSuperParent() == this) {
if (this.getTopParent() == this) {
((ITopLevelWidget) this).updateTopLevel();
}
this.onUpdateClient();
@@ -386,17 +389,17 @@ public class Widget implements IWidget {
@Override
public final boolean isFocused() {
return this.getSuperParent().isFocused(this);
return this.getTopParent().isFocused(this);
}
@Override
public final boolean isDragged() {
return this.getSuperParent().isDragged(this);
return this.getTopParent().isDragged(this);
}
@Override
public final boolean isMouseOver() {
return this.getSuperParent().isMouseOver(this);
return this.getTopParent().isMouseOver(this);
}
@Override
@@ -437,7 +440,7 @@ public class Widget implements IWidget {
@Override
public final void delete() {
this.getSuperParent().widgetDeleted(this);
this.getTopParent().widgetDeleted(this);
this.onDelete();
}
@@ -446,12 +449,11 @@ public class Widget implements IWidget {
}
@Override
@SuppressWarnings("unchecked")
@Nullable
public <T> T getWidget(final Class<T> widgetClass) {
for (final IWidget child : this.getWidgets()) {
if (widgetClass.isInstance(child)) {
return (T) child;
return widgetClass.cast(child);
}
final T found = child.getWidget(widgetClass);
if (found != null) {
@@ -2,6 +2,8 @@ package binnie.craftgui.events;
import binnie.craftgui.core.IWidget;
import javax.annotation.Nullable;
public abstract class EventHandler<E extends Event> {
Class<E> eventClass;
Origin origin;
@@ -16,6 +16,7 @@ import binnie.core.machines.transfer.TransferRequest;
import binnie.core.network.packet.MessageContainerUpdate;
import binnie.craftgui.minecraft.control.ControlSlot;
import binnie.craftgui.minecraft.control.EnumHighlighting;
import com.google.common.base.Preconditions;
import com.google.common.collect.Sets;
import com.mojang.authlib.GameProfile;
import net.minecraft.entity.player.EntityPlayer;
@@ -79,33 +80,6 @@ public class ContainerCraftGUI extends Container {
return this.window.isServer() ? Side.SERVER : Side.CLIENT;
}
@Override
@Nullable
public Slot getSlot(final int index) {
if (index < 0 || index >= this.inventorySlots.size()) {
return null;
}
return this.inventorySlots.get(index);
}
@Override
public void putStackInSlot(final int index, final ItemStack par2ItemStack) {
Slot slot = this.getSlot(index);
if (slot != null) {
slot.putStack(par2ItemStack);
}
}
@Override
public void putStacksInSlots(final ItemStack[] par1ArrayOfItemStack) {
for (int i = 0; i < par1ArrayOfItemStack.length; ++i) {
Slot slot = this.getSlot(i);
if (slot != null) {
slot.putStack(par1ArrayOfItemStack[i]);
}
}
}
@Override
public void onContainerClosed(final EntityPlayer par1EntityPlayer) {
this.crafters.remove(par1EntityPlayer);
@@ -125,7 +99,6 @@ public class ContainerCraftGUI extends Container {
}
}
@Nullable
@Override
public ItemStack slotClick(int slotNum, int dragType, ClickType clickType, EntityPlayer player) {
@@ -134,11 +107,9 @@ public class ContainerCraftGUI extends Container {
((CustomSlot) slot).onSlotClick(this, dragType, clickType, player);
return player.inventory.getItemStack();
}
final ItemStack stack = super.slotClick(slotNum, dragType, clickType, player);
return stack;
return super.slotClick(slotNum, dragType, clickType, player);
}
public void sendNBTToClient(final String key, final NBTTagCompound nbt) {
this.syncedNBT.put(key, nbt);
}
@@ -153,15 +124,14 @@ public class ContainerCraftGUI extends Container {
}
@Override
@Nullable
public final ItemStack transferStackInSlot(final EntityPlayer player, final int slotID) {
return this.shiftClick(player, slotID);
}
@Nullable
private ItemStack shiftClick(final EntityPlayer player, final int slotnumber) {
final TransferRequest request = this.getShiftClickRequest(player, slotnumber);
if (request == null) {
return null;
}
final ItemStack itemstack = request.transfer(true);
final Slot shiftClickedSlot = this.inventorySlots.get(slotnumber);
shiftClickedSlot.putStack(itemstack);
@@ -170,9 +140,6 @@ public class ContainerCraftGUI extends Container {
}
private TransferRequest getShiftClickRequest(final EntityPlayer player, final int slotnumber) {
if (slotnumber < 0) {
return null;
}
final Slot shiftClickedSlot = this.inventorySlots.get(slotnumber);
ItemStack itemstack = null;
if (shiftClickedSlot.getHasStack()) {
@@ -201,12 +168,19 @@ public class ContainerCraftGUI extends Container {
return request;
}
@Nullable
public final ItemStack tankClick(final EntityPlayer player, final int slotID) {
if (player.inventory.getItemStack() == null) {
IInventory inventory = this.window.getInventory();
if (inventory == null) {
return null;
}
ItemStack heldItem = player.inventory.getItemStack().copy();
heldItem = new TransferRequest(heldItem, this.window.getInventory()).setOrigin(player.inventory).setTargetSlots(new int[0]).setTargetTanks(new int[]{slotID}).transfer(true);
ItemStack heldItem = player.inventory.getItemStack();
if (heldItem == null) {
return null;
}
heldItem = heldItem.copy();
TransferRequest transferRequest = new TransferRequest(heldItem, inventory).setOrigin(player.inventory).setTargetSlots(new int[0]).setTargetTanks(new int[]{slotID});
heldItem = transferRequest.transfer(true);
player.inventory.setItemStack(heldItem);
if (player instanceof EntityPlayerMP) {
((EntityPlayerMP) player).updateHeldItem();
@@ -295,18 +269,6 @@ public class ContainerCraftGUI extends Container {
this.syncedNBT.clear();
}
//FIXME hack
/**
* sets whether the player can craft in this inventory or not
*/
@Override
public void setCanCraft(EntityPlayer player, boolean canCraft) {
super.setCanCraft(player, canCraft);
}
//end
private NBTTagCompound createErrorNBT(final IErrorStateSource error) {
final NBTTagCompound nbt = new NBTTagCompound();
ErrorState state = null;
@@ -378,6 +340,7 @@ public class ContainerCraftGUI extends Container {
}
}
@Nullable
public ErrorState getErrorState() {
return this.error;
}
@@ -409,9 +372,6 @@ public class ContainerCraftGUI extends Container {
private void onMouseOverSlot(final EntityPlayer player, final NBTTagCompound data) {
final int slotnumber = data.getShort("slot");
final TransferRequest request = this.getShiftClickRequest(player, slotnumber);
if (request == null) {
return;
}
request.transfer(false);
final NBTTagCompound nbt = new NBTTagCompound();
final List<Integer> slots = new ArrayList<>();
@@ -437,11 +397,14 @@ public class ContainerCraftGUI extends Container {
}
}
private CustomSlot getSlot(final IInventory inventory, final int id) {
for (final Object o : this.inventorySlots) {
final CustomSlot slot = (CustomSlot) o;
if (slot.inventory == inventory && slot.getSlotIndex() == id) {
return slot;
@Nullable
private CustomSlot getSlot(@Nullable final IInventory inventory, final int id) {
if (inventory != null) {
for (final Object o : this.inventorySlots) {
final CustomSlot slot = (CustomSlot) o;
if (slot.inventory == inventory && slot.getSlotIndex() == id) {
return slot;
}
}
}
return null;
@@ -475,18 +438,22 @@ public class ContainerCraftGUI extends Container {
}
protected IInventory getInventory(final InventoryType type) {
if (type == InventoryType.Machine) {
return this.window.getInventory();
switch (type) {
case Machine: {
IInventory inventory = this.window.getInventory();
Preconditions.checkState(inventory != null, "Window has no machine inventory: %s", this.window);
return inventory;
}
case Player:
return this.window.getPlayer().inventory;
case Window:
return this.window.getWindowInventory();
default:
throw new IllegalArgumentException("Unknown type: " + type);
}
if (type == InventoryType.Player) {
return this.window.getPlayer().inventory;
}
if (type == InventoryType.Window) {
return this.window.getWindowInventory();
}
return null;
}
@Nullable
private Slot createServerSlot(final InventoryType type, final int index, final int slotNumber) {
final IInventory inventory = this.getInventory(type);
if (this.inventorySlots.get(slotNumber) != null) {
@@ -3,5 +3,5 @@ package binnie.craftgui.minecraft;
import binnie.core.machines.transfer.TransferRequest;
public interface IWindowAffectsShiftClick {
void alterRequest(final TransferRequest p0);
void alterRequest(final TransferRequest request);
}
@@ -3,6 +3,5 @@ package binnie.craftgui.minecraft;
public enum InventoryType {
Player,
Machine,
Window,
Custom;
Window
}
@@ -1,5 +1,6 @@
package binnie.craftgui.minecraft;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
@@ -96,6 +97,7 @@ class ListMap<T> implements List<T> {
}
@Override
@Nullable
public T get(final int index) {
return this.map.get(index);
}
@@ -112,6 +114,7 @@ class ListMap<T> implements List<T> {
}
@Override
@Nullable
public T remove(final int index) {
return null;
}
@@ -133,16 +136,16 @@ class ListMap<T> implements List<T> {
@Override
public ListIterator<T> listIterator() {
return null;
throw new UnsupportedOperationException();
}
@Override
public ListIterator<T> listIterator(final int index) {
return null;
throw new UnsupportedOperationException();
}
@Override
public List<T> subList(final int fromIndex, final int toIndex) {
return null;
throw new UnsupportedOperationException();
}
}
@@ -32,6 +32,7 @@ import binnie.craftgui.resource.StyleSheetManager;
import binnie.craftgui.resource.Texture;
import binnie.craftgui.resource.minecraft.CraftGUITexture;
import binnie.craftgui.resource.minecraft.StandardTexture;
import com.google.common.base.Preconditions;
import com.mojang.authlib.GameProfile;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
@@ -46,7 +47,7 @@ import java.util.ArrayList;
import java.util.Deque;
public abstract class Window extends TopLevelWidget implements INetwork.RecieveGuiNBT {
@Nullable
@Nullable // client side only
private GuiCraftGUI gui;
private ContainerCraftGUI container;
private WindowInventory windowInventory;
@@ -59,12 +60,54 @@ public abstract class Window extends TopLevelWidget implements INetwork.RecieveG
@Nullable
private StandardTexture bgText2;
private boolean hasBeenInitialised;
@Nullable
private EntityPlayer player;
@Nullable
private IInventory entityInventory;
private Side side;
public Window(final int width, final int height, final EntityPlayer player, @Nullable final IInventory inventory, final Side side) {
this.titleButtonLeft = 8;
this.titleButtonRight = 8;
this.bgText1 = null;
this.bgText2 = null;
this.hasBeenInitialised = false;
this.side = Side.CLIENT;
this.side = side;
this.player = player;
this.entityInventory = inventory;
this.container = new ContainerCraftGUI(this);
this.windowInventory = new WindowInventory(this);
if (side == Side.SERVER) {
return;
}
this.setSize(new IPoint(width, height));
this.gui = new GuiCraftGUI(this);
for (final EnumHighlighting h : EnumHighlighting.values()) {
ControlSlot.highlighting.put(h, new ArrayList<>());
}
CraftGUI.render.setStyleSheet(StyleSheetManager.getDefault());
this.titleButtonLeft = -14;
if (this.showHelpButton()) {
new ControlHelp(this, this.titleButtonLeft += 22, 8);
}
String showInfoButton = this.showInfoButton();
if (showInfoButton != null) {
new ControlInfo(this, this.titleButtonLeft += 22, 8, showInfoButton);
}
this.addSelfEventHandler(new EventWidget.ChangeSize.Handler() {
@Override
public void onEvent(final EventWidget.ChangeSize event) {
if (Window.this.isClient()) {
Window.this.getGui().resize(Window.this.getSize());
if (Window.this.title != null) {
Window.this.title.setSize(new IPoint(Window.this.w(), Window.this.title.h()));
}
}
}
});
}
public void getTooltip(final Tooltip tooltip) {
final Deque<IWidget> queue = this.calculateMousedOverWidgets();
while (!queue.isEmpty()) {
@@ -130,54 +173,13 @@ public abstract class Window extends TopLevelWidget implements INetwork.RecieveG
return null;
}
public Window(final int width, final int height, final EntityPlayer player, @Nullable final IInventory inventory, final Side side) {
this.titleButtonLeft = 8;
this.titleButtonRight = 8;
this.bgText1 = null;
this.bgText2 = null;
this.hasBeenInitialised = false;
this.side = Side.CLIENT;
this.side = side;
this.setInventories(player, inventory);
this.container = new ContainerCraftGUI(this);
this.windowInventory = new WindowInventory(this);
if (side == Side.SERVER) {
return;
}
this.setSize(new IPoint(width, height));
this.gui = new GuiCraftGUI(this);
for (final EnumHighlighting h : EnumHighlighting.values()) {
ControlSlot.highlighting.put(h, new ArrayList<>());
}
CraftGUI.render.setStyleSheet(StyleSheetManager.getDefault());
this.titleButtonLeft = -14;
if (this.showHelpButton()) {
new ControlHelp(this, this.titleButtonLeft += 22, 8);
}
String showInfoButton = this.showInfoButton();
if (showInfoButton != null) {
new ControlInfo(this, this.titleButtonLeft += 22, 8, showInfoButton);
}
this.addSelfEventHandler(new EventWidget.ChangeSize.Handler() {
@Override
public void onEvent(final EventWidget.ChangeSize event) {
if (Window.this.isClient() && Window.this.getGui() != null) {
Window.this.getGui().resize(Window.this.getSize());
if (Window.this.title != null) {
Window.this.title.setSize(new IPoint(Window.this.w(), Window.this.title.h()));
}
}
}
});
}
public void setTitle(final String title) {
(this.title = new ControlTextCentered(this, 12, title)).setColour(4210752);
}
@SideOnly(Side.CLIENT)
@Nullable
public final GuiCraftGUI getGui() {
Preconditions.checkState(this.gui != null, "tried to get gui on server-side, should not be possible");
return this.gui;
}
@@ -239,10 +241,7 @@ public abstract class Window extends TopLevelWidget implements INetwork.RecieveG
@Nullable
public ItemStack getHeldItemStack() {
if (this.player != null) {
return this.player.inventory.getItemStack();
}
return null;
return this.player.inventory.getItemStack();
}
@Nullable
@@ -250,18 +249,11 @@ public abstract class Window extends TopLevelWidget implements INetwork.RecieveG
return this.entityInventory;
}
public void setInventories(final EntityPlayer player2, @Nullable final IInventory inventory) {
this.player = player2;
this.entityInventory = inventory;
}
public void onClose() {
}
public void setHeldItemStack(final ItemStack stack) {
if (this.player != null) {
this.player.inventory.setItemStack(stack);
}
this.player.inventory.setItemStack(stack);
}
public boolean isServer() {
@@ -273,10 +265,7 @@ public abstract class Window extends TopLevelWidget implements INetwork.RecieveG
}
public World getWorld() {
if (this.getPlayer() != null) {
return this.getPlayer().worldObj;
}
return BinnieCore.getBinnieProxy().getWorld();
return this.getPlayer().worldObj;
}
public void onInventoryUpdate() {
@@ -320,6 +309,6 @@ public abstract class Window extends TopLevelWidget implements INetwork.RecieveG
}
public static <T extends Window> T get(final IWidget widget) {
return (T) widget.getSuperParent();
return (T) widget.getTopParent();
}
}
@@ -41,6 +41,7 @@ public class WindowInventory implements IInventory {
}
@Override
@Nullable
public ItemStack getStackInSlot(final int var1) {
if (this.inventory.containsKey(var1)) {
return this.inventory.get(var1);
@@ -49,6 +50,7 @@ public class WindowInventory implements IInventory {
}
@Override
@Nullable
public ItemStack decrStackSize(final int index, int amount) {
if (this.inventory.containsKey(index)) {
final ItemStack item = this.inventory.get(index);
@@ -57,8 +59,7 @@ public class WindowInventory implements IInventory {
if (amount > available) {
amount = available;
}
final ItemStack itemStack = item;
itemStack.stackSize -= amount;
item.stackSize -= amount;
output.stackSize = amount;
if (item.stackSize == 0) {
this.setInventorySlotContents(index, null);
@@ -69,8 +70,8 @@ public class WindowInventory implements IInventory {
}
@Override
public void setInventorySlotContents(final int var1, final ItemStack var2) {
this.inventory.put(var1, var2);
public void setInventorySlotContents(final int index, @Nullable final ItemStack stack) {
this.inventory.put(index, stack);
this.markDirty();
}
@@ -111,11 +112,11 @@ public class WindowInventory implements IInventory {
return !this.disabledAutoDispenses.contains(i);
}
@Nullable
public SlotValidator getValidator(final int i) {
return this.validators.get(i);
}
@Override
public boolean hasCustomName() {
return false;
@@ -136,10 +137,9 @@ public class WindowInventory implements IInventory {
return "window.inventory";
}
//TODO INV
@Override
public void clear() {
this.inventory.clear();
}
@Override
@@ -160,10 +160,9 @@ public class WindowInventory implements IInventory {
@Nullable
@Override
public ItemStack removeStackFromSlot(int index) {
return null;
return this.inventory.remove(index);
}
//TODO end inv
@Override
public ITextComponent getDisplayName() {
return new TextComponentString("Inventory");
@@ -49,7 +49,7 @@ public class ControlItemDisplay extends Control implements ITooltip {
return;
}
final IPoint relativeToWindow = this.getAbsolutePosition().sub(this.getSuperParent().getPosition());
final IPoint relativeToWindow = this.getAbsolutePosition().sub(this.getTopParent().getPosition());
if (relativeToWindow.x() > Window.get(this).getSize().x() + 100 || relativeToWindow.y() > Window.get(this).getSize().y() + 100) {
return;
}
@@ -67,7 +67,7 @@ public class ControlItemDisplay extends Control implements ITooltip {
GlStateManager.enableAlpha();
}
public void setItemStack(final ItemStack itemStack) {
public void setItemStack(@Nullable final ItemStack itemStack) {
this.itemStack = itemStack;
}
@@ -79,7 +79,7 @@ public class ControlItemDisplay extends Control implements ITooltip {
@Override
public void getTooltip(final Tooltip tooltip) {
if (this.hastooltip && this.itemStack != null) {
tooltip.add(this.itemStack.getTooltip(((Window) this.getSuperParent()).getPlayer(), false));
tooltip.add(this.itemStack.getTooltip(((Window) this.getTopParent()).getPlayer(), false));
}
super.getTooltip(tooltip);
}
@@ -78,21 +78,20 @@ public class ControlLiquidTank extends Control implements ITooltip {
public void onRenderBackground(int guiWidth, int guiHeight) {
CraftGUI.render.texture(this.horizontal ? CraftGUITexture.HorizontalLiquidTank : CraftGUITexture.LiquidTank, IPoint.ZERO);
GuiCraftGUI gui = Window.get(this).getGui();
if (gui != null) {
if (this.isMouseOver() && gui.isHelpMode()) {
final int c = -1442840576 + MinecraftTooltip.getOutline(Tooltip.Type.Help);
RenderUtil.drawGradientRect(this.getArea().inset(1), c, c);
} else if (ControlLiquidTank.tankError.contains(this.tankID)) {
final int c = -1442840576 + MinecraftTooltip.getOutline(MinecraftTooltip.Type.Error);
RenderUtil.drawGradientRect(this.getArea().inset(1), c, c);
} else if (this.getSuperParent().getMousedOverWidget() == this) {
if (gui.getDraggedItem() != null) {
RenderUtil.drawGradientRect(this.getArea().inset(1), -1426089575, -1426089575);
} else {
RenderUtil.drawGradientRect(this.getArea().inset(1), -2130706433, -2130706433);
}
if (this.isMouseOver() && gui.isHelpMode()) {
final int c = -1442840576 + MinecraftTooltip.getOutline(Tooltip.Type.Help);
RenderUtil.drawGradientRect(this.getArea().inset(1), c, c);
} else if (ControlLiquidTank.tankError.contains(this.tankID)) {
final int c = -1442840576 + MinecraftTooltip.getOutline(MinecraftTooltip.Type.Error);
RenderUtil.drawGradientRect(this.getArea().inset(1), c, c);
} else if (this.getTopParent().getMousedOverWidget() == this) {
if (gui.getDraggedItem() != null) {
RenderUtil.drawGradientRect(this.getArea().inset(1), -1426089575, -1426089575);
} else {
RenderUtil.drawGradientRect(this.getArea().inset(1), -2130706433, -2130706433);
}
}
if (this.isTankValid()) {
final int height = this.horizontal ? 16 : 58;
final int squaled = Math.round(height * (this.getTank().getAmount() / this.getTank().getCapacity()));
@@ -134,7 +133,7 @@ public class ControlLiquidTank extends Control implements ITooltip {
public void onRenderForeground(int guiWidth, int guiHeight) {
CraftGUI.render.texture(this.horizontal ? CraftGUITexture.HorizontalLiquidTankOverlay : CraftGUITexture.LiquidTankOverlay, IPoint.ZERO);
GuiCraftGUI gui = Window.get(this).getGui();
if (this.isMouseOver() && gui != null && gui.isHelpMode()) {
if (this.isMouseOver() && gui.isHelpMode()) {
final IArea area = this.getArea();
RenderUtil.setColour(MinecraftTooltip.getOutline(Tooltip.Type.Help));
CraftGUI.render.texture(CraftGUITexture.Outline, area.outset(1));
@@ -6,33 +6,33 @@ import binnie.craftgui.minecraft.InventoryType;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
public class ControlPlayerInventory extends Control {
private List<ControlSlot> slots;
private final List<ControlSlot> slots;
public ControlPlayerInventory(final IWidget parent, final boolean wide) {
super(parent, parent.getSize().x() / 2 - (wide ? 110 : 81), parent.getSize().y() - (wide ? 54 : 76) - 12, wide ? 220 : 162, wide ? 54 : 76);
this.slots = new ArrayList<>();
for (int row = 0; row < 3; ++row) {
for (int column = 0; column < 9; ++column) {
final ControlSlot slot = new ControlSlot(this, (wide ? 58 : 0) + column * 18, row * 18);
final ControlSlot slot = new ControlSlot.Builder(this, (wide ? 58 : 0) + column * 18, row * 18).assign(InventoryType.Player, 9 + column + row * 9);
this.slots.add(slot);
}
}
if (wide) {
for (int i1 = 0; i1 < 9; ++i1) {
final ControlSlot slot2 = new ControlSlot(this, i1 % 3 * 18, i1 / 3 * 18);
final ControlSlot slot2 = new ControlSlot.Builder(this, i1 % 3 * 18, i1 / 3 * 18).assign(InventoryType.Player, i1);
this.slots.add(slot2);
}
} else {
for (int i1 = 0; i1 < 9; ++i1) {
final ControlSlot slot2 = new ControlSlot(this, i1 * 18, 58);
final ControlSlot slot2 = new ControlSlot.Builder(this, i1 * 18, 58).assign(InventoryType.Player, i1);
this.slots.add(slot2);
}
}
this.create();
}
public ControlPlayerInventory(final IWidget parent) {
@@ -44,30 +44,13 @@ public class ControlPlayerInventory extends Control {
this.slots = new ArrayList<>();
for (int row = 0; row < 6; ++row) {
for (int column = 0; column < 6; ++column) {
final ControlSlot slot = new ControlSlot(this, column * 18, row * 18);
final ControlSlot slot = new ControlSlot.Builder(this, column * 18, row * 18).assign(InventoryType.Player, 9 + column + row * 9);
this.slots.add(slot);
}
}
this.create();
}
public void create() {
for (int row = 0; row < 3; ++row) {
for (int column = 0; column < 9; ++column) {
final ControlSlot slot = this.slots.get(column + row * 9);
slot.assign(InventoryType.Player, 9 + column + row * 9);
}
}
for (int i1 = 0; i1 < 9; ++i1) {
final ControlSlot slot2 = this.slots.get(27 + i1);
slot2.assign(InventoryType.Player, i1);
}
}
public void addItem(final ItemStack item) {
if (item == null) {
return;
}
public void addItem(@Nullable final ItemStack item) {
for (final ControlSlot slot : this.slots) {
if (!slot.slot.getHasStack()) {
slot.slot.putStack(item);
@@ -77,10 +60,12 @@ public class ControlPlayerInventory extends Control {
public void addInventory(final IInventory inventory) {
for (int i = 0; i < inventory.getSizeInventory(); ++i) {
this.addItem(inventory.getStackInSlot(i));
ItemStack stackInSlot = inventory.getStackInSlot(i);
this.addItem(stackInSlot);
}
}
@Nullable
public ControlSlot getSlot(final int i) {
if (i < 0 || i >= this.slots.size()) {
return null;
@@ -11,6 +11,7 @@ import binnie.craftgui.core.geometry.IPoint;
import binnie.craftgui.core.renderer.RenderUtil;
import binnie.craftgui.events.EventMouse;
import binnie.craftgui.minecraft.CustomSlot;
import binnie.craftgui.minecraft.GuiCraftGUI;
import binnie.craftgui.minecraft.InventoryType;
import binnie.craftgui.minecraft.Window;
import binnie.craftgui.minecraft.WindowInventory;
@@ -25,46 +26,69 @@ import net.minecraft.inventory.ClickType;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
public class ControlSlot extends ControlSlotBase {
public static Map<EnumHighlighting, List<Integer>> highlighting = new HashMap<>();
public static final Map<EnumHighlighting, List<Integer>> highlighting = new EnumMap<>(EnumHighlighting.class);
public static boolean shiftClickActive = false;
public Slot slot;
public ControlSlot(final IWidget parent, final int x, final int y) {
static {
for (final EnumHighlighting h : EnumHighlighting.values()) {
ControlSlot.highlighting.put(h, new ArrayList<>());
}
}
public static class Builder {
private final IWidget parent;
private final int x;
private final int y;
public Builder(final IWidget parent, final int x, final int y) {
this.parent = parent;
this.x = x;
this.y = y;
}
public ControlSlot assign(final int index) {
return assign(InventoryType.Machine, index);
}
public ControlSlot assign(final InventoryType inventory, final int index) {
Slot slot = ((Window) parent.getTopParent()).getContainer().getOrCreateSlot(inventory, index);
return new ControlSlot(parent, x, y, slot);
}
}
public final Slot slot;
public ControlSlot(final IWidget parent, final int x, final int y, final Slot slot) {
super(parent, x, y);
this.slot = null;
this.slot = slot;
this.addSelfEventHandler(new EventMouse.Down.Handler() {
@Override
public void onEvent(final EventMouse.Down event) {
if (ControlSlot.this.slot != null) {
final PlayerControllerMP playerController = ((Window) ControlSlot.this.getSuperParent()).getGui().getMinecraft().playerController;
final int windowId = ((Window) ControlSlot.this.getSuperParent()).getContainer().windowId;
final int slotNumber = ControlSlot.this.slot.slotNumber;
final int button = event.getButton();
Window.get(ControlSlot.this.getWidget()).getGui();
playerController.windowClick(windowId, slotNumber, button, GuiScreen.isShiftKeyDown() ? ClickType.QUICK_MOVE : ClickType.PICKUP, ((Window) ControlSlot.this.getSuperParent()).getGui().getMinecraft().thePlayer);
Window superParent = (Window) ControlSlot.this.getTopParent();
GuiCraftGUI superParentGui = superParent.getGui();
Minecraft minecraft = superParentGui.getMinecraft();
final PlayerControllerMP playerController = minecraft.playerController;
final int windowId = superParent.getContainer().windowId;
final int slotNumber = ControlSlot.this.slot.slotNumber;
final int button = event.getButton();
Window.get(ControlSlot.this.getWidget()).getGui();
if (playerController != null) {
playerController.windowClick(windowId, slotNumber, button, GuiScreen.isShiftKeyDown() ? ClickType.QUICK_MOVE : ClickType.PICKUP, minecraft.thePlayer);
}
}
});
}
public ControlSlot(final IWidget parent, final int x, final int y, final Slot slot) {
super(parent, x, y);
this.slot = null;
this.slot = slot;
}
@Override
public void onRenderBackground(int guiWidth, int guiHeight) {
CraftGUI.render.texture(CraftGUITexture.Slot, IPoint.ZERO);
if (this.slot == null) {
return;
}
final InventorySlot islot = this.getInventorySlot();
if (islot != null) {
SlotValidator validator = islot.getValidator();
@@ -89,8 +113,9 @@ public class ControlSlot extends ControlSlotBase {
final int c = -1442840576 + Math.min(highlight.getKey().getColour(), 16777215);
RenderUtil.drawGradientRect(new IArea(1, 1, 16, 16), c, c);
}
if (!highlighted && this.getSuperParent().getMousedOverWidget() == this) {
if (Window.get(this).getGui().getDraggedItem() != null && !this.slot.isItemValid(Window.get(this).getGui().getDraggedItem())) {
if (!highlighted && this.getTopParent().getMousedOverWidget() == this) {
GuiCraftGUI gui = Window.get(this).getGui();
if (gui.getDraggedItem() != null && !this.slot.isItemValid(gui.getDraggedItem())) {
RenderUtil.drawGradientRect(new IArea(1, 1, 16, 16), -1426089575, -1426089575);
} else {
RenderUtil.drawGradientRect(new IArea(1, 1, 16, 16), -2130706433, -2130706433);
@@ -100,9 +125,6 @@ public class ControlSlot extends ControlSlotBase {
@Override
public void onRenderOverlay() {
if (this.slot == null) {
return;
}
boolean highlighted = false;
for (final Map.Entry<EnumHighlighting, List<Integer>> highlight : ControlSlot.highlighting.entrySet()) {
if (highlight.getKey() == EnumHighlighting.ShiftClick && !ControlSlot.shiftClickActive) {
@@ -126,18 +148,13 @@ public class ControlSlot extends ControlSlotBase {
@Override
public void onUpdateClient() {
super.onUpdateClient();
if (this.slot == null) {
return;
}
if (this.isMouseOver() && GuiScreen.isShiftKeyDown()) {
Window.get(this).getContainer().setMouseOverSlot(this.slot);
ControlSlot.shiftClickActive = true;
}
if (Window.get(this).getGui().isHelpMode() && this.isMouseOver()) {
for (final ControlSlot slot2 : this.getControlSlots()) {
if (slot2.slot != null) {
ControlSlot.highlighting.get(EnumHighlighting.Help).add(slot2.slot.slotNumber);
}
ControlSlot.highlighting.get(EnumHighlighting.Help).add(slot2.slot.slotNumber);
}
}
}
@@ -156,31 +173,13 @@ public class ControlSlot extends ControlSlotBase {
@Override
public ItemStack getItemStack() {
if (this.slot != null) {
return this.slot.getStack();
}
return null;
}
public ControlSlot assign(final int index) {
return this.assign(InventoryType.Machine, index);
}
public ControlSlot assign(final InventoryType inventory, final int index) {
if (this.slot != null) {
return this;
}
this.slot = ((Window) this.getSuperParent()).getContainer().getOrCreateSlot(inventory, index);
return this;
return this.slot.getStack();
}
@Override
public void getHelpTooltip(final Tooltip tooltip) {
if (this.slot == null) {
return;
}
final InventorySlot slot = this.getInventorySlot();
if (this.getInventorySlot() != null) {
if (slot != null) {
tooltip.add(slot.getName());
tooltip.add("Insert Side: " + MachineSide.asString(slot.getInputSides()));
tooltip.add("Extract Side: " + MachineSide.asString(slot.getOutputSides()));
@@ -196,13 +195,13 @@ public class ControlSlot extends ControlSlotBase {
}
}
@Nullable
public InventorySlot getInventorySlot() {
return (this.slot instanceof CustomSlot) ? ((CustomSlot) this.slot).getInventorySlot() : null;
}
static {
for (final EnumHighlighting h : EnumHighlighting.values()) {
ControlSlot.highlighting.put(h, new ArrayList<>());
if (this.slot instanceof CustomSlot) {
CustomSlot customSlot = (CustomSlot) this.slot;
return customSlot.getInventorySlot();
} else {
return null;
}
}
}
@@ -3,6 +3,7 @@ package binnie.craftgui.minecraft.control;
import binnie.craftgui.controls.core.Control;
import binnie.craftgui.core.IWidget;
import binnie.craftgui.minecraft.InventoryType;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import java.util.ArrayList;
@@ -10,24 +11,45 @@ import java.util.Iterator;
import java.util.List;
public class ControlSlotArray extends Control implements Iterable<ControlSlot> {
private int rows;
private int columns;
private List<ControlSlot> slots;
public static class Builder {
private final IWidget parent;
private final int x;
private final int y;
private final int columns;
private final int rows;
public ControlSlotArray(final IWidget parent, final int x, final int y, final int columns, final int rows) {
super(parent, x, y, columns * 18, rows * 18);
this.slots = new ArrayList<>();
this.rows = rows;
this.columns = columns;
for (int row = 0; row < rows; ++row) {
for (int column = 0; column < columns; ++column) {
this.slots.add(this.createSlot(column * 18, row * 18));
public Builder(final IWidget parent, final int x, final int y, final int columns, final int rows) {
this.parent = parent;
this.x = x;
this.y = y;
this.columns = columns;
this.rows = rows;
}
public ControlSlotArray create(final int[] index) {
return this.create(InventoryType.Machine, index);
}
public ControlSlotArray create(final InventoryType type, final int[] index) {
ControlSlotArray controlSlots = new ControlSlotArray(parent, x, y, columns, rows);
int i = 0;
for (int row = 0; row < rows; ++row) {
for (int column = 0; column < columns; ++column) {
ControlSlot.Builder slotBuilder = new ControlSlot.Builder(controlSlots, column * 18, row * 18);
ControlSlot slot = slotBuilder.assign(type, index[i++]);
controlSlots.slots.add(slot);
}
}
return controlSlots;
}
}
public ControlSlot createSlot(final int x, final int y) {
return new ControlSlot(this, x, y);
private List<ControlSlot> slots = new ArrayList<>();
private ControlSlotArray(final IWidget parent, final int x, final int y, final int columns, final int rows) {
super(parent, x, y, columns * 18, rows * 18);
this.slots = new ArrayList<>();
}
public void setItemStacks(final ItemStack[] array) {
@@ -36,30 +58,17 @@ public class ControlSlotArray extends Control implements Iterable<ControlSlot> {
if (i >= this.slots.size()) {
return;
}
this.slots.get(i).slot.putStack(item);
ControlSlot controlSlot = this.slots.get(i);
Slot slot = controlSlot.slot;
slot.putStack(item);
++i;
}
}
public ControlSlot getControlSlot(final int i) {
if (i < 0 || i >= this.slots.size()) {
return null;
}
return this.slots.get(i);
}
public ControlSlotArray create(final int[] index) {
return this.create(InventoryType.Machine, index);
}
public ControlSlotArray create(final InventoryType type, final int[] index) {
int i = 0;
for (final ControlSlot slot : this.slots) {
slot.assign(type, index[i++]);
}
return this;
}
@Override
public Iterator<ControlSlot> iterator() {
return this.slots.iterator();
@@ -14,6 +14,8 @@ import binnie.craftgui.minecraft.Window;
import binnie.craftgui.resource.minecraft.CraftGUITexture;
import net.minecraft.item.ItemStack;
import javax.annotation.Nullable;
public abstract class ControlSlotBase extends Control implements ITooltip {
private ControlItemDisplay itemDisplay;
@@ -43,7 +45,7 @@ public abstract class ControlSlotBase extends Control implements ITooltip {
public void onRenderBackground(int guiWidth, int guiHeight) {
final int size = this.getSize().x();
CraftGUI.render.texture(CraftGUITexture.Slot, this.getArea());
if (this.getSuperParent().getMousedOverWidget() == this) {
if (this.getTopParent().getMousedOverWidget() == this) {
RenderUtil.drawGradientRect(new IArea(new IPoint(1, 1), this.getArea().size().sub(new IPoint(2, 2))), -2130706433, -2130706433);
}
}
@@ -60,8 +62,9 @@ public abstract class ControlSlotBase extends Control implements ITooltip {
if (item == null) {
return;
}
tooltip.add(item.getTooltip(((Window) this.getSuperParent()).getPlayer(), false));
tooltip.add(item.getTooltip(((Window) this.getTopParent()).getPlayer(), false));
}
@Nullable
public abstract ItemStack getItemStack();
}
@@ -6,6 +6,8 @@ import binnie.craftgui.controls.tab.ControlTabBar;
import binnie.craftgui.core.geometry.IPoint;
import net.minecraft.item.ItemStack;
import javax.annotation.Nullable;
public class ControlTabIcon<T> extends ControlTab<T> {
private ControlItemDisplay item;
@@ -15,6 +17,7 @@ public class ControlTabIcon<T> extends ControlTab<T> {
this.item.hastooltip = false;
}
@Nullable
public ItemStack getItemStack() {
if (this.value instanceof IItemStackRepresentitive) {
return ((IItemStackRepresentitive) this.value).getItemStackRepresentitive();
@@ -26,7 +29,8 @@ public class ControlTabIcon<T> extends ControlTab<T> {
public void onUpdateClient() {
super.onUpdateClient();
this.item.setItemStack(this.getItemStack());
final int x = ((ControlTabBar) this.getParent()).getDirection().x();
ControlTabBar parent = (ControlTabBar) this.getParent();
final int x = parent.getDirection().x();
this.item.setOffset(new IPoint((this.isCurrentSelection() || this.isMouseOver()) ? 0 : (-4 * x), 0));
}
@@ -54,7 +54,7 @@ public class ControlDatabaseIndividualDisplay extends ControlItemDisplay impleme
@Override
public void onEvent(final EventMouse.Down event) {
if (event.getButton() == 0 && ControlDatabaseIndividualDisplay.this.species != null && EnumDiscoveryState.Show == ControlDatabaseIndividualDisplay.this.discovered) {
((WindowAbstractDatabase) ControlDatabaseIndividualDisplay.this.getSuperParent()).gotoSpeciesDelayed(ControlDatabaseIndividualDisplay.this.species);
((WindowAbstractDatabase) ControlDatabaseIndividualDisplay.this.getTopParent()).gotoSpeciesDelayed(ControlDatabaseIndividualDisplay.this.species);
}
}
});
@@ -30,7 +30,7 @@ class ControlMutationBox extends ControlListBox<IMutation> {
this.species = species;
this.index = 0;
this.movePercentage(-100.0f);
final BreedingSystem system = ((WindowAbstractDatabase) this.getSuperParent()).getBreedingSystem();
final BreedingSystem system = ((WindowAbstractDatabase) this.getTopParent()).getBreedingSystem();
final List<IMutation> discovered = system.getDiscoveredMutations(Window.get(this).getWorld(), Window.get(this).getUsername());
if (species != null) {
if (this.type == Type.Resultant) {
@@ -21,8 +21,8 @@ class ControlMutationItem extends ControlOption<IMutation> {
this.itemWidget3 = new ControlDatabaseIndividualDisplay(this, 104, 4);
this.addSymbol = new ControlMutationSymbol(this, 24, 4, 0);
this.arrowSymbol = new ControlMutationSymbol(this, 64, 4, 1);
final boolean isNEI = ((WindowAbstractDatabase) this.getSuperParent()).isNEI();
final BreedingSystem system = ((WindowAbstractDatabase) this.getSuperParent()).getBreedingSystem();
final boolean isNEI = ((WindowAbstractDatabase) this.getTopParent()).isNEI();
final BreedingSystem system = ((WindowAbstractDatabase) this.getTopParent()).getBreedingSystem();
if (this.getValue() != null) {
final boolean isMutationDiscovered = system.isMutationDiscovered(this.getValue(), Window.get(this).getWorld(), Window.get(this).getUsername());
IAlleleSpecies allele = null;
@@ -41,8 +41,8 @@ class ControlMutationSymbol extends Control implements ITooltip {
public void setValue(final IMutation value) {
this.value = value;
final boolean isNEI = ((WindowAbstractDatabase) this.getSuperParent()).isNEI();
final BreedingSystem system = ((WindowAbstractDatabase) this.getSuperParent()).getBreedingSystem();
final boolean isNEI = ((WindowAbstractDatabase) this.getTopParent()).isNEI();
final BreedingSystem system = ((WindowAbstractDatabase) this.getTopParent()).getBreedingSystem();
this.discovered = (isNEI || system.isMutationDiscovered(value, Window.get(this).getWorld(), Window.get(this).getUsername()));
if (this.discovered) {
this.setColour(16777215);
@@ -56,7 +56,7 @@ class ControlMutationSymbol extends Control implements ITooltip {
if (this.type == 1 && this.discovered) {
final IAllele species1 = this.value.getAllele0();
final IAllele species2 = this.value.getAllele1();
final BreedingSystem system = ((WindowAbstractDatabase) this.getSuperParent()).getBreedingSystem();
final BreedingSystem system = ((WindowAbstractDatabase) this.getTopParent()).getBreedingSystem();
final float chance = system.getChance(this.value, Window.get(this).getPlayer(), species1, species2);
tooltip.add("Current Chance - " + chance + "%");
if (this.value.getSpecialConditions() != null) {
@@ -24,7 +24,7 @@ public class PageBranchSpecies extends PageBranch {
@Override
public void onEvent(final EventValueChanged event) {
if (event.isOrigin(PageBranchSpecies.this.pageBranchSpecies_speciesList)) {
((WindowAbstractDatabase) PageBranchSpecies.this.getSuperParent()).gotoSpecies((IAlleleSpecies) event.getValue());
((WindowAbstractDatabase) PageBranchSpecies.this.getTopParent()).gotoSpecies((IAlleleSpecies) event.getValue());
}
}
});
@@ -15,6 +15,6 @@ public class PageBreederStats extends Control {
super(parent, 0, 0, w, h);
this.player = player;
final ControlText pageBranchOverview_branchName = new ControlTextCentered(this, 8, TextFormatting.UNDERLINE + Binnie.LANGUAGE.localise("binniecore.gui.database.breeder.stats"));
final BreedingSystem system = ((WindowAbstractDatabase) this.getSuperParent()).getBreedingSystem();
final BreedingSystem system = ((WindowAbstractDatabase) this.getTopParent()).getBreedingSystem();
}
}
@@ -202,7 +202,7 @@ public abstract class WindowAbstractDatabase extends Window {
public void onUpdateClient() {
super.onUpdateClient();
if (this.gotoSpecies != null) {
((WindowAbstractDatabase) this.getSuperParent()).gotoSpecies(this.gotoSpecies);
((WindowAbstractDatabase) this.getTopParent()).gotoSpecies(this.gotoSpecies);
this.gotoSpecies = null;
}
}
@@ -5,7 +5,10 @@ import binnie.craftgui.core.geometry.IArea;
import binnie.craftgui.core.geometry.IBorder;
import binnie.craftgui.core.geometry.Position;
import javax.annotation.Nullable;
public class Texture {
@Nullable
public static final Texture NULL = null;
IArea area;
IBorder padding;