Merge GuiUtil into Utils

This commit is contained in:
mezz committed 2015-08-14 00:54:27 -07:00
1 parent 844045f75b
commit 689b97d948
17 files changed
+44 -61

No files matched your search

@@ -18,7 +18,7 @@ import forestry.api.apiculture.IBeeHousingInventory;
import forestry.core.interfaces.IAccessHandler;
import forestry.core.inventory.InvTools;
import forestry.core.inventory.InventoryAdapterRestricted;
import forestry.core.utils.GuiUtil;
import forestry.core.utils.Utils;
public class BeeHousingInventory extends InventoryAdapterRestricted implements IBeeHousingInventory {
public static final int SLOT_QUEEN = 0;
@@ -47,7 +47,7 @@ public class BeeHousingInventory extends InventoryAdapterRestricted implements I
if (!super.canExtractItem(slotIndex, itemstack, side)) {
return false;
}
return GuiUtil.isIndexInRange(slotIndex, SLOT_PRODUCT_1, SLOT_PRODUCT_COUNT);
return Utils.isIndexInRange(slotIndex, SLOT_PRODUCT_1, SLOT_PRODUCT_COUNT);
}
@Override
@@ -40,7 +40,7 @@ import forestry.api.core.ForestryAPI;
import forestry.apiculture.trigger.ApicultureTriggers;
import forestry.core.inventory.wrappers.InventoryMapper;
import forestry.core.network.GuiId;
import forestry.core.utils.GuiUtil;
import forestry.core.utils.Utils;
import buildcraft.api.statements.ITriggerExternal;
@@ -138,7 +138,7 @@ public class TileApiary extends TileBeeHousing {
@Override
public boolean canSlotAccept(int slotIndex, ItemStack itemStack) {
if (GuiUtil.isIndexInRange(slotIndex, SLOT_FRAMES_1, SLOT_FRAMES_COUNT)) {
if (Utils.isIndexInRange(slotIndex, SLOT_FRAMES_1, SLOT_FRAMES_COUNT)) {
return itemStack.getItem() instanceof IHiveFrame;
}
@@ -50,7 +50,7 @@ import forestry.core.network.GuiId;
import forestry.core.network.PacketItemStackDisplay;
import forestry.core.proxy.Proxies;
import forestry.core.utils.GeneticsUtil;
import forestry.core.utils.GuiUtil;
import forestry.core.utils.Utils;
public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiquidTankContainer, IItemStackDisplay {
@@ -312,7 +312,7 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui
@Override
public boolean canSlotAccept(int slotIndex, ItemStack itemStack) {
if (GuiUtil.isIndexInRange(slotIndex, SLOT_INPUT_1, SLOT_INPUT_COUNT)) {
if (Utils.isIndexInRange(slotIndex, SLOT_INPUT_1, SLOT_INPUT_COUNT)) {
return AlleleManager.alleleRegistry.isIndividual(itemStack) || GeneticsUtil.getGeneticEquivalent(itemStack) != null;
} else if (slotIndex == SLOT_CAN) {
Fluid fluid = FluidHelper.getFluidInContainer(itemStack);
@@ -324,7 +324,7 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui
@Override
public boolean canExtractItem(int slotIndex, ItemStack stack, int side) {
return GuiUtil.isIndexInRange(slotIndex, SLOT_OUTPUT_1, SLOT_OUTPUT_COUNT);
return Utils.isIndexInRange(slotIndex, SLOT_OUTPUT_1, SLOT_OUTPUT_COUNT);
}
}
}
@@ -33,7 +33,7 @@ import forestry.core.network.PacketTileStream;
import forestry.core.proxy.Proxies;
import forestry.core.utils.EnumTankLevel;
import forestry.core.utils.GeneticsUtil;
import forestry.core.utils.GuiUtil;
import forestry.core.utils.Utils;
public class TileEscritoire extends TileBase implements ISidedInventory, IRenderableMachine, ICrafter {
@@ -188,7 +188,7 @@ public class TileEscritoire extends TileBase implements ISidedInventory, IRender
return true;
}
if (GuiUtil.isIndexInRange(slotIndex, SLOT_INPUT_1, SLOTS_INPUT_COUNT)) {
if (Utils.isIndexInRange(slotIndex, SLOT_INPUT_1, SLOTS_INPUT_COUNT)) {
if (slotIndex >= SLOT_INPUT_1 + tile.game.getSampleSize()) {
return true;
}
@@ -199,7 +199,7 @@ public class TileEscritoire extends TileBase implements ISidedInventory, IRender
@Override
public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) {
return GuiUtil.isIndexInRange(slotIndex, SLOT_RESULTS_1, SLOTS_RESULTS_COUNT);
return Utils.isIndexInRange(slotIndex, SLOT_RESULTS_1, SLOTS_RESULTS_COUNT);
}
@Override
@@ -1,19 +0,0 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.core.utils;
public class GuiUtil {
public static boolean isIndexInRange(int index, int start, int count) {
return (index >= start) && (index < start + count);
}
}
@@ -192,7 +192,7 @@ public class SlotHelper {
}
private static boolean isInPlayerHotbar(int slotIndex) {
return GuiUtil.isIndexInRange(slotIndex, playerInventorySize - playerHotbarSize, playerInventorySize);
return Utils.isIndexInRange(slotIndex, playerInventorySize - playerHotbarSize, playerInventorySize);
}
private static boolean shiftToPlayerInventoryNoHotbar(List inventorySlots, ItemStack stackInSlot) {
+5 -1
View File
@@ -36,7 +36,7 @@ import forestry.core.proxy.Proxies;
import buildcraft.api.tools.IToolWrench;
public class Utils {
public abstract class Utils {
private static final int slabWoodId = OreDictionary.getOreID("slabWood");
private static final Random rand = new Random();
@@ -225,6 +225,10 @@ public class Utils {
}
}
public static boolean isIndexInRange(int index, int start, int count) {
return (index >= start) && (index < start + count);
}
public static int addRGBComponents(int colour, int r, int g, int b) {
r = ((colour & 0xff0000) >> 16) + r;
g = ((colour & 0xff00) >> 8) + g;
@@ -42,7 +42,7 @@ import forestry.core.inventory.InvTools;
import forestry.core.inventory.TileInventoryAdapter;
import forestry.core.inventory.wrappers.InventoryMapper;
import forestry.core.network.GuiId;
import forestry.core.utils.GuiUtil;
import forestry.core.utils.Utils;
import forestry.factory.triggers.FactoryTriggers;
import buildcraft.api.statements.ITriggerExternal;
@@ -366,7 +366,7 @@ public class EngineCopper extends Engine implements ISidedInventory {
@Override
public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) {
return GuiUtil.isIndexInRange(slotIndex, SLOT_WASTE_1, SLOT_WASTE_COUNT);
return Utils.isIndexInRange(slotIndex, SLOT_WASTE_1, SLOT_WASTE_COUNT);
}
}
}
@@ -58,7 +58,6 @@ import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.GuiId;
import forestry.core.proxy.Proxies;
import forestry.core.utils.EnumTankLevel;
import forestry.core.utils.GuiUtil;
import forestry.core.utils.ShapedRecipeCustom;
import forestry.core.utils.StackUtils;
import forestry.core.utils.Utils;
@@ -456,7 +455,7 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL
return false;
}
return GuiUtil.isIndexInRange(slotIndex, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT);
return Utils.isIndexInRange(slotIndex, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT);
}
@Override
@@ -46,8 +46,8 @@ import forestry.core.inventory.IInventoryAdapter;
import forestry.core.inventory.InvTools;
import forestry.core.inventory.TileInventoryAdapter;
import forestry.core.network.GuiId;
import forestry.core.utils.GuiUtil;
import forestry.core.utils.StackUtils;
import forestry.core.utils.Utils;
import forestry.factory.triggers.FactoryTriggers;
import buildcraft.api.statements.ITriggerExternal;
@@ -273,7 +273,7 @@ public class MachineCentrifuge extends TilePowered implements ISidedInventory {
@Override
public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) {
return GuiUtil.isIndexInRange(slotIndex, SLOT_PRODUCT_1, SLOT_PRODUCT_COUNT);
return Utils.isIndexInRange(slotIndex, SLOT_PRODUCT_1, SLOT_PRODUCT_COUNT);
}
}
@@ -49,9 +49,9 @@ import forestry.core.inventory.TileInventoryAdapter;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.GuiId;
import forestry.core.utils.GuiUtil;
import forestry.core.utils.ShapedRecipeCustom;
import forestry.core.utils.StackUtils;
import forestry.core.utils.Utils;
import forestry.factory.recipes.FabricatorRecipe;
public class MachineFabricator extends TilePowered implements ICrafter, ILiquidTankContainer, ISidedInventory {
@@ -426,14 +426,14 @@ public class MachineFabricator extends TilePowered implements ICrafter, ILiquidT
return RecipeManager.findMatchingSmelting(itemStack) != null;
} else if (slotIndex == SLOT_PLAN) {
return RecipeManager.isPlan(itemStack);
} else if (GuiUtil.isIndexInRange(slotIndex, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT)) {
} else if (Utils.isIndexInRange(slotIndex, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT)) {
if (RecipeManager.isPlan(itemStack)) {
return false;
} else if (RecipeManager.findMatchingSmelting(itemStack) != null) {
return false;
}
}
return GuiUtil.isIndexInRange(slotIndex, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT);
return Utils.isIndexInRange(slotIndex, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT);
}
@Override
@@ -49,7 +49,6 @@ import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.GuiId;
import forestry.core.utils.EnumTankLevel;
import forestry.core.utils.GuiUtil;
import forestry.core.utils.StackUtils;
import forestry.core.utils.Utils;
@@ -635,7 +634,7 @@ public class MachineMoistener extends TileBase implements ISidedInventory, ILiqu
return RecipeManager.isResource(itemStack);
}
if (GuiUtil.isIndexInRange(slotIndex, SLOT_STASH_1, SLOT_STASH_COUNT)) {
if (Utils.isIndexInRange(slotIndex, SLOT_STASH_1, SLOT_STASH_COUNT)) {
return FuelManager.moistenerResource.containsKey(itemStack);
}
@@ -653,7 +652,7 @@ public class MachineMoistener extends TileBase implements ISidedInventory, ILiqu
return true;
}
if (GuiUtil.isIndexInRange(slotIndex, SLOT_STASH_1, (SLOT_STASH_COUNT + SLOT_RESERVOIR_COUNT))) {
if (Utils.isIndexInRange(slotIndex, SLOT_STASH_1, (SLOT_STASH_COUNT + SLOT_RESERVOIR_COUNT))) {
return !FuelManager.moistenerResource.containsKey(itemstack);
}
@@ -32,8 +32,8 @@ import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.GuiId;
import forestry.core.proxy.Proxies;
import forestry.core.utils.GuiUtil;
import forestry.core.utils.RecipeUtil;
import forestry.core.utils.Utils;
import forestry.factory.recipes.RecipeMemory;
public class TileWorktable extends TileBase implements ICrafterWorktable {
@@ -242,7 +242,7 @@ public class TileWorktable extends TileBase implements ICrafterWorktable {
@Override
public boolean canSlotAccept(int slotIndex, ItemStack itemStack) {
return GuiUtil.isIndexInRange(slotIndex, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT);
return Utils.isIndexInRange(slotIndex, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT);
}
}
}
@@ -28,8 +28,8 @@ import forestry.core.inventory.InvTools;
import forestry.core.inventory.InventoryAdapterRestricted;
import forestry.core.inventory.wrappers.InventoryMapper;
import forestry.core.proxy.Proxies;
import forestry.core.utils.GuiUtil;
import forestry.core.utils.StackUtils;
import forestry.core.utils.Utils;
import forestry.plugins.PluginFarming;
public class FarmInventory extends InventoryAdapterRestricted implements IFarmInventory {
@@ -66,13 +66,13 @@ public class FarmInventory extends InventoryAdapterRestricted implements IFarmIn
@Override
public boolean canSlotAccept(int slotIndex, ItemStack itemStack) {
if (GuiUtil.isIndexInRange(slotIndex, SLOT_FERTILIZER, SLOT_FERTILIZER_COUNT)) {
if (Utils.isIndexInRange(slotIndex, SLOT_FERTILIZER, SLOT_FERTILIZER_COUNT)) {
return acceptsAsFertilizer(itemStack);
} else if (GuiUtil.isIndexInRange(slotIndex, SLOT_GERMLINGS_1, SLOT_GERMLINGS_COUNT)) {
} else if (Utils.isIndexInRange(slotIndex, SLOT_GERMLINGS_1, SLOT_GERMLINGS_COUNT)) {
return acceptsAsGermling(itemStack);
} else if (GuiUtil.isIndexInRange(slotIndex, SLOT_RESOURCES_1, SLOT_RESOURCES_COUNT)) {
} else if (Utils.isIndexInRange(slotIndex, SLOT_RESOURCES_1, SLOT_RESOURCES_COUNT)) {
return acceptsAsResource(itemStack);
} else if (GuiUtil.isIndexInRange(slotIndex, SLOT_CAN, SLOT_CAN_COUNT)) {
} else if (Utils.isIndexInRange(slotIndex, SLOT_CAN, SLOT_CAN_COUNT)) {
Fluid fluid = FluidHelper.getFluidInContainer(itemStack);
return farmController.getTankManager().accepts(fluid);
}
@@ -81,7 +81,7 @@ public class FarmInventory extends InventoryAdapterRestricted implements IFarmIn
@Override
public boolean canExtractItem(int slotIndex, ItemStack stack, int side) {
return GuiUtil.isIndexInRange(slotIndex, SLOT_PRODUCTION_1, SLOT_PRODUCTION_COUNT);
return Utils.isIndexInRange(slotIndex, SLOT_PRODUCTION_1, SLOT_PRODUCTION_COUNT);
}
@Override
@@ -35,8 +35,8 @@ import forestry.core.config.ForestryItem;
import forestry.core.inventory.IInventoryAdapter;
import forestry.core.inventory.InvTools;
import forestry.core.inventory.InventoryAdapter;
import forestry.core.utils.GuiUtil;
import forestry.core.utils.StackUtils;
import forestry.core.utils.Utils;
import forestry.mail.items.ItemLetter;
public class TradeStation extends WorldSavedData implements ITradeStation, IInventoryAdapter {
@@ -72,12 +72,12 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
@Override
public boolean canExtractItem(int slot, ItemStack itemStack, int side) {
return GuiUtil.isIndexInRange(slot, SLOT_RECEIVE_BUFFER, SLOT_RECEIVE_BUFFER_COUNT);
return Utils.isIndexInRange(slot, SLOT_RECEIVE_BUFFER, SLOT_RECEIVE_BUFFER_COUNT);
}
@Override
public boolean canSlotAccept(int slotIndex, ItemStack itemStack) {
if (GuiUtil.isIndexInRange(slotIndex, SLOT_SEND_BUFFER, SLOT_SEND_BUFFER_COUNT)) {
if (Utils.isIndexInRange(slotIndex, SLOT_SEND_BUFFER, SLOT_SEND_BUFFER_COUNT)) {
for (int i = 0; i < SLOT_TRADEGOOD_COUNT; i++) {
ItemStack tradeGood = getStackInSlot(SLOT_TRADEGOOD + i);
if (StackUtils.isIdenticalItem(tradeGood, itemStack)) {
@@ -85,10 +85,10 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
}
}
return false;
} else if (GuiUtil.isIndexInRange(slotIndex, SLOT_LETTERS_1, SLOT_LETTERS_COUNT)) {
} else if (Utils.isIndexInRange(slotIndex, SLOT_LETTERS_1, SLOT_LETTERS_COUNT)) {
Item item = itemStack.getItem();
return item == Items.paper;
} else if (GuiUtil.isIndexInRange(slotIndex, SLOT_STAMPS_1, SLOT_STAMPS_COUNT)) {
} else if (Utils.isIndexInRange(slotIndex, SLOT_STAMPS_1, SLOT_STAMPS_COUNT)) {
Item item = itemStack.getItem();
return item instanceof IStamps;
}
@@ -18,7 +18,7 @@ import net.minecraft.item.ItemStack;
import forestry.core.gui.ContainerTile;
import forestry.core.gui.slots.SlotOutput;
import forestry.core.proxy.Proxies;
import forestry.core.utils.GuiUtil;
import forestry.core.utils.Utils;
import forestry.mail.POBox;
import forestry.mail.POBoxInfo;
import forestry.mail.gadgets.MachineMailbox;
@@ -52,7 +52,7 @@ public class ContainerMailbox extends ContainerTile<MachineMailbox> {
public ItemStack slotClick(int slotIndex, int button, int par3, EntityPlayer player) {
ItemStack stack = super.slotClick(slotIndex, button, par3, player);
if (GuiUtil.isIndexInRange(slotIndex, SLOT_LETTERS, SLOT_LETTERS_COUNT)) {
if (Utils.isIndexInRange(slotIndex, SLOT_LETTERS, SLOT_LETTERS_COUNT)) {
if (Proxies.common.isSimulating(player.worldObj) && mailInventory != null) {
POBoxInfo info = mailInventory.getPOBoxInfo();
Proxies.net.sendToPlayer(new PacketPOBoxInfo(info), player);
@@ -39,8 +39,8 @@ import forestry.core.items.ItemInventoried;
import forestry.core.network.GuiId;
import forestry.core.proxy.Proxies;
import forestry.core.render.TextureManager;
import forestry.core.utils.GuiUtil;
import forestry.core.utils.StringUtil;
import forestry.core.utils.Utils;
import forestry.mail.Letter;
public class ItemLetter extends ItemInventoried {
@@ -266,10 +266,10 @@ public class ItemLetter extends ItemInventoried {
public boolean canSlotAccept(int slotIndex, ItemStack itemStack) {
if (letter.isProcessed()) {
return false;
} else if (GuiUtil.isIndexInRange(slotIndex, Letter.SLOT_POSTAGE_1, Letter.SLOT_POSTAGE_COUNT)) {
} else if (Utils.isIndexInRange(slotIndex, Letter.SLOT_POSTAGE_1, Letter.SLOT_POSTAGE_COUNT)) {
Item item = itemStack.getItem();
return item instanceof ItemStamps;
} else if (GuiUtil.isIndexInRange(slotIndex, Letter.SLOT_ATTACHMENT_1, Letter.SLOT_ATTACHMENT_COUNT)) {
} else if (Utils.isIndexInRange(slotIndex, Letter.SLOT_ATTACHMENT_1, Letter.SLOT_ATTACHMENT_COUNT)) {
return !ForestryItem.letters.isItemEqual(itemStack);
}
return false;