Better BC item integration, javadocs, cleanup

This commit is contained in:
Aidan Brady 2013-07-31 21:20:12 -04:00
parent 0b5d188cd7
commit 4c50c442d1
30 changed files with 122 additions and 92 deletions

View file

@ -98,4 +98,52 @@ public final class ChargeUtils
}
}
}
/**
* Whether or not a defined ItemStack can be discharged for energy in some way.
* @param itemstack - ItemStack to check
* @return if the ItemStack can be discharged
*/
public static boolean canBeDischarged(ItemStack itemstack)
{
return (itemstack.getItem() instanceof IElectricItem && ((IElectricItem)itemstack.getItem()).canProvideEnergy(itemstack)) ||
(itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).discharge(itemstack, 1, false) != 0) ||
(itemstack.getItem() instanceof IChargeableItem && ((IChargeableItem)itemstack.getItem()).transferEnergy(itemstack, 1, false) != 0) ||
itemstack.itemID == Item.redstone.itemID;
}
/**
* Whether or not a defined ItemStack can be charged with energy in some way.
* @param itemstack - ItemStack to check
* @return if the ItemStack can be discharged
*/
public static boolean canBeCharged(ItemStack itemstack)
{
return itemstack.getItem() instanceof IElectricItem ||
(itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).recharge(itemstack, 1, false) != 0) ||
(itemstack.getItem() instanceof IChargeableItem && ((IChargeableItem)itemstack.getItem()).receiveEnergy(itemstack, 1, false) != 0);
}
/**
* Whether or not a defined deemed-electrical ItemStack can be outputted out of a slot.
* This puts into account whether or not that slot is used for charging or discharging.
* @param itemstack - ItemStack to perform the check on
* @param chargeSlot - whether or not the outputting slot is for charging or discharging
* @return if the ItemStack can be outputted
*/
public static boolean canBeOutputted(ItemStack itemstack, boolean chargeSlot)
{
if(chargeSlot)
{
return (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).recharge(itemstack, 1, false) == 0) ||
(itemstack.getItem() instanceof IElectricItem && (!(itemstack.getItem() instanceof IItemElectric) ||
((IItemElectric)itemstack.getItem()).recharge(itemstack, 1, false) == 0));
}
else {
return (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).discharge(itemstack, 1, false) == 0) ||
(itemstack.getItem() instanceof IElectricItem && ((IElectricItem)itemstack.getItem()).canProvideEnergy(itemstack) &&
(!(itemstack.getItem() instanceof IItemElectric) ||
((IItemElectric)itemstack.getItem()).discharge(itemstack, 1, false) == 0));
}
}
}

View file

@ -90,7 +90,7 @@ public class ContainerAdvancedElectricMachine extends Container
}
}
}
else if(MekanismUtils.canBeDischarged(slotStack))
else if(ChargeUtils.canBeDischarged(slotStack))
{
if(slotID != 0 && slotID != 1 && slotID != 2 && slotID != 3)
{

View file

@ -106,7 +106,7 @@ public class ContainerElectricChest extends Container
ItemStack slotStack = currentSlot.getStack();
stack = slotStack.copy();
if(MekanismUtils.canBeDischarged(slotStack))
if(ChargeUtils.canBeDischarged(slotStack))
{
if(slotID != 54)
{

View file

@ -72,7 +72,7 @@ public class ContainerElectricMachine extends Container
return null;
}
}
else if(MekanismUtils.canBeDischarged(slotStack))
else if(ChargeUtils.canBeDischarged(slotStack))
{
if(slotID != 1)
{

View file

@ -65,7 +65,7 @@ public class ContainerElectricPump extends Container
ItemStack slotStack = currentSlot.getStack();
stack = slotStack.copy();
if(MekanismUtils.canBeDischarged(slotStack))
if(ChargeUtils.canBeDischarged(slotStack))
{
if(slotID != 2)
{

View file

@ -86,7 +86,7 @@ public class ContainerEnergyCube extends Container
else {
if(slotID != 1 && slotID != 0)
{
if(MekanismUtils.canBeDischarged(slotStack))
if(ChargeUtils.canBeDischarged(slotStack))
{
if(!mergeItemStack(slotStack, 1, 2, false))
{

View file

@ -140,7 +140,7 @@ public class ContainerFactory extends Container
return null;
}
}
else if(MekanismUtils.canBeDischarged(slotStack))
else if(ChargeUtils.canBeDischarged(slotStack))
{
if(slotID != 1)
{

View file

@ -85,7 +85,7 @@ public class ContainerMetallurgicInfuser extends Container
return null;
}
}
else if(MekanismUtils.canBeDischarged(slotStack))
else if(ChargeUtils.canBeDischarged(slotStack))
{
if(!mergeItemStack(slotStack, 4, 5, false))
{

View file

@ -62,7 +62,7 @@ public class ContainerTeleporter extends Container
ItemStack slotStack = currentSlot.getStack();
stack = slotStack.copy();
if(MekanismUtils.canBeDischarged(slotStack))
if(ChargeUtils.canBeDischarged(slotStack))
{
if(slotID != 0)
{

View file

@ -1,7 +1,6 @@
package mekanism.common;
import ic2.api.Direction;
import ic2.api.item.IElectricItem;
import java.io.BufferedReader;
import java.io.IOException;
@ -25,7 +24,6 @@ import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
@ -42,7 +40,6 @@ import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidBlock;
import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.oredict.ShapedOreRecipe;
import universalelectricity.core.item.IItemElectric;
import cpw.mods.fml.common.network.PacketDispatcher;
import cpw.mods.fml.server.FMLServerHandler;
@ -847,6 +844,13 @@ public final class MekanismUtils
return OreDictionary.getOreName(OreDictionary.getOreID(itemStack));
}
/**
* Retrieves a private value from a defined class and field.
* @param obj - the Object to retrieve the value from, null if static
* @param c - Class to retrieve field value from
* @param field - name of declared field
* @return value as an Object, cast as necessary
*/
public static Object getPrivateValue(Object obj, Class c, String field)
{
try {
@ -858,6 +862,13 @@ public final class MekanismUtils
}
}
/**
* Sets a private value from a defined class and field to a new value.
* @param obj - the Object to perform the operation on, null if static
* @param value - value to set the field to
* @param c - Class the operation will be performed on
* @param field - name of declared field
*/
public static void setPrivateValue(Object obj, Object value, Class c, String field)
{
try {
@ -867,40 +878,22 @@ public final class MekanismUtils
} catch(Exception e) {}
}
/**
* Gets a ResourceLocation with a defined resource type and name.
* @param type - type of resource to retrieve
* @param name - simple name of file to retrieve as a ResourceLocation
* @return the corresponding ResourceLocation
*/
public static ResourceLocation getResource(ResourceType type, String name)
{
return new ResourceLocation("mekanism", type.getPrefix() + name);
}
public static boolean canBeDischarged(ItemStack itemstack)
{
return (itemstack.getItem() instanceof IElectricItem && ((IElectricItem)itemstack.getItem()).canProvideEnergy(itemstack)) ||
(itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).discharge(itemstack, 1, false) != 0) ||
itemstack.itemID == Item.redstone.itemID;
}
public static boolean canBeCharged(ItemStack itemstack)
{
return itemstack.getItem() instanceof IElectricItem ||
(itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).recharge(itemstack, 1, false) != 0);
}
public static boolean canBeOutputted(ItemStack itemstack, boolean chargeSlot)
{
if(chargeSlot)
{
return (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).recharge(itemstack, 1, false) == 0) ||
(itemstack.getItem() instanceof IElectricItem && (!(itemstack.getItem() instanceof IItemElectric) ||
((IItemElectric)itemstack.getItem()).recharge(itemstack, 1, false) == 0));
}
else {
return (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).discharge(itemstack, 1, false) == 0) ||
(itemstack.getItem() instanceof IElectricItem && ((IElectricItem)itemstack.getItem()).canProvideEnergy(itemstack) &&
(!(itemstack.getItem() instanceof IItemElectric) ||
((IItemElectric)itemstack.getItem()).discharge(itemstack, 1, false) == 0));
}
}
/**
* Removes all recipes that are used to create the defined ItemStacks.
* @param itemStacks - ItemStacks to perform the operation on
* @return if any recipes were removed
*/
public static boolean removeRecipes(ItemStack... itemStacks)
{
boolean didRemove = false;

View file

@ -19,7 +19,7 @@ public class SlotEnergy
@Override
public boolean isItemValid(ItemStack itemstack)
{
return MekanismUtils.canBeCharged(itemstack);
return ChargeUtils.canBeCharged(itemstack);
}
}
@ -33,7 +33,7 @@ public class SlotEnergy
@Override
public boolean isItemValid(ItemStack itemstack)
{
return MekanismUtils.canBeDischarged(itemstack);
return ChargeUtils.canBeDischarged(itemstack);
}
}
}

View file

@ -195,7 +195,7 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM
}
else if(slotID == 3)
{
return MekanismUtils.canBeDischarged(itemstack);
return ChargeUtils.canBeDischarged(itemstack);
}
else if(slotID == 1)
{
@ -309,7 +309,7 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM
{
if(slotID == 3)
{
return MekanismUtils.canBeOutputted(itemstack, false);
return ChargeUtils.canBeOutputted(itemstack, false);
}
else if(slotID == 2)
{

View file

@ -126,7 +126,7 @@ public class TileEntityElectricChest extends TileEntityElectricBlock
{
if(slotID == 54)
{
return MekanismUtils.canBeDischarged(itemstack);
return ChargeUtils.canBeDischarged(itemstack);
}
else {
return true;
@ -162,7 +162,7 @@ public class TileEntityElectricChest extends TileEntityElectricBlock
{
if(slotID == 54)
{
return MekanismUtils.canBeOutputted(itemstack, false);
return ChargeUtils.canBeOutputted(itemstack, false);
}
else {
return true;

View file

@ -142,7 +142,7 @@ public abstract class TileEntityElectricMachine extends TileEntityBasicMachine
}
else if(slotID == 1)
{
return MekanismUtils.canBeDischarged(itemstack);
return ChargeUtils.canBeDischarged(itemstack);
}
return true;
@ -201,7 +201,7 @@ public abstract class TileEntityElectricMachine extends TileEntityBasicMachine
{
if(slotID == 1)
{
return MekanismUtils.canBeOutputted(itemstack, false);
return ChargeUtils.canBeOutputted(itemstack, false);
}
else if(slotID == 2)
{

View file

@ -402,7 +402,7 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I
}
else if(slotID == 2)
{
return MekanismUtils.canBeDischarged(itemstack);
return ChargeUtils.canBeDischarged(itemstack);
}
return true;
@ -413,7 +413,7 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I
{
if(slotID == 2)
{
return MekanismUtils.canBeOutputted(itemstack, false);
return ChargeUtils.canBeOutputted(itemstack, false);
}
else if(slotID == 1)
{

View file

@ -123,11 +123,11 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements IEn
{
if(slotID == 0)
{
return MekanismUtils.canBeCharged(itemstack);
return ChargeUtils.canBeCharged(itemstack);
}
else if(slotID == 1)
{
return MekanismUtils.canBeDischarged(itemstack);
return ChargeUtils.canBeDischarged(itemstack);
}
return true;
@ -264,11 +264,11 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements IEn
{
if(slotID == 1)
{
return MekanismUtils.canBeOutputted(itemstack, false);
return ChargeUtils.canBeOutputted(itemstack, false);
}
else if(slotID == 0)
{
return MekanismUtils.canBeOutputted(itemstack, true);
return ChargeUtils.canBeOutputted(itemstack, true);
}
return false;

View file

@ -287,7 +287,7 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IEnerg
{
if(slotID == 1)
{
return MekanismUtils.canBeOutputted(itemstack, false);
return ChargeUtils.canBeOutputted(itemstack, false);
}
else if(tier == FactoryTier.BASIC && slotID >= 7 && slotID <= 9)
{
@ -348,7 +348,7 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IEnerg
}
else if(slotID == 1)
{
return MekanismUtils.canBeDischarged(itemstack);
return ChargeUtils.canBeDischarged(itemstack);
}
return true;

View file

@ -221,7 +221,7 @@ public class TileEntityMetallurgicInfuser extends TileEntityElectricBlock implem
{
if(slotID == 4)
{
return MekanismUtils.canBeOutputted(itemstack, false);
return ChargeUtils.canBeOutputted(itemstack, false);
}
else if(slotID == 3)
{
@ -268,7 +268,7 @@ public class TileEntityMetallurgicInfuser extends TileEntityElectricBlock implem
}
else if(slotID == 4)
{
return MekanismUtils.canBeDischarged(itemstack);
return ChargeUtils.canBeDischarged(itemstack);
}
return true;

View file

@ -105,7 +105,7 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IEn
{
if(slotID == 0)
{
return MekanismUtils.canBeDischarged(itemstack);
return ChargeUtils.canBeDischarged(itemstack);
}
return true;
@ -361,7 +361,7 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IEn
@Override
public boolean canExtractItem(int slotID, ItemStack itemstack, int side)
{
return MekanismUtils.canBeOutputted(itemstack, false);
return ChargeUtils.canBeOutputted(itemstack, false);
}
@Override

View file

@ -1,15 +1,13 @@
package mekanism.generators.common;
import ic2.api.item.IElectricItem;
import mekanism.common.ChargeUtils;
import mekanism.common.Mekanism;
import mekanism.common.MekanismUtils;
import mekanism.common.SlotEnergy.SlotCharge;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import universalelectricity.core.item.IItemElectric;
public class ContainerBioGenerator extends Container
{
@ -64,7 +62,7 @@ public class ContainerBioGenerator extends Container
ItemStack slotStack = currentSlot.getStack();
stack = slotStack.copy();
if(MekanismUtils.canBeCharged(slotStack))
if(ChargeUtils.canBeCharged(slotStack))
{
if(slotID != 1)
{

View file

@ -2,7 +2,7 @@ package mekanism.generators.common;
import mekanism.api.EnumGas;
import mekanism.api.IStorageTank;
import mekanism.common.MekanismUtils;
import mekanism.common.ChargeUtils;
import mekanism.common.SlotEnergy.SlotDischarge;
import mekanism.common.SlotStorageTank;
import net.minecraft.entity.player.EntityPlayer;
@ -105,7 +105,7 @@ public class ContainerElectrolyticSeparator extends Container
}
}
}
else if(MekanismUtils.canBeDischarged(slotStack))
else if(ChargeUtils.canBeDischarged(slotStack))
{
if(!mergeItemStack(slotStack, 3, 4, false))
{

View file

@ -1,14 +1,12 @@
package mekanism.generators.common;
import ic2.api.item.IElectricItem;
import mekanism.common.MekanismUtils;
import mekanism.common.ChargeUtils;
import mekanism.common.SlotEnergy.SlotCharge;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import universalelectricity.core.item.IItemElectric;
public class ContainerHeatGenerator extends Container
{
@ -63,7 +61,7 @@ public class ContainerHeatGenerator extends Container
ItemStack slotStack = currentSlot.getStack();
stack = slotStack.copy();
if(MekanismUtils.canBeCharged(slotStack))
if(ChargeUtils.canBeCharged(slotStack))
{
if(slotID != 1)
{

View file

@ -1,16 +1,14 @@
package mekanism.generators.common;
import ic2.api.item.IElectricItem;
import mekanism.api.EnumGas;
import mekanism.api.IStorageTank;
import mekanism.common.MekanismUtils;
import mekanism.common.ChargeUtils;
import mekanism.common.SlotEnergy.SlotCharge;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import universalelectricity.core.item.IItemElectric;
public class ContainerHydrogenGenerator extends Container
{
@ -65,7 +63,7 @@ public class ContainerHydrogenGenerator extends Container
ItemStack slotStack = currentSlot.getStack();
stack = slotStack.copy();
if(MekanismUtils.canBeCharged(slotStack))
if(ChargeUtils.canBeCharged(slotStack))
{
if(slotID != 1)
{

View file

@ -1,6 +1,6 @@
package mekanism.generators.common;
import mekanism.common.MekanismUtils;
import mekanism.common.ChargeUtils;
import mekanism.common.SlotEnergy.SlotCharge;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
@ -60,7 +60,7 @@ public class ContainerSolarGenerator extends Container
ItemStack slotStack = currentSlot.getStack();
stack = slotStack.copy();
if(MekanismUtils.canBeCharged(slotStack))
if(ChargeUtils.canBeCharged(slotStack))
{
if(slotID != 0)
{

View file

@ -1,14 +1,12 @@
package mekanism.generators.common;
import ic2.api.item.IElectricItem;
import mekanism.common.MekanismUtils;
import mekanism.common.ChargeUtils;
import mekanism.common.SlotEnergy.SlotCharge;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import universalelectricity.core.item.IItemElectric;
public class ContainerWindTurbine extends Container
{
@ -62,7 +60,7 @@ public class ContainerWindTurbine extends Container
ItemStack slotStack = currentSlot.getStack();
stack = slotStack.copy();
if(MekanismUtils.canBeCharged(slotStack))
if(ChargeUtils.canBeCharged(slotStack))
{
if(slotID != 0)
{

View file

@ -1,7 +1,5 @@
package mekanism.generators.common;
import ic2.api.item.IElectricItem;
import java.util.ArrayList;
import mekanism.client.Sound;
@ -18,7 +16,6 @@ import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import universalelectricity.core.item.IItemElectric;
import com.google.common.io.ByteArrayDataInput;
@ -156,7 +153,7 @@ public class TileEntityBioGenerator extends TileEntityGenerator implements IFlui
}
else if(slotID == 1)
{
return MekanismUtils.canBeCharged(itemstack);
return ChargeUtils.canBeCharged(itemstack);
}
return true;

View file

@ -241,7 +241,7 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
{
if(slotID == 3)
{
return MekanismUtils.canBeOutputted(itemstack, false);
return ChargeUtils.canBeOutputted(itemstack, false);
}
else if(slotID == 0)
{
@ -276,7 +276,7 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
}
else if(slotID == 3)
{
return MekanismUtils.canBeDischarged(itemstack);
return ChargeUtils.canBeDischarged(itemstack);
}
return true;

View file

@ -115,7 +115,7 @@ public class TileEntityHeatGenerator extends TileEntityGenerator implements IFlu
}
else if(slotID == 1)
{
return MekanismUtils.canBeCharged(itemstack);
return ChargeUtils.canBeCharged(itemstack);
}
return true;
@ -154,7 +154,7 @@ public class TileEntityHeatGenerator extends TileEntityGenerator implements IFlu
{
if(slotID == 1)
{
return MekanismUtils.canBeOutputted(itemstack, true);
return ChargeUtils.canBeOutputted(itemstack, true);
}
else if(slotID == 0)
{

View file

@ -86,7 +86,7 @@ public class TileEntityHydrogenGenerator extends TileEntityGenerator implements
{
if(slotID == 1)
{
return MekanismUtils.canBeOutputted(itemstack, true);
return ChargeUtils.canBeOutputted(itemstack, true);
}
else if(slotID == 0)
{
@ -105,7 +105,7 @@ public class TileEntityHydrogenGenerator extends TileEntityGenerator implements
}
else if(slotID == 1)
{
return MekanismUtils.canBeCharged(itemstack);
return ChargeUtils.canBeCharged(itemstack);
}
return true;

View file

@ -106,7 +106,7 @@ public class TileEntitySolarGenerator extends TileEntityGenerator
{
if(slotID == 0)
{
return MekanismUtils.canBeOutputted(itemstack, true);
return ChargeUtils.canBeOutputted(itemstack, true);
}
return false;
@ -117,7 +117,7 @@ public class TileEntitySolarGenerator extends TileEntityGenerator
{
if(slotID == 0)
{
return MekanismUtils.canBeCharged(itemstack);
return ChargeUtils.canBeCharged(itemstack);
}
return true;