pulled some reusable files from AL
These files can be put to good use in other mods rather than recreating them.
This commit is contained in:
parent
8e41c99ec7
commit
81f581e8a5
8 changed files with 247 additions and 49 deletions
|
@ -8,14 +8,13 @@ public enum PowerSystems
|
|||
|
||||
public String id;
|
||||
|
||||
|
||||
|
||||
private PowerSystems(String id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
//private static boolean[] loaded = new boolean[PowerSystems.values().length];
|
||||
private static boolean init = false;
|
||||
private static Boolean[] loaded;
|
||||
|
||||
/**
|
||||
* Checks to see if something can run powerless based on mods loaded
|
||||
|
@ -27,7 +26,7 @@ public enum PowerSystems
|
|||
{
|
||||
for (int i = 0; i < optional.length; i++)
|
||||
{
|
||||
if (isPowerSystemLoaded(optional[i]))
|
||||
if (isPowerSystemLoaded(optional[i], false))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -38,8 +37,17 @@ public enum PowerSystems
|
|||
/**
|
||||
* Check to see if one of the mods listed in the PowerSystem enum is loaded
|
||||
*/
|
||||
public static boolean isPowerSystemLoaded(PowerSystems power)
|
||||
public static boolean isPowerSystemLoaded(PowerSystems power, boolean force)
|
||||
{
|
||||
return power != null && Loader.isModLoaded(power.id);
|
||||
if (!init || force)
|
||||
{
|
||||
loaded = new Boolean[PowerSystems.values().length];
|
||||
for (int i = 0; i < PowerSystems.values().length; i++)
|
||||
{
|
||||
loaded[i] = Loader.isModLoaded(PowerSystems.values()[i].id);
|
||||
}
|
||||
init = true;
|
||||
}
|
||||
return power != null && loaded[power.ordinal()];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,18 @@
|
|||
package dark.library.helpers;
|
||||
|
||||
|
||||
/**
|
||||
* Used by machines that only rotate to 4 directions
|
||||
*
|
||||
* @author DarkGuardsman *
|
||||
*/
|
||||
public class MetaGroup
|
||||
{
|
||||
/**
|
||||
* Gets minecraft style facing direction base
|
||||
*
|
||||
* @param metaData - block metadata based on 4 meta rotation
|
||||
* @return 2,5,3,4
|
||||
*/
|
||||
public static int getFacingMeta(int metaData)
|
||||
{
|
||||
int meta = metaData % 4;
|
||||
|
@ -25,19 +35,18 @@ public class MetaGroup
|
|||
return newMeta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the block's group
|
||||
*/
|
||||
public static int getGrouping(int meta)
|
||||
{
|
||||
if ((meta >= 0) && (meta <= 3))
|
||||
return 0;
|
||||
if ((meta >= 4) && (meta <= 7))
|
||||
return 1;
|
||||
if ((meta >= 8) && (meta <= 11))
|
||||
return 2;
|
||||
if ((meta >= 12) && (meta <= 15))
|
||||
return 3;
|
||||
return 0;
|
||||
return meta % 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the starting meta of a group
|
||||
* @param grouping - 4 meta group base
|
||||
* @return metadata
|
||||
*/
|
||||
public static int getGroupStartMeta(int grouping)
|
||||
{
|
||||
return grouping * 4;
|
||||
|
|
41
src/minecraft/dark/library/helpers/Pair.java
Normal file
41
src/minecraft/dark/library/helpers/Pair.java
Normal file
|
@ -0,0 +1,41 @@
|
|||
package dark.library.helpers;
|
||||
|
||||
public class Pair<L, R>
|
||||
{
|
||||
private final L left;
|
||||
private final R right;
|
||||
|
||||
public Pair(L left, R right)
|
||||
{
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
public L getKey()
|
||||
{
|
||||
return left;
|
||||
}
|
||||
|
||||
public R getValue()
|
||||
{
|
||||
return right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return left.hashCode() ^ right.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (o == null)
|
||||
return false;
|
||||
if (!(o instanceof Pair))
|
||||
return false;
|
||||
Pair pairo = (Pair) o;
|
||||
return this.left.equals(pairo.getKey()) && this.right.equals(pairo.getValue());
|
||||
}
|
||||
|
||||
}
|
18
src/minecraft/dark/library/inv/ISlotPickResult.java
Normal file
18
src/minecraft/dark/library/inv/ISlotPickResult.java
Normal file
|
@ -0,0 +1,18 @@
|
|||
package dark.library.inv;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
/**
|
||||
* TileEntities that wish to do something if an item is removed from a slot
|
||||
*/
|
||||
public interface ISlotPickResult
|
||||
{
|
||||
/**
|
||||
* If the slot in the gui does something if the item is removed
|
||||
*
|
||||
* @param entityPlayer - player who removed the item, will pass null from automation
|
||||
* @param slot - slot in the container class the item came from
|
||||
* @param itemStack - item stack pulled from the slot
|
||||
*/
|
||||
public void onPickUpFromSlot(EntityPlayer entityPlayer, int slot, ItemStack itemStack);
|
||||
}
|
12
src/minecraft/dark/library/inv/ISlotWatcher.java
Normal file
12
src/minecraft/dark/library/inv/ISlotWatcher.java
Normal file
|
@ -0,0 +1,12 @@
|
|||
package dark.library.inv;
|
||||
|
||||
/**
|
||||
* Add this to a container class if using WatchedSlot to trigger the container on slot change
|
||||
*/
|
||||
public interface ISlotWatcher
|
||||
{
|
||||
/**
|
||||
* Will trigger if the watched slot has changed
|
||||
*/
|
||||
public void slotContentsChanged(int slot);
|
||||
}
|
43
src/minecraft/dark/library/inv/SlotCraftingResult.java
Normal file
43
src/minecraft/dark/library/inv/SlotCraftingResult.java
Normal file
|
@ -0,0 +1,43 @@
|
|||
package dark.library.inv;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Easy class to create a slot that is used for an event trigger or crafting based event
|
||||
*
|
||||
*/
|
||||
public class SlotCraftingResult extends WatchedSlot
|
||||
{
|
||||
private ISlotPickResult tile;
|
||||
|
||||
public SlotCraftingResult(ISlotPickResult tile, ISlotWatcher container, IInventory inventory, int par2, int par3, int par4)
|
||||
{
|
||||
super(inventory, par2, par3, par4, container);
|
||||
this.tile = tile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack itemStack)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeStack(EntityPlayer player)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* When the slot has changed it calls @ISlotPickResult 's method
|
||||
*/
|
||||
@Override
|
||||
public void onPickupFromSlot(EntityPlayer entityPlayer, ItemStack itemStack)
|
||||
{
|
||||
this.tile.onPickUpFromSlot(entityPlayer, this.slotNumber, itemStack);
|
||||
super.onPickupFromSlot(entityPlayer, itemStack);
|
||||
}
|
||||
}
|
39
src/minecraft/dark/library/inv/SlotRestricted.java
Normal file
39
src/minecraft/dark/library/inv/SlotRestricted.java
Normal file
|
@ -0,0 +1,39 @@
|
|||
package dark.library.inv;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Slot that can only allow one itemStack into it
|
||||
*
|
||||
* @author DarkGuardsman
|
||||
*
|
||||
*/
|
||||
public class SlotRestricted extends Slot
|
||||
{
|
||||
private ItemStack[] itemStacks;
|
||||
|
||||
public SlotRestricted(IInventory par1iInventory, int par2, int par3, int par4, ItemStack... itemStacks)
|
||||
{
|
||||
super(par1iInventory, par2, par3, par4);
|
||||
this.itemStacks = itemStacks;
|
||||
}
|
||||
|
||||
public boolean isItemValid(ItemStack itemStack)
|
||||
{
|
||||
if (itemStack != null && this.itemStacks != null)
|
||||
{
|
||||
for (int i = 0; i < itemStacks.length; i++)
|
||||
{
|
||||
ItemStack stack = itemStacks[i];
|
||||
if (stack != null && itemStack.isItemEqual(stack))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
28
src/minecraft/dark/library/inv/WatchedSlot.java
Normal file
28
src/minecraft/dark/library/inv/WatchedSlot.java
Normal file
|
@ -0,0 +1,28 @@
|
|||
package dark.library.inv;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
|
||||
/**
|
||||
* A slot that triggers the container class if changed
|
||||
*/
|
||||
public class WatchedSlot extends Slot
|
||||
{
|
||||
private ISlotWatcher slotWatcher;
|
||||
|
||||
public WatchedSlot(IInventory inventory, int id, int xPosition, int yPosition, ISlotWatcher slotWatcher)
|
||||
{
|
||||
super(inventory, id, xPosition, yPosition);
|
||||
this.slotWatcher = slotWatcher;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlotChanged()
|
||||
{
|
||||
if (this.slotWatcher != null)
|
||||
{
|
||||
this.slotWatcher.slotContentsChanged(this.slotNumber);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue