Updated ImmersiveEngineering to 0.10+ with Maven

Updated OpenComputers to 1.6.0+ with Maven
This commit is contained in:
LemADEC 2016-12-03 13:32:48 +01:00
parent 8a96069a0c
commit ab23f7673c
69 changed files with 31 additions and 6974 deletions

View file

@ -49,6 +49,29 @@ minecraft {
replaceIn "MyDummyModContainer.java"
}
repositories {
maven { // JEI & Tinkers
name 'DVS1 Maven FS'
url 'http://dvs1.progwml6.com/files/maven'
}
maven { // WAILA
name "ProfMobius Maven FS"
url "http://mobiusstrip.eu/maven"
}
maven { // OpenComputers
name "OpenComputers"
url "http://maven.cil.li/"
}
maven { // TOP
name 'tterrag maven'
url "http://maven.tterrag.com/"
}
maven { // CraftTweaker (aka MineTweaker3), Immersive Engineering
name 'jared maven'
url "http://blamejared.com/maven"
}
}
dependencies {
// you may put jars on which you depend on in ./libs
// or you may define them like so..
@ -63,6 +86,14 @@ dependencies {
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html
deobfCompile "blusunrize:ImmersiveEngineering:0.10-+:deobf"
// deobfCompile "mezz.jei:jei_1.10.2:3.13.+"
// deobfCompile "mcp.mobius.waila:Waila:1.7.0-B3_1.9.4"
// deobfCompile "slimeknights.mantle:Mantle:1.10.2-1.+"
// deobfCompile "slimeknights:TConstruct:1.10.2-2.5.6.+"
deobfCompile "li.cil.oc:OpenComputers:MC1.10.2-1.6.0.+"
// deobfCompile "mcjty.theoneprobe:TheOneProbe:1.10-1.0.13-26"
// deobfCompile "MineTweaker3:MineTweaker3-API:3.0.14.59"
}
processResources {

View file

@ -1,40 +0,0 @@
package blusunrize.immersiveengineering.api;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.Vec3d;
/**
* @author BluSunrize - 24.09.2015
*
* Just an AABB with additional info, for use with pipes
*/
public class AdvancedAABB extends AxisAlignedBB
{
public EnumFacing fd;
public Vec3d[][] drawOverride;
public AdvancedAABB(double xMin, double yMin, double zMin, double xMax, double yMax, double zMax, EnumFacing fd, Vec3d[]... drawOverride)
{
super(xMin, yMin, zMin, xMax, yMax, zMax);
this.fd = fd;
this.drawOverride = drawOverride;
}
public AdvancedAABB(double xMin, double yMin, double zMin, double xMax, double yMax, double zMax, EnumFacing fd)
{
this(xMin, yMin, zMin, xMax, yMax, zMax, fd, new Vec3d[0][]);
}
public AdvancedAABB(double xMin, double yMin, double zMin, double xMax, double yMax, double zMax, Vec3d[]... drawOverride)
{
this(xMin, yMin, zMin, xMax, yMax, zMax, null, drawOverride);
}
public AdvancedAABB(double xMin, double yMin, double zMin, double xMax, double yMax, double zMax)
{
this(xMin, yMin, zMin, xMax, yMax, zMax, null, new Vec3d[0][]);
}
public AdvancedAABB(AxisAlignedBB aabb, EnumFacing fd)
{
this(aabb.minX, aabb.minY, aabb.minZ, aabb.maxX, aabb.maxY, aabb.maxZ, fd, new Vec3d[0][]);
}
}

View file

@ -1,447 +0,0 @@
package blusunrize.immersiveengineering.api;
import blusunrize.immersiveengineering.api.crafting.IngredientStack;
import blusunrize.immersiveengineering.api.energy.wires.IICProxy;
import blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable;
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler;
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection;
import blusunrize.immersiveengineering.api.energy.wires.WireType;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagInt;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.oredict.OreDictionary;
import java.util.*;
import static blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection.vertices;
public class ApiUtils
{
public static boolean compareToOreName(ItemStack stack, String oreName)
{
if(!isExistingOreName(oreName))
return false;
ItemStack comp = copyStackWithAmount(stack, 1);
List<ItemStack> s = OreDictionary.getOres(oreName);
for(ItemStack st:s)
if(OreDictionary.itemMatches(st, stack, false))
return true;
return false;
}
public static boolean stackMatchesObject(ItemStack stack, Object o)
{
if(o instanceof ItemStack)
return OreDictionary.itemMatches((ItemStack)o, stack, false);
else if(o instanceof List)
{
for(Object io : (List)o)
if(io instanceof ItemStack && OreDictionary.itemMatches((ItemStack)io, stack, false))
return true;
}
else if(o instanceof String)
return compareToOreName(stack, (String)o);
return false;
}
public static ItemStack copyStackWithAmount(ItemStack stack, int amount)
{
if(stack==null)
return null;
ItemStack s2 = stack.copy();
s2.stackSize=amount;
return s2;
}
public static boolean stacksMatchIngredientList(List<IngredientStack> list, ItemStack... stacks)
{
ArrayList<ItemStack> queryList = new ArrayList<ItemStack>(stacks.length);
for(ItemStack s : stacks)
if(s!=null)
queryList.add(s.copy());
for(IngredientStack ingr : list)
if(ingr!=null)
{
int amount = ingr.inputSize;
Iterator<ItemStack> it = queryList.iterator();
while(it.hasNext())
{
ItemStack query = it.next();
if(query!=null)
{
if(ingr.matchesItemStackIgnoringSize(query))
{
if(query.stackSize > amount)
{
query.stackSize-=amount;
amount=0;
}
else
{
amount-=query.stackSize;
query.stackSize=0;
}
}
if(query.stackSize<=0)
it.remove();
if(amount<=0)
break;
}
}
if(amount>0)
return false;
}
return true;
}
public static ComparableItemStack createComparableItemStack(ItemStack stack)
{
ComparableItemStack comp = new ComparableItemStack(stack);
if(stack.hasTagCompound())
comp.setUseNBT(true);
return comp;
}
public static boolean isExistingOreName(String name)
{
if(!OreDictionary.doesOreNameExist(name))
return false;
else
return !OreDictionary.getOres(name).isEmpty();
}
public static boolean isMetalComponent(ItemStack stack, String componentType)
{
return getMetalComponentType(stack, componentType)!=null;
}
public static String getMetalComponentType(ItemStack stack, String... componentTypes)
{
ItemStack comp = copyStackWithAmount(stack, 1);
for(String oreName : OreDictionary.getOreNames())//This is super ugly, but I don't want to force the latest forge ._.
for(int iType=0; iType<componentTypes.length; iType++)
if(oreName.startsWith(componentTypes[iType]))
{
List<ItemStack> s = OreDictionary.getOres(oreName);
for(ItemStack st : s)
if(ItemStack.areItemStacksEqual(comp, st))
return componentTypes[iType];
}
return null;
}
public static String[] getMetalComponentTypeAndMetal(ItemStack stack, String... componentTypes)
{
ItemStack comp = copyStackWithAmount(stack, 1);
for(String oreName : OreDictionary.getOreNames())//This is super ugly, but I don't want to force the latest forge ._.
for(int iType=0; iType<componentTypes.length; iType++)
if(oreName.startsWith(componentTypes[iType]))
{
List<ItemStack> s = OreDictionary.getOres(oreName);
for(ItemStack st : s)
if(ItemStack.areItemStacksEqual(comp, st))
return new String[]{componentTypes[iType], oreName.substring(componentTypes[iType].length())};
}
return null;
}
public static boolean isIngot(ItemStack stack)
{
return isMetalComponent(stack, "ingot");
}
public static boolean isPlate(ItemStack stack)
{
return isMetalComponent(stack, "plate");
}
public static int getComponentIngotWorth(ItemStack stack)
{
String[] keys = IEApi.prefixToIngotMap.keySet().toArray(new String[IEApi.prefixToIngotMap.size()]);
String key = getMetalComponentType(stack, keys);
if(key!=null)
{
Integer[] relation = IEApi.prefixToIngotMap.get(key);
if(relation!=null && relation.length>1)
{
double val = relation[0]/(double)relation[1];
return (int)val;
}
}
return 0;
}
public static ItemStack breakStackIntoIngots(ItemStack stack)
{
String[] keys = IEApi.prefixToIngotMap.keySet().toArray(new String[IEApi.prefixToIngotMap.size()]);
String[] type = getMetalComponentTypeAndMetal(stack, keys);
if(type!=null)
{
Integer[] relation = IEApi.prefixToIngotMap.get(type[0]);
if(relation!=null && relation.length>1)
{
double val = relation[0]/(double)relation[1];
return copyStackWithAmount(IEApi.getPreferredOreStack("ingot"+type[1]), (int)val);
}
}
return null;
}
public static Object[] breakStackIntoPreciseIngots(ItemStack stack)
{
String[] keys = IEApi.prefixToIngotMap.keySet().toArray(new String[IEApi.prefixToIngotMap.size()]);
String[] type = getMetalComponentTypeAndMetal(stack, keys);
if(type!=null)
{
Integer[] relation = IEApi.prefixToIngotMap.get(type[0]);
if(relation!=null && relation.length>1)
{
double val = relation[0]/(double)relation[1];
return new Object[]{IEApi.getPreferredOreStack("ingot"+type[1]),val};
}
}
return null;
}
public static BlockPos toBlockPos(Object object)
{
if(object instanceof BlockPos)
return (BlockPos)object;
if(object instanceof TileEntity)
return ((TileEntity)object).getPos();
if (object instanceof IICProxy)
return ((IICProxy) object).getPos();
return null;
}
public static IImmersiveConnectable toIIC(Object object, World world)
{
return toIIC(object, world, true);
}
public static IImmersiveConnectable toIIC(Object object, World world, boolean allowProxies)
{
if(object instanceof IImmersiveConnectable)
return (IImmersiveConnectable)object;
else if(object instanceof BlockPos)
{
if (world!=null && world.isBlockLoaded((BlockPos)object))
{
TileEntity te = world.getTileEntity((BlockPos)object);
if(te instanceof IImmersiveConnectable)
return (IImmersiveConnectable) te;
}
if (allowProxies)
{
DimensionBlockPos pos = new DimensionBlockPos((BlockPos)object, world);
if (ImmersiveNetHandler.INSTANCE.proxies.containsKey(pos))
return ImmersiveNetHandler.INSTANCE.proxies.get(pos);
}
}
return null;
}
public static Vec3d addVectors(Vec3d vec0, Vec3d vec1)
{
return vec0.addVector(vec1.xCoord,vec1.yCoord,vec1.zCoord);
}
public static Vec3d[] getConnectionCatenary(Connection connection, Vec3d start, Vec3d end)
{
boolean vertical = connection.end.getX()==connection.start.getX() && connection.end.getZ()==connection.start.getZ();
if(vertical)
return new Vec3d[]{new Vec3d(start.xCoord, start.yCoord, start.zCoord), new Vec3d(end.xCoord, end.yCoord, end.zCoord)};
double dx = (end.xCoord)-(start.xCoord);
double dy = (end.yCoord)-(start.yCoord);
double dz = (end.zCoord)-(start.zCoord);
double dw = Math.sqrt(dx*dx + dz*dz);
double k = Math.sqrt(dx*dx + dy*dy + dz*dz) * connection.cableType.getSlack();
double l = 0;
int limiter = 0;
while(!vertical && limiter<300)
{
limiter++;
l += 0.01;
if (Math.sinh(l)/l >= Math.sqrt(k*k - dy*dy)/dw)
break;
}
double a = dw/2/l;
double p = (0+dw-a*Math.log((k+dy)/(k-dy)))*0.5;
double q = (dy+0-k*Math.cosh(l)/Math.sinh(l))*0.5;
Vec3d[] vex = new Vec3d[vertices];
vex[0] = new Vec3d(start.xCoord, start.yCoord, start.zCoord);
for(int i=1; i<vertices; i++)
{
float n1 = i/(float)vertices;
double x1 = 0 + dx * n1;
double z1 = 0 + dz * n1;
double y1 = a * Math.cosh((( Math.sqrt(x1*x1+z1*z1) )-p)/a)+q;
vex[i] = new Vec3d(start.xCoord+x1, start.yCoord+y1, start.zCoord+z1);
}
vex[vertices-1] = new Vec3d(end.xCoord, end.yCoord, end.zCoord);
return vex;
}
public static WireType getWireTypeFromNBT(NBTTagCompound tag, String key)
{
//Legacy code for old save data, where types used to be integers
if(tag.getTag(key) instanceof NBTTagInt)
{
int i = tag.getInteger(key);
return i==1?WireType.ELECTRUM: i==2?WireType.STEEL: i==3?WireType.STRUCTURE_ROPE: i==4?WireType.STRUCTURE_STEEL: WireType.COPPER;
}
else
return WireType.getValue(tag.getString(key));
}
public static Object convertToValidRecipeInput(Object input)
{
if(input instanceof ItemStack)
return input;
else if(input instanceof Item)
return new ItemStack((Item)input);
else if(input instanceof Block)
return new ItemStack((Block)input);
else if(input instanceof List)
return input;
else if(input instanceof String)
{
if(!ApiUtils.isExistingOreName((String)input))
return null;
List<ItemStack> l = OreDictionary.getOres((String)input);
if(!l.isEmpty())
return l;
else
return null;
}
else
throw new RuntimeException("Recipe Inputs must always be ItemStack, Item, Block or String (OreDictionary name), "+input+" is invalid");
}
public static IngredientStack createIngredientStack(Object input, boolean preferWildcard)
{
if(input instanceof ItemStack)
return new IngredientStack((ItemStack)input);
else if(input instanceof Item)
{
if(preferWildcard)
return new IngredientStack(new ItemStack((Item)input,1,OreDictionary.WILDCARD_VALUE));
return new IngredientStack(new ItemStack((Item)input));
}
else if(input instanceof Block)
{
if(preferWildcard)
return new IngredientStack(new ItemStack((Block)input,1,OreDictionary.WILDCARD_VALUE));
return new IngredientStack(new ItemStack((Block)input));
}
else if(input instanceof List && ((List)input).isEmpty() && ((List)input).get(0) instanceof ItemStack)
return new IngredientStack(((List<ItemStack>)input));
else if(input instanceof String)
return new IngredientStack((String)input);
else if(input instanceof FluidStack)
return new IngredientStack((FluidStack)input);
throw new RuntimeException("Recipe Ingredients must always be ItemStack, Item, Block, List<ItemStack>, String (OreDictionary name) or FluidStack; "+input+" is invalid");
}
public static IngredientStack createIngredientStack(Object input)
{
return createIngredientStack(input, false);
}
public static ItemStack getItemStackFromObject(Object o)
{
if(o instanceof ItemStack)
return (ItemStack)o;
else if(o instanceof Item)
return new ItemStack((Item)o);
else if(o instanceof Block)
return new ItemStack((Block)o);
else if(o instanceof List)
return ((List<ItemStack>)o).get(0);
else if(o instanceof String)
{
if(!isExistingOreName((String)o))
return null;
List<ItemStack> l = OreDictionary.getOres((String)o);
if(!l.isEmpty())
return l.get(0);
else
return null;
}
return null;
}
public static Map<String, Integer> sortMap(Map<String, Integer> map, boolean inverse)
{
TreeMap<String,Integer> sortedMap = new TreeMap<String,Integer>(new ValueComparator(map, inverse));
sortedMap.putAll(map);
return sortedMap;
}
public static class ValueComparator implements java.util.Comparator<String>
{
Map<String, Integer> base;
boolean inverse;
public ValueComparator(Map<String, Integer> base, boolean inverse)
{
this.base = base;
this.inverse = inverse;
}
@Override
public int compare(String s0, String s1)//Cant return equal to keys separate
{
if(inverse)
{
if (base.get(s0) <= base.get(s1))
return -1;
else
return 1;
}
else
{
if (base.get(s0) >= base.get(s1))
return -1;
else
return 1;
}
}
@Override
public boolean equals(Object obj)
{
if(!(obj instanceof ValueComparator))
return false;
ValueComparator other = (ValueComparator) obj;
return other.base == base && other.inverse == inverse;
}
}
@SideOnly(Side.CLIENT)
public static TextureAtlasSprite getRegisterSprite(TextureMap map, String path)
{
TextureAtlasSprite sprite = map.getTextureExtry(path);
if(sprite==null)
{
map.registerSprite(new ResourceLocation(path));
sprite = map.getTextureExtry(path);
}
return sprite;
}
@SideOnly(Side.CLIENT)
public static TextureAtlasSprite getRegisterSprite(TextureMap map, ResourceLocation path)
{
TextureAtlasSprite sprite = map.getTextureExtry(path.toString());
if(sprite==null)
{
map.registerSprite(path);
sprite = map.getTextureExtry(path.toString());
}
return sprite;
}
}

View file

@ -1,103 +0,0 @@
package blusunrize.immersiveengineering.api;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.oredict.OreDictionary;
public class ComparableItemStack
{
public ItemStack stack;
public boolean useNBT;
public int oreID=-1;
public ComparableItemStack(ItemStack stack)
{
if(stack==null)
throw new RuntimeException("You cannot instantiate a ComparableItemStack with null for an Item!");
this.stack = stack;
int[] oids = OreDictionary.getOreIDs(stack);
if(oids!=null && oids.length>0)
this.oreID = oids[0];
}
public ComparableItemStack(String oreName)
{
this(IEApi.getPreferredOreStack(oreName));
this.oreID = OreDictionary.getOreID(oreName);
}
public ComparableItemStack setUseNBT(boolean useNBT)
{
this.useNBT = useNBT;
return this;
}
public ComparableItemStack setOreID(int oid)
{
this.oreID = oid;
return this;
}
@Override
public String toString()
{
return "ComparableStack: {"+this.stack.toString()+"}; oreID: "+this.oreID+"; checkNBT: "+this.useNBT;
}
@Override
public int hashCode()
{
if(this.oreID!=-1)
return this.oreID;
int hash = (stack.getItemDamage()&0xffff)*31 + stack.getItem().hashCode()*31;
if(this.useNBT && stack.hasTagCompound())
hash += stack.getTagCompound().hashCode()*31;
return hash;
}
@Override
public boolean equals(Object object)
{
if(!(object instanceof ComparableItemStack))
return false;
if(this.oreID!=-1 && ((ComparableItemStack)object).oreID!=-1)
return this.oreID == ((ComparableItemStack)object).oreID;
ItemStack otherStack = ((ComparableItemStack)object).stack;
if(!OreDictionary.itemMatches(stack,otherStack, false))
return false;
if(this.useNBT)
{
if(this.stack.hasTagCompound() != otherStack.hasTagCompound())
return false;
if(!this.stack.hasTagCompound() && !otherStack.hasTagCompound())
return true;
if(!this.stack.getTagCompound().equals(otherStack.getTagCompound()))
return false;
}
return true;
}
public NBTTagCompound writeToNBT(NBTTagCompound nbt)
{
if(this.oreID!=-1)
nbt.setString("oreID", OreDictionary.getOreName(oreID));
else
{
nbt.setTag("stack", stack.writeToNBT(new NBTTagCompound()));
nbt.setBoolean("useNBT", useNBT);
}
return nbt;
}
public static ComparableItemStack readFromNBT(NBTTagCompound nbt)
{
if(nbt.hasKey("oreID"))
return new ComparableItemStack(nbt.getString("oreID"));
else if(nbt.hasKey("stack"))
{
ComparableItemStack comp = new ComparableItemStack(ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("stack")));
comp.useNBT = nbt.getBoolean("useNBT");
return comp;
}
return null;
}
}

View file

@ -1,60 +0,0 @@
package blusunrize.immersiveengineering.api;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class DimensionBlockPos extends BlockPos
{
public int dimension;
public DimensionBlockPos(int x, int y, int z, int dim)
{
super(x, y, z);
dimension = dim;
}
public DimensionBlockPos(int x, int y, int z, World w)
{
this(x, y, z, w.provider.getDimension());
}
public DimensionBlockPos(BlockPos pos, World w)
{
this(pos.getX(), pos.getY(), pos.getZ(), w.provider.getDimension());
}
public DimensionBlockPos(BlockPos pos, int dim)
{
this(pos.getX(), pos.getY(), pos.getZ(), dim);
}
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + dimension;
result = prime * result + getX();
result = prime * result + getY();
result = prime * result + getZ();
return result;
}
@Override
public boolean equals(Object obj)
{
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
DimensionBlockPos other = (DimensionBlockPos) obj;
if (dimension != other.dimension)
return false;
if (getX() != other.getX())
return false;
if (getY() != other.getY())
return false;
return getZ() == other.getZ();
}
@Override
public String toString() {
return "Dimension: "+dimension+" Pos: "+super.toString();
}
}

View file

@ -1,48 +0,0 @@
package blusunrize.immersiveengineering.api;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.ChunkPos;
public class DimensionChunkCoords extends ChunkPos
{
public int dimension;
public DimensionChunkCoords(int dimension, int x, int z)
{
super(x,z);
this.dimension=dimension;
}
@Override
public boolean equals(Object o)
{
if (this == o)
return true;
else if (!(o instanceof DimensionChunkCoords))
return false;
else
{
DimensionChunkCoords coordPair = (DimensionChunkCoords)o;
return this.dimension==coordPair.dimension && this.chunkXPos==coordPair.chunkXPos && this.chunkZPos==coordPair.chunkZPos;
}
}
@Override
public String toString()
{
return "[dim:"+ this.dimension+ "; " +this.chunkXPos+ ", " +this.chunkZPos + "]";
}
public NBTTagCompound writeToNBT()
{
NBTTagCompound tag = new NBTTagCompound();
tag.setInteger("dim", dimension);
tag.setInteger("x", this.chunkXPos);
tag.setInteger("z", this.chunkZPos);
return tag;
}
public static DimensionChunkCoords readFromNBT(NBTTagCompound tag)
{
if(tag.hasKey("dim",3)&&tag.hasKey("x",3)&&tag.hasKey("z",3))
return new DimensionChunkCoords(tag.getInteger("dim"),tag.getInteger("x"),tag.getInteger("z"));
return null;
}
}

View file

@ -1,39 +0,0 @@
package blusunrize.immersiveengineering.api;
import com.google.common.base.Objects;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
public class DirectionalBlockPos extends BlockPos
{
public EnumFacing direction;
public DirectionalBlockPos(BlockPos pos)
{
this(pos, EnumFacing.DOWN);
}
public DirectionalBlockPos(BlockPos pos, EnumFacing direction)
{
this(pos.getX(), pos.getY(), pos.getZ(), direction);
}
public DirectionalBlockPos(int x, int y, int z, EnumFacing direction)
{
super(x, y, z);
this.direction = direction;
}
public String toString()
{
return Objects.toStringHelper(this).add("x", this.getX()).add("y", this.getY()).add("z", this.getZ()).add("direction", this.direction.toString()).toString();
}
public TileEntity getTile(World world)
{
return world.getTileEntity(this);
}
}

View file

@ -1,80 +0,0 @@
package blusunrize.immersiveengineering.api;
import java.util.HashMap;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.registry.GameData;
import net.minecraftforge.oredict.OreDictionary;
/**
* @author BluSunrize - 13.08.2015
*
* An API class, for features that should be accessible in compatibility
*/
public class IEApi
{
/**
* A list of mod-ids, representing the mods an ore should be used from in order of priority
*/
public static List<String> modPreference;
/**
* This map caches the preferred ores for the given OreDict name
*/
public static HashMap<String, ItemStack> oreOutputPreference = new HashMap<String, ItemStack>();
/**
* The TextureSheet id for the revolver's icons
*/
public static int revolverTextureSheetID;
/**
* This map stores a list of OreDict prefixes (ingot, plate, gear, nugget) and their ingot relation (ingot:component) <br>
* Examples:<br>"plate"-{1,1},<br>"nugget"-{1,9},<br>"block"-{9,1},<br>"gear"-{4,1}
*/
public static HashMap<String, Integer[]> prefixToIngotMap = new HashMap<String, Integer[]>();
/**
* An array of all potions added by IE. indices are as follows:<br>
* 0: flammable, increases all fire damage done<br>
* 1: slippery, makes the target slide around and randomly drop their held item<br>
* 2: conductive, increases flux damage done to the target (CoFH/RedstoneArsenal compat)<br>
*/
public static Potion[] potions;
public static ItemStack getPreferredOreStack(String oreName)
{
if(!oreOutputPreference.containsKey(oreName))
{
ItemStack preferredStack = ApiUtils.isExistingOreName(oreName)?getPreferredStackbyMod(OreDictionary.getOres(oreName)): null;
oreOutputPreference.put(oreName, preferredStack);
return preferredStack;
}
ItemStack s = oreOutputPreference.get(oreName);
return s!=null?s.copy():null;
}
public static ItemStack getPreferredStackbyMod(List<ItemStack> list)
{
ItemStack preferredStack = null;
int lastPref = -1;
for(ItemStack stack : list)
if(stack!=null && stack.getItem()!=null)
{
ResourceLocation rl = GameData.getItemRegistry().getNameForObject(stack.getItem());
if(rl!=null)
{
String modId = rl.getResourceDomain();
int idx = modId==null||modId.isEmpty()?-1: modPreference.indexOf(modId);
if(preferredStack==null || (idx>=0 && (lastPref<0 || idx<lastPref)))
{
preferredStack = stack;
lastPref = idx;
}
}
}
return preferredStack!=null?preferredStack.copy():null;
}
}

View file

@ -1,19 +0,0 @@
package blusunrize.immersiveengineering.api;
import net.minecraft.util.IStringSerializable;
public class IEEnums
{
public enum SideConfig implements IStringSerializable
{
NONE,
INPUT,
OUTPUT;
@Override
public String getName()
{
return this.toString().toLowerCase();
}
}
}

View file

@ -1,15 +0,0 @@
package blusunrize.immersiveengineering.api;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
/**
* Implemented on blocks that can have a transformer 'attached' to them (for example, wooden post).
*/
public interface IPostBlock
{
/**
* Returns true if a transformer should render attached to this post
*/
boolean canConnectTransformer(IBlockAccess world, BlockPos pos);
}

View file

@ -1,84 +0,0 @@
package blusunrize.immersiveengineering.api;
import java.util.ArrayList;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
/**
* @author BluSunrize - 27.04.2015
* <br>
* The handler for IE multiblocks. TO handle custom structures, create a class implementing IMultiblock and register it
*/
public class MultiblockHandler
{
static ArrayList<IMultiblock> multiblocks = new ArrayList<IMultiblock>();
public static void registerMultiblock(IMultiblock multiblock)
{
multiblocks.add(multiblock);
}
public static ArrayList<IMultiblock> getMultiblocks()
{
return multiblocks;
}
public interface IMultiblock
{
/**
* returns name of the Multiblock. This is used for the interdiction NBT system on the hammer, so this name /must/ be unique.
*/
String getUniqueName();
/**
* Check whether the given block can be used to trigger the structure creation of the multiblock.<br>
* Basically, a less resource-intensive preliminary check to avoid checking every structure.
*/
boolean isBlockTrigger(IBlockState state);
/**
* This method checks the structure and sets the new one.
* @return if the structure was valid and transformed
*/
boolean createStructure(World world, BlockPos pos, EnumFacing side, EntityPlayer player);
/**
* A three-dimensional array (height, length, width) of the structure to be rendered in the Engineers Manual
*/
ItemStack[][][] getStructureManual();
/**
* An array of ItemStacks that summarizes the total amount of materials needed for the structure. Will be rendered in the Engineer's Manual
*/
ItemStack[] getTotalMaterials();
/**
* Use this to overwrite the rendering of a Multiblock's Component
*/
@SideOnly(Side.CLIENT)
boolean overwriteBlockRender(ItemStack stack, int iterator);
/**
* returns the scale modifier to be applied when rendering the structure in the IE manual
*/
float getManualScale();
/**
* returns true to add a button that will switch between the assembly of multiblocks and the finished render
*/
@SideOnly(Side.CLIENT)
boolean canRenderFormedStructure();
/**
* use this function to render the complete multiblock
*/
@SideOnly(Side.CLIENT)
void renderFormedStructure();
}
}

View file

@ -1,36 +0,0 @@
package blusunrize.immersiveengineering.api;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
/**
* @author BluSunrize - 11.03.2015
*
* Similar too MovingObjectPosition.class, but this is specifically designed for sub-targets on a block
*/
public class TargetingInfo
{
public final EnumFacing side;
public final float hitX;
public final float hitY;
public final float hitZ;
public TargetingInfo(EnumFacing side, float hitX, float hitY, float hitZ)
{
this.side=side;
this.hitX=hitX;
this.hitY=hitY;
this.hitZ=hitZ;
}
public void writeToNBT(NBTTagCompound tag)
{
tag.setInteger("side", side.ordinal());
tag.setFloat("hitX", hitX);
tag.setFloat("hitY", hitY);
tag.setFloat("hitZ", hitZ);
}
public static TargetingInfo readFromNBT(NBTTagCompound tag)
{
return new TargetingInfo(EnumFacing.getFront(tag.getInteger("side")), tag.getFloat("hitX"),tag.getFloat("hitY"),tag.getFloat("hitZ") );
}
}

View file

@ -1,250 +0,0 @@
package blusunrize.immersiveengineering.api.crafting;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.google.common.collect.Lists;
import blusunrize.immersiveengineering.api.ApiUtils;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.oredict.OreDictionary;
/**
* @author BluSunrize - 23.03.2015
* <br>
* The recipe for the arc furnace
*/
public class ArcFurnaceRecipe extends MultiblockRecipe
{
public static float energyModifier = 1;
public static float timeModifier = 1;
public final IngredientStack input;
public final String oreInputString;
public final IngredientStack[] additives;
public final ItemStack output;
public final ItemStack slag;
public String specialRecipeType;
public static ArrayList<String> specialRecipeTypes = new ArrayList<String>();
public static ArrayList<ArcFurnaceRecipe> recipeList = new ArrayList<ArcFurnaceRecipe>();
public ArcFurnaceRecipe(ItemStack output, Object input, ItemStack slag, int time, int energyPerTick, Object... additives)
{
this.output = output;
this.input = ApiUtils.createIngredientStack(input);
this.oreInputString = input instanceof String?(String)input: null;
this.slag = slag;
this.totalProcessTime = (int)Math.floor(time*timeModifier);
this.totalProcessEnergy = (int)Math.floor(energyPerTick*energyModifier)*totalProcessTime;
if(additives==null)
this.additives = new IngredientStack[0];
else
{
this.additives = new IngredientStack[additives.length];
for(int i=0; i<additives.length; i++)
this.additives[i]=ApiUtils.createIngredientStack(additives[i]);
}
this.inputList = Lists.newArrayList(this.input);
if(additives.length>0)
this.inputList.addAll(Lists.newArrayList(this.additives));
this.outputList = Lists.newArrayList(this.output);
}
@Override
public void setupJEI()
{
super.setupJEI();
// List<ItemStack>[] newJeiItemOutputList = new ArrayList[jeiItemOutputList.length+1];
// System.arraycopy(jeiItemOutputList,0, newJeiItemOutputList,0, jeiItemOutputList.length);
// newJeiItemOutputList[jeiItemOutputList.length] = Lists.newArrayList(slag);
// jeiItemOutputList = newJeiItemOutputList;
this.jeiTotalItemOutputList.add(slag);
}
@Override
public int getMultipleProcessTicks()
{
return 0;
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt)
{
nbt.setTag("input", input.writeToNBT(new NBTTagCompound()));
if(this.additives.length>0)
{
NBTTagList list = new NBTTagList();
for(IngredientStack add : this.additives)
list.appendTag(add.writeToNBT(new NBTTagCompound()));
nbt.setTag("additives", list);
}
return nbt;
}
public static ArcFurnaceRecipe loadFromNBT(NBTTagCompound nbt)
{
IngredientStack input = IngredientStack.readFromNBT(nbt.getCompoundTag("input"));
IngredientStack[] additives = null;
if(nbt.hasKey("additives"))
{
NBTTagList list = nbt.getTagList("additives", 10);
additives = new IngredientStack[list.tagCount()];
for(int i=0; i<additives.length; i++)
additives[i] = IngredientStack.readFromNBT(list.getCompoundTagAt(i));
}
for(ArcFurnaceRecipe recipe : recipeList)
if(recipe.input.equals(input))
{
if(additives==null && recipe.additives.length<1)
return recipe;
else if(additives!=null && recipe.additives.length==additives.length)
{
boolean b = true;
for(int i=0; i<additives.length; i++)
if(!additives[i].equals(recipe.additives[i]))
{
b=false;
break;
}
if(b)
return recipe;
}
}
return null;
}
public List<ItemStack> getOutputs(ItemStack input, ItemStack[] additives)
{
return Lists.newArrayList(output);
}
public boolean matches(ItemStack input, ItemStack[] additives)
{
if(this.input!=null && this.input.matches(input))
{
ArrayList<ItemStack> qAdd = new ArrayList<ItemStack>(additives.length);
for(ItemStack s : additives)
qAdd.add(s);
for(IngredientStack add : this.additives)
if(add!=null)
{
int addAmount = add.inputSize;
Iterator<ItemStack> it = qAdd.iterator();
while(it.hasNext())
{
ItemStack query = it.next();
if(query!=null)
{
if(add.matches(query))
{
if(query.stackSize > addAmount)
{
query.stackSize-=addAmount;
addAmount=0;
}
else
{
addAmount-=query.stackSize;
query.stackSize=0;
}
}
if(query.stackSize<=0)
it.remove();
if(addAmount<=0)
break;
}
}
if(addAmount>0)
return false;
}
return true;
}
return false;
}
public boolean isValidInput(ItemStack stack)
{
return this.input!=null && this.input.matches(stack);
}
public boolean isValidAdditive(ItemStack stack)
{
for(IngredientStack add : additives)
if(add!=null && add.matches(stack))
return true;
return false;
}
public ArcFurnaceRecipe setSpecialRecipeType(String type)
{
this.specialRecipeType = type;
if(!specialRecipeTypes.contains(type))
specialRecipeTypes.add(type);
return this;
}
public static ArcFurnaceRecipe addRecipe(ItemStack output, Object input, ItemStack slag, int time, int energyPerTick, Object... additives)
{
ArcFurnaceRecipe recipe = new ArcFurnaceRecipe(output, input, slag, time, energyPerTick, additives);
if(recipe.input!=null)
recipeList.add(recipe);
return recipe;
}
public static ArcFurnaceRecipe findRecipe(ItemStack input, ItemStack[] additives)
{
for(ArcFurnaceRecipe recipe : recipeList)
if(recipe!=null && recipe.matches(input, additives))
return recipe;
return null;
}
public static List<ArcFurnaceRecipe> removeRecipes(ItemStack stack)
{
List<ArcFurnaceRecipe> list = new ArrayList();
Iterator<ArcFurnaceRecipe> it = recipeList.iterator();
while(it.hasNext())
{
ArcFurnaceRecipe ir = it.next();
if(OreDictionary.itemMatches(ir.output, stack, true))
{
list.add(ir);
it.remove();
}
}
return list;
}
public static boolean isValidRecipeInput(ItemStack stack)
{
for(ArcFurnaceRecipe recipe : recipeList)
if(recipe!=null && recipe.isValidInput(stack))
return true;
return false;
}
public static boolean isValidRecipeAdditive(ItemStack stack)
{
for(ArcFurnaceRecipe recipe : recipeList)
if(recipe!=null && recipe.isValidAdditive(stack))
return true;
return false;
}
public static ArrayList recyclingAllowed = new ArrayList();
/**
* Set an item/oredict-entry to be considered for recycling in the arc furnace. Tools and Armor should usually be auto-detected
*/
public static void allowItemForRecycling(Object stack)
{
recyclingAllowed.add(ApiUtils.convertToValidRecipeInput(stack));
}
public static ArrayList invalidRecyclingOutput = new ArrayList();
/**
* Set an item/oredict-entry to be an invalid output for the recycling process. Used for magical ingots that should be reclaimable or similar
*/
public static void makeItemInvalidRecyclingOutput(Object stack)
{
invalidRecyclingOutput.add(ApiUtils.convertToValidRecipeInput(stack));
}
}

View file

@ -1,83 +0,0 @@
package blusunrize.immersiveengineering.api.crafting;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import blusunrize.immersiveengineering.api.ApiUtils;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
/**
* @author BluSunrize - 23.03.2015
* <br>
* The recipe for the blast furnace
*/
public class BlastFurnaceRecipe
{
public final Object input;
public final ItemStack output;
public final ItemStack slag;
public final int time;
public BlastFurnaceRecipe(ItemStack output, Object input, int time, ItemStack slag)
{
this.output=output;
this.input=ApiUtils.convertToValidRecipeInput(input);
this.time=time;
this.slag=slag;
}
public static ArrayList<BlastFurnaceRecipe> recipeList = new ArrayList<BlastFurnaceRecipe>();
public static void addRecipe(ItemStack output, Object input, int time, ItemStack slag)
{
BlastFurnaceRecipe recipe = new BlastFurnaceRecipe(output, input, time, slag);
if(recipe.input!=null)
recipeList.add(recipe);
}
public static BlastFurnaceRecipe findRecipe(ItemStack input)
{
for(BlastFurnaceRecipe recipe : recipeList)
{
if(ApiUtils.stackMatchesObject(input, recipe.input))
return recipe;
}
return null;
}
public static List<BlastFurnaceRecipe> removeRecipes(ItemStack stack)
{
List<BlastFurnaceRecipe> list = new ArrayList();
Iterator<BlastFurnaceRecipe> it = recipeList.iterator();
while(it.hasNext())
{
BlastFurnaceRecipe ir = it.next();
if(OreDictionary.itemMatches(ir.output, stack, true))
{
list.add(ir);
it.remove();
}
}
return list;
}
public static HashMap<Object, Integer> blastFuels = new HashMap<Object, Integer>();
public static void addBlastFuel(Object fuel, int burnTime)
{
Object key = ApiUtils.convertToValidRecipeInput(fuel);
if(key!=null)
blastFuels.put(key, burnTime);
}
public static int getBlastFuelTime(ItemStack stack)
{
for(Map.Entry<Object,Integer> e : blastFuels.entrySet())
if(ApiUtils.stackMatchesObject(stack, e.getKey()))
return e.getValue();
return 0;
}
public static boolean isValidBlastFuel(ItemStack stack)
{
return getBlastFuelTime(stack)>0;
}
}

View file

@ -1,298 +0,0 @@
package blusunrize.immersiveengineering.api.crafting;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Lists;
import blusunrize.immersiveengineering.api.ApiUtils;
import blusunrize.immersiveengineering.common.util.Utils;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.oredict.OreDictionary;
/**
* @author BluSunrize - 21.07.2015
* <br>
* These recipes are accessible in the Engineers Workbench, with a Engineers Blueprint item.<br>
* For every "category" registered, a blueprint item will be added automatically.
*/
public class BlueprintCraftingRecipe extends MultiblockRecipe
{
public static ArrayList<String> blueprintCategories = new ArrayList<String>();
public static ArrayListMultimap<String, BlueprintCraftingRecipe> recipeList = ArrayListMultimap.create();
public static HashMap<String, ItemStack> villagerPrices = new HashMap<String, ItemStack>();
public String blueprintCategory;
public ItemStack output;
public IngredientStack[] inputs;
public BlueprintCraftingRecipe(String blueprintCategory, ItemStack output, Object[] inputs)
{
this.blueprintCategory = blueprintCategory;
this.output = output;
this.inputs = new IngredientStack[inputs.length];
for(int io=0; io<inputs.length; io++)
this.inputs[io] = ApiUtils.createIngredientStack(inputs[io]);
this.inputList = Lists.newArrayList(this.inputs);
this.outputList = Lists.newArrayList(this.output);
}
public boolean matchesRecipe(ItemStack[] query)
{
// ArrayList<Object> inputList = new ArrayList();
// for(Object i : inputs)
// if(i!=null)
// inputList.add(i instanceof ItemStack? ((ItemStack)i).copy(): i);
// ArrayList<ItemStack> queryList = new ArrayList();
// for(ItemStack q : query)
// if(q!=null)
// queryList.add(q.copy());
//
// Iterator inputIt = inputList.iterator();
// while(inputIt.hasNext())
// {
// boolean match = false;
// Object o = inputIt.next();
// Iterator<ItemStack> queryIt = queryList.iterator();
// while(queryIt.hasNext())
// {
// ItemStack stack = queryIt.next();
// if(ApiUtils.stackMatchesObject(stack, o))
// {
// if(o instanceof ItemStack)
// {
// int taken = Math.min(stack.stackSize, ((ItemStack)o).stackSize);
// stack.stackSize-=taken;
// if(stack.stackSize<=0)
// {
// queryIt.remove();
// }
//
// ((ItemStack)o).stackSize-=taken;
// if(((ItemStack)o).stackSize<=0)
// {
// match = true;
// inputIt.remove();
// break;
// }
// }
// else
// {
// stack.stackSize--;
// if(stack.stackSize<=0)
// queryIt.remove();
//
// match = true;
// inputIt.remove();
// break;
// }
//
// }
// }
// if(!match)
// {
// return false;
// }
// }
// if(inputList.isEmpty())
// return true;
return getMaxCrafted(query)>0;
}
public int getMaxCrafted(ItemStack[] query)
{
HashMap<ItemStack, Integer> queryAmount = new HashMap<ItemStack, Integer>();
for(ItemStack q : query)
if(q!=null)
{
boolean inc = false;
for(ItemStack key : queryAmount.keySet())
if(OreDictionary.itemMatches(q, key, true))
{
queryAmount.put(key, queryAmount.get(key)+q.stackSize);
inc = true;
}
if(!inc)
queryAmount.put(q, q.stackSize);
}
int maxCrafted = 0;
ArrayList<IngredientStack> formattedInputList = getFormattedInputs();
Iterator<IngredientStack> formInputIt = formattedInputList.iterator();
while(formInputIt.hasNext())
{
IngredientStack ingr = formInputIt.next();
int supplied = 0;
int req = ingr.inputSize;
Iterator<Entry<ItemStack, Integer>> queryIt = queryAmount.entrySet().iterator();
while(queryIt.hasNext())
{
Entry<ItemStack, Integer> e = queryIt.next();
ItemStack compStack = e.getKey();
if(ingr.matchesItemStack(compStack))
{
int taken = e.getValue()/req;
if(taken>0)
{
e.setValue(e.getValue()-taken*req);
if(e.getValue()<=0)
queryIt.remove();
supplied += taken;
}
}
}
if(supplied<=0)
return 0;
else
maxCrafted = maxCrafted==0?supplied:Math.min(maxCrafted, supplied);
}
return maxCrafted;
}
public void consumeInputs(ItemStack[] query, int crafted)
{
ArrayList<IngredientStack> inputList = new ArrayList();
for(IngredientStack i : inputs)
if(i!=null)
{
if(i.oreName!=null)
inputList.add(new IngredientStack(i.oreName, i.inputSize));
else if(i.stackList!=null)
inputList.add(new IngredientStack(Lists.newArrayList(i.stackList), i.inputSize));
else if(i.stack!=null)
inputList.add(new IngredientStack(Utils.copyStackWithAmount(i.stack, i.inputSize)));
}
Iterator<IngredientStack> inputIt = inputList.iterator();
while(inputIt.hasNext())
{
IngredientStack ingr = inputIt.next();
int inputSize = ingr.inputSize*crafted;
for(int i=0; i<query.length; i++)
if(query[i]!=null)
if(ingr.matchesItemStack(query[i]))
{
int taken = Math.min(query[i].stackSize, inputSize);
query[i].stackSize-=taken;
if(query[i].stackSize<=0)
query[i] = null;
inputSize-=taken;
if(inputSize<=0)
{
inputIt.remove();
break;
}
}
}
}
public ArrayList<IngredientStack> getFormattedInputs()
{
ArrayList<IngredientStack> formattedInputs = new ArrayList<IngredientStack>();
for(IngredientStack ingr : this.inputs)
if(ingr!=null)
{
boolean isNew = true;
for(IngredientStack formatted : formattedInputs)
{
if(ingr.oreName!=null && ingr.oreName.equals(formatted.oreName))
isNew=false;
else if(ingr.stackList!=null && formatted.stackList!=null)
{
for(ItemStack iStack : ingr.stackList)
for(ItemStack iStack2 : formatted.stackList)
if(OreDictionary.itemMatches(iStack, iStack2, false))
{
isNew=false;
break;
}
}
else if(ingr.stack!=null && OreDictionary.itemMatches(ingr.stack, formatted.stack, false))
isNew=false;
if(!isNew)
formatted.inputSize += ingr.inputSize;
}
if(isNew)
{
if(ingr.oreName!=null)
formattedInputs.add(new IngredientStack(ingr.oreName, ingr.inputSize));
else if(ingr.stackList!=null)
formattedInputs.add(new IngredientStack(Lists.newArrayList(ingr.stackList), ingr.inputSize));
else if(ingr.stack!=null)
formattedInputs.add(new IngredientStack(Utils.copyStackWithAmount(ingr.stack, ingr.inputSize)));
}
}
return formattedInputs;
}
public static void addRecipe(String blueprintCategory, ItemStack output, Object... inputs)
{
recipeList.put(blueprintCategory, new BlueprintCraftingRecipe(blueprintCategory, output, inputs));
if(!blueprintCategories.contains(blueprintCategory))
blueprintCategories.add(blueprintCategory);
}
public static BlueprintCraftingRecipe[] findRecipes(String blueprintCategory)
{
if(recipeList.containsKey(blueprintCategory))
{
List<BlueprintCraftingRecipe> list = recipeList.get(blueprintCategory);
return list.toArray(new BlueprintCraftingRecipe[list.size()]);
}
return new BlueprintCraftingRecipe[0];
}
/**
* registers a type of blueprint to be up for sale at the IE villager. Stacksize of the price will be slightly randomized (+- 2)
*/
public static void addVillagerTrade(String blueprintCategory, ItemStack villagerPrice)
{
villagerPrices.put(blueprintCategory, villagerPrice);
}
@Override
public int getMultipleProcessTicks()
{
return 0;
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt)
{
NBTTagList list = new NBTTagList();
for(IngredientStack ingr : this.inputs)
list.appendTag(ingr.writeToNBT(new NBTTagCompound()));
nbt.setTag("inputs", list);
nbt.setString("blueprintCategory", this.blueprintCategory);
return nbt;
}
public static BlueprintCraftingRecipe loadFromNBT(NBTTagCompound nbt)
{
NBTTagList list = nbt.getTagList("inputs", 10);
IngredientStack[] inputs = new IngredientStack[list.tagCount()];
for(int i=0; i<inputs.length; i++)
inputs[i] = IngredientStack.readFromNBT(list.getCompoundTagAt(i));
List<BlueprintCraftingRecipe> recipeList = BlueprintCraftingRecipe.recipeList.get("blueprintCategory");
for(BlueprintCraftingRecipe recipe : recipeList)
{
boolean b = false;
for(int i=0; i<inputs.length; i++)
{
for(int j=0; j<recipe.inputs.length; j++)
if(recipe.inputs[j].matches(inputs[i]))
{
b = true;
break;
}
}
if(b)
return recipe;
}
return null;
}
}

View file

@ -1,60 +0,0 @@
package blusunrize.immersiveengineering.api.crafting;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.OreDictionary;
import blusunrize.immersiveengineering.api.ApiUtils;
/**
* @author BluSunrize - 27.10.2015
* <br>
* The recipe for the bottling machine
*/
public class BottlingMachineRecipe
{
public final Object input;
public final FluidStack fluidInput;
public final ItemStack output;
public BottlingMachineRecipe(ItemStack output, Object input, FluidStack fluidInput)
{
this.output=output;
this.input=ApiUtils.convertToValidRecipeInput(input);
this.fluidInput=fluidInput;
}
public static ArrayList<BottlingMachineRecipe> recipeList = new ArrayList<BottlingMachineRecipe>();
public static void addRecipe(ItemStack output, Object input, FluidStack fluidInput)
{
BottlingMachineRecipe recipe = new BottlingMachineRecipe(output, input, fluidInput);
if(recipe.input!=null)
recipeList.add(recipe);
}
public static BottlingMachineRecipe findRecipe(ItemStack input, FluidStack fluid)
{
if(input!=null && fluid!=null)
for(BottlingMachineRecipe recipe : recipeList)
if(ApiUtils.stackMatchesObject(input, recipe.input) && fluid.containsFluid(recipe.fluidInput))
return recipe;
return null;
}
public static List<BottlingMachineRecipe> removeRecipes(ItemStack stack)
{
List<BottlingMachineRecipe> list = new ArrayList();
Iterator<BottlingMachineRecipe> it = recipeList.iterator();
while(it.hasNext())
{
BottlingMachineRecipe ir = it.next();
if(OreDictionary.itemMatches(ir.output, stack, true))
{
list.add(ir);
it.remove();
}
}
return list;
}
}

View file

@ -1,60 +0,0 @@
package blusunrize.immersiveengineering.api.crafting;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import blusunrize.immersiveengineering.api.ApiUtils;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
/**
* @author BluSunrize - 23.03.2015
* <br>
* The recipe for the coke oven
*/
public class CokeOvenRecipe
{
public final Object input;
public final ItemStack output;
public final int time;
public final int creosoteOutput;
public CokeOvenRecipe(ItemStack output, Object input, int time, int creosoteOutput)
{
this.output=output;
this.input=ApiUtils.convertToValidRecipeInput(input);
this.time=time;
this.creosoteOutput=creosoteOutput;
}
public static ArrayList<CokeOvenRecipe> recipeList = new ArrayList<CokeOvenRecipe>();
public static void addRecipe(ItemStack output, Object input, int time, int creosoteOutput)
{
CokeOvenRecipe recipe = new CokeOvenRecipe(output, input, time, creosoteOutput);
if(recipe.input!=null)
recipeList.add(recipe);
}
public static CokeOvenRecipe findRecipe(ItemStack input)
{
for(CokeOvenRecipe recipe : recipeList)
if(ApiUtils.stackMatchesObject(input, recipe.input))
return recipe;
return null;
}
public static List<CokeOvenRecipe> removeRecipes(ItemStack stack)
{
List<CokeOvenRecipe> list = new ArrayList();
Iterator<CokeOvenRecipe> it = recipeList.iterator();
while(it.hasNext())
{
CokeOvenRecipe ir = it.next();
if(OreDictionary.itemMatches(ir.output, stack, true))
{
list.add(ir);
it.remove();
}
}
return list;
}
}

View file

@ -1,135 +0,0 @@
package blusunrize.immersiveengineering.api.crafting;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.google.common.collect.Lists;
import blusunrize.immersiveengineering.api.ApiUtils;
import blusunrize.immersiveengineering.api.IEApi;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.oredict.OreDictionary;
/**
* @author BluSunrize - 01.05.2015
*
* The recipe for the crusher
*/
public class CrusherRecipe extends MultiblockRecipe
{
public static float energyModifier = 1;
public static float timeModifier = 1;
public final String oreInputString;
public final IngredientStack input;
public final ItemStack output;
public ItemStack[] secondaryOutput;
public float[] secondaryChance;
public CrusherRecipe(ItemStack output, Object input, int energy)
{
this.output = output;
this.input = ApiUtils.createIngredientStack(input);
this.oreInputString = input instanceof String?(String)input: null;
this.totalProcessEnergy = (int)Math.floor(energy*energyModifier);
this.totalProcessTime = (int)Math.floor(50*timeModifier);
this.inputList = Lists.newArrayList(this.input);
this.outputList = Lists.newArrayList(this.output);
}
/**
* Adds secondary outputs to the recipe. Should the recipe have secondary outputs, these will be added /in addition/<br>
* The array should be alternating between Item/Block/ItemStack/ArrayList and a float for the chance
*/
public CrusherRecipe addToSecondaryOutput(Object... outputs)
{
if(outputs.length%2!=0)
return this;
ArrayList<ItemStack> newSecondaryOutput = new ArrayList<ItemStack>();
ArrayList<Float> newSecondaryChance = new ArrayList<Float>();
if(secondaryOutput!=null)
for(int i=0; i<secondaryOutput.length; i++)
{
newSecondaryOutput.add(secondaryOutput[i]);
newSecondaryChance.add(secondaryChance[i]);
}
for(int i=0; i<(outputs.length/2); i++)
if(outputs[i*2]!=null)
{
Object o = ApiUtils.convertToValidRecipeInput(outputs[i*2]);
ItemStack ss = o instanceof ItemStack?(ItemStack)o: o instanceof List?IEApi.getPreferredStackbyMod((List<ItemStack>)o): null;
if(ss!=null)
{
newSecondaryOutput.add(ss);
newSecondaryChance.add((Float)outputs[i*2+1]);
}
}
secondaryOutput = newSecondaryOutput.toArray(new ItemStack[newSecondaryOutput.size()]);
secondaryChance = new float[newSecondaryChance.size()];
int i=0;
for(Float f : newSecondaryChance)
secondaryChance[i++] = f;
this.outputList = Lists.newArrayList(this.secondaryOutput);
if(this.outputList.isEmpty())
this.outputList.add(this.output);
else
this.outputList.add(0, this.output);
return this;
}
public static ArrayList<CrusherRecipe> recipeList = new ArrayList<CrusherRecipe>();
public static CrusherRecipe addRecipe(ItemStack output, Object input, int energy)
{
CrusherRecipe r = new CrusherRecipe(output, input, energy);
if(r.input!=null && r.output!=null)
recipeList.add(r);
return r;
}
public static CrusherRecipe findRecipe(ItemStack input)
{
for(CrusherRecipe recipe : recipeList)
if(recipe.input.matchesItemStack(input))
return recipe;
return null;
}
public static List<CrusherRecipe> removeRecipes(ItemStack stack)
{
List<CrusherRecipe> list = new ArrayList();
Iterator<CrusherRecipe> it = recipeList.iterator();
while(it.hasNext())
{
CrusherRecipe ir = it.next();
if(OreDictionary.itemMatches(ir.output, stack, true))
{
list.add(ir);
it.remove();
}
}
return list;
}
@Override
public int getMultipleProcessTicks()
{
return 4;
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt)
{
nbt.setTag("input", input.writeToNBT(new NBTTagCompound()));
return nbt;
}
public static CrusherRecipe loadFromNBT(NBTTagCompound nbt)
{
IngredientStack input = IngredientStack.readFromNBT(nbt.getCompoundTag("input"));
for(CrusherRecipe recipe : recipeList)
if(recipe.input.equals(input))
return recipe;
return null;
}
}

View file

@ -1,112 +0,0 @@
package blusunrize.immersiveengineering.api.crafting;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import com.google.common.collect.Lists;
import blusunrize.immersiveengineering.api.ApiUtils;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
/**
* @author BluSunrize - 01.03.2016
*
* The recipe for the Fermenter
*/
public class FermenterRecipe extends MultiblockRecipe
{
public static float energyModifier = 1;
public static float timeModifier = 1;
public final IngredientStack input;
public final FluidStack fluidOutput;
public final ItemStack itemOutput;
public FermenterRecipe(FluidStack fluidOutput, ItemStack itemOutput, Object input, int energy)
{
this.fluidOutput = fluidOutput;
this.itemOutput = itemOutput;
this.input = ApiUtils.createIngredientStack(input);
this.totalProcessEnergy = (int)Math.floor(energy*energyModifier);
this.totalProcessTime = (int)Math.floor(80*timeModifier);
this.inputList = Lists.newArrayList(this.input);
this.fluidOutputList = Lists.newArrayList(this.fluidOutput);
this.outputList = Lists.newArrayList(this.itemOutput);
}
public FermenterRecipe setInputSize(int size)
{
this.input.inputSize = size;
return this;
}
public static ArrayList<FermenterRecipe> recipeList = new ArrayList();
public static FermenterRecipe addRecipe(FluidStack fluidOutput, ItemStack itemOutput, Object input, int energy)
{
FermenterRecipe r = new FermenterRecipe(fluidOutput, itemOutput, input, energy);
recipeList.add(r);
return r;
}
public static FermenterRecipe findRecipe(ItemStack input)
{
if(input==null)
return null;
for(FermenterRecipe recipe : recipeList)
if(recipe.input.matches(input))
return recipe;
return null;
}
// public static List<SqueezerRecipe> removeRecipes(ItemStack output)
// {
// List<SqueezerRecipe> list = new ArrayList();
// for(ComparableItemStack mold : recipeList.keySet())
// {
// Iterator<SqueezerRecipe> it = recipeList.get(mold).iterator();
// while(it.hasNext())
// {
// SqueezerRecipe ir = it.next();
// if(OreDictionary.itemMatches(ir.output, output, true))
// {
// list.add(ir);
// it.remove();
// }
// }
// }
// return list;
// }
@Override
public int getMultipleProcessTicks()
{
return 0;
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt)
{
nbt.setTag("input", input.writeToNBT(new NBTTagCompound()));
return nbt;
}
public static FermenterRecipe loadFromNBT(NBTTagCompound nbt)
{
IngredientStack input = IngredientStack.readFromNBT(nbt.getCompoundTag("input"));
for(FermenterRecipe recipe : recipeList)
if(recipe.input.equals(input))
return recipe;
return null;
}
public static Map<String, Integer> getFluidValuesSorted(Fluid f, boolean inverse)
{
HashMap<String, Integer> map = new HashMap<String, Integer>();
for(FermenterRecipe recipe : recipeList)
if(recipe.fluidOutput!=null && recipe.fluidOutput.getFluid()==f)
{
ItemStack is = recipe.input.getExampleStack();
map.put(is.getDisplayName(), recipe.fluidOutput.amount);
}
return ApiUtils.sortMap(map, inverse);
}
}

View file

@ -1,14 +0,0 @@
package blusunrize.immersiveengineering.api.crafting;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
public interface IJEIRecipe
{
List<ItemStack> getJEITotalItemInputs();
List<ItemStack> getJEITotalItemOutputs();
List<FluidStack> getJEITotalFluidInputs();
List<FluidStack> getJEITotalFluidOutputs();
}

View file

@ -1,27 +0,0 @@
package blusunrize.immersiveengineering.api.crafting;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidStack;
/**
* @author BluSunrize - 02.02.2016
* <br>
* An interface implemented by recipes that can be handled by IE's Metal Multiblocks. <br>
* This is only used by IE's own machines, it's just in the API because recipes have to implement it.
*/
public interface IMultiblockRecipe
{
List<IngredientStack> getItemInputs();
List<FluidStack> getFluidInputs();
List<ItemStack> getItemOutputs();
List<FluidStack> getFluidOutputs();
int getTotalProcessTime();
int getTotalProcessEnergy();
int getMultipleProcessTicks();
NBTTagCompound writeToNBT(NBTTagCompound nbtTagCompound);
}

View file

@ -1,284 +0,0 @@
package blusunrize.immersiveengineering.api.crafting;
import java.util.ArrayList;
import java.util.List;
import blusunrize.immersiveengineering.api.ApiUtils;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.common.ForgeModContainer;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidRegistry.FluidRegisterEvent;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.fluids.UniversalBucket;
import net.minecraftforge.oredict.OreDictionary;
public class IngredientStack
{
public ItemStack stack;
public List<ItemStack> stackList;
public String oreName;
public FluidStack fluid;
public int inputSize;
public boolean useNBT;
public IngredientStack(ItemStack stack)
{
this.stack = stack;
this.inputSize = stack.stackSize;
}
public IngredientStack(String oreName, int inputSize)
{
this.oreName = oreName;
this.inputSize = inputSize;
}
public IngredientStack(String oreName)
{
this(oreName, 1);
}
public IngredientStack(List<ItemStack> stackList, int inputSize)
{
this.stackList = stackList;
this.inputSize = inputSize;
}
public IngredientStack(List<ItemStack> stackList)
{
this(stackList, 1);
}
public IngredientStack(FluidStack fluid)
{
this.fluid = fluid;
}
public IngredientStack setUseNBT(boolean useNBT)
{
this.useNBT = useNBT;
return this;
}
public boolean matches(Object input)
{
if(input==null)
return false;
if(input instanceof IngredientStack)
return this.equals(input) && this.inputSize <= ((IngredientStack)input).inputSize;
if(input instanceof ItemStack)
{
return matchesItemStack((ItemStack)input);
}
else if(input instanceof ItemStack[])
{
for(ItemStack iStack : (ItemStack[])input)
if(matchesItemStack(iStack))
return true;
}
else if(input instanceof List)
{
for(Object io : (List)input)
if(this.matches(io))
return true;
}
else if(input instanceof String)
{
if(this.oreName!=null)
return this.oreName.equals(input);
return ApiUtils.compareToOreName(stack, (String)input);
}
return false;
}
public ItemStack getExampleStack()
{
ItemStack ret = stack;
if(ret==null&&stackList!=null&&stackList.size()>0)
ret = stackList.get(0);
if(ret==null&&oreName!=null)
{
List<ItemStack> ores = OreDictionary.getOres(oreName);
if(ores!=null&&ores.size()>0)
ret = ores.get(0);
}
if(ret==null&&fluid!=null&&ForgeModContainer.getInstance().universalBucket!=null)
ret = UniversalBucket.getFilledBucket(ForgeModContainer.getInstance().universalBucket, fluid.getFluid());
return ret;
}
public Object getShapedRecipeInput()
{
Object ret = stack;
if(ret==null&&stackList!=null&&stackList.size()>0)
ret = stackList;
if(ret==null&&oreName!=null)
ret = OreDictionary.getOres(oreName);
if(ret==null&&fluid!=null&&ForgeModContainer.getInstance().universalBucket!=null)
ret = UniversalBucket.getFilledBucket(ForgeModContainer.getInstance().universalBucket, fluid.getFluid());
return ret;
}
public boolean matchesItemStack(ItemStack input)
{
if(input==null)
return false;
if(this.fluid!=null)
{
FluidStack fs = FluidUtil.getFluidContained(input);
if(fs!=null && fs.containsFluid(fluid))
return true;
}
if(this.oreName!=null)
return ApiUtils.compareToOreName(input, oreName) && this.inputSize <= input.stackSize;
if(this.stackList!=null)
{
for(ItemStack iStack : this.stackList)
if(OreDictionary.itemMatches(iStack, input, false) && this.inputSize <= input.stackSize)
return true;
}
if(!OreDictionary.itemMatches(stack,input, false) || this.inputSize > input.stackSize)
return false;
if(this.useNBT)
{
if(this.stack.hasTagCompound() != input.hasTagCompound())
return false;
if(!this.stack.hasTagCompound() && !input.hasTagCompound())
return true;
if(!this.stack.getTagCompound().equals(input.getTagCompound()))
return false;
}
return true;
}
public boolean matchesItemStackIgnoringSize(ItemStack input)
{
if(this.fluid!=null)
{
FluidStack fs = FluidUtil.getFluidContained(input);
if(fs!=null && fs.containsFluid(fluid))
return true;
}
if(this.oreName!=null)
return ApiUtils.compareToOreName(input, oreName);
if(this.stackList!=null)
{
for(ItemStack iStack : this.stackList)
if(OreDictionary.itemMatches(iStack, input, false))
return true;
}
if(!OreDictionary.itemMatches(stack,input, false))
return false;
if(this.useNBT)
{
if(this.stack.hasTagCompound() != input.hasTagCompound())
return false;
if(!this.stack.hasTagCompound() && !input.hasTagCompound())
return true;
if(!this.stack.getTagCompound().equals(input.getTagCompound()))
return false;
}
return true;
}
@Override
public boolean equals(Object object)
{
if(!(object instanceof IngredientStack))
return false;
if(this.fluid!=null && ((IngredientStack)object).fluid!=null)
return this.fluid.equals(((IngredientStack)object).fluid);
if(this.oreName!=null && ((IngredientStack)object).oreName!=null)
return this.oreName.equals(((IngredientStack)object).oreName);
if(this.stackList!=null)
{
if(((IngredientStack)object).stack!=null)
{
for(ItemStack iStack : this.stackList)
if(OreDictionary.itemMatches(iStack, ((IngredientStack)object).stack, false))
return true;
}
else
{
for(ItemStack iStack : this.stackList)
for(ItemStack iStack2 : ((IngredientStack)object).stackList)
if(OreDictionary.itemMatches(iStack, iStack2, false))
return true;
}
return false;
}
if(this.stack!=null && ((IngredientStack)object).stack!=null)
{
ItemStack otherStack = ((IngredientStack)object).stack;
if(!OreDictionary.itemMatches(stack,otherStack, false))
return false;
if(this.useNBT)
{
if(this.stack.hasTagCompound() != otherStack.hasTagCompound())
return false;
if(!this.stack.hasTagCompound() && !otherStack.hasTagCompound())
return true;
if(!this.stack.getTagCompound().equals(otherStack.getTagCompound()))
return false;
}
return true;
}
return false;
}
public NBTTagCompound writeToNBT(NBTTagCompound nbt)
{
if(this.fluid!=null)
{
nbt.setString("fluid", FluidRegistry.getFluidName(fluid));
nbt.setInteger("fluidAmount", fluid.amount);
nbt.setInteger("nbtType", 3);
}
else if(this.oreName!=null)
{
nbt.setString("oreName", oreName);
nbt.setInteger("nbtType", 2);
}
else if(this.stackList!=null)
{
NBTTagList list = new NBTTagList();
for(ItemStack stack : stackList)
if(stack!=null)
list.appendTag(stack.writeToNBT(new NBTTagCompound()));
nbt.setTag("stackList", list);
nbt.setInteger("nbtType", 1);
}
else
{
nbt.setTag("stack", stack.writeToNBT(new NBTTagCompound()));
nbt.setInteger("nbtType", 0);
nbt.setBoolean("useNBT", useNBT);
}
nbt.setInteger("inputSize", inputSize);
return nbt;
}
public static IngredientStack readFromNBT(NBTTagCompound nbt)
{
if(nbt.hasKey("nbtType"))
switch(nbt.getInteger("nbtType"))
{
case 0:
ItemStack stack = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("stack"));
stack.stackSize = nbt.getInteger("inputSize");
IngredientStack ingr = new IngredientStack(stack);
ingr.useNBT = nbt.getBoolean("useNBT");
return ingr;
case 1:
NBTTagList list = nbt.getTagList("stackList", 10);
List<ItemStack> stackList = new ArrayList();
for(int i=0; i<list.tagCount(); i++)
stackList.add(ItemStack.loadItemStackFromNBT(list.getCompoundTagAt(i)));
return new IngredientStack(stackList, nbt.getInteger("inputSize"));
case 2:
return new IngredientStack(nbt.getString("oreName"), nbt.getInteger("inputSize"));
case 3:
FluidStack fs = new FluidStack(FluidRegistry.getFluid(nbt.getString("fluid")),nbt.getInteger("fluidAmount"));
return new IngredientStack(fs);
}
return null;
}
}

View file

@ -1,121 +0,0 @@
package blusunrize.immersiveengineering.api.crafting;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Lists;
import blusunrize.immersiveengineering.api.ApiUtils;
import blusunrize.immersiveengineering.api.ComparableItemStack;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.oredict.OreDictionary;
/**
* @author BluSunrize - 07.01.2016
*
* The recipe for the metal press
*/
public class MetalPressRecipe extends MultiblockRecipe
{
public static float energyModifier = 1;
public static float timeModifier = 1;
public final IngredientStack input;
public final ComparableItemStack mold;
public final ItemStack output;
public MetalPressRecipe(ItemStack output, Object input, ItemStack mold, int energy)
{
this.output = output;
this.input = ApiUtils.createIngredientStack(input);
this.mold = ApiUtils.createComparableItemStack(mold);
this.totalProcessEnergy = (int)Math.floor(energy*energyModifier);
this.totalProcessTime = (int)Math.floor(120*timeModifier);
this.inputList = Lists.newArrayList(this.input);
this.outputList = Lists.newArrayList(this.output);
}
public MetalPressRecipe setInputSize(int size)
{
this.input.inputSize = size;
return this;
}
@Override
public void setupJEI()
{
super.setupJEI();
this.jeiItemInputList = new ArrayList[2];
this.jeiItemInputList[0] =Lists.newArrayList(jeiTotalItemInputList);
this.jeiItemInputList[1] = Lists.newArrayList(mold.stack);
this.jeiTotalItemInputList.add(mold.stack);
}
public static ArrayListMultimap<ComparableItemStack, MetalPressRecipe> recipeList = ArrayListMultimap.create();
public static MetalPressRecipe addRecipe(ItemStack output, Object input, ItemStack mold, int energy)
{
MetalPressRecipe r = new MetalPressRecipe(output, input, mold, energy);
recipeList.put(r.mold, r);
return r;
}
public static MetalPressRecipe findRecipe(ItemStack mold, ItemStack input, boolean checkStackSize)
{
if(mold==null || input==null)
return null;
ComparableItemStack comp = ApiUtils.createComparableItemStack(mold);
List<MetalPressRecipe> list = recipeList.get(comp);
for(MetalPressRecipe recipe : list)
if(recipe.input.matches(input))
return recipe;
return null;
}
public static List<MetalPressRecipe> removeRecipes(ItemStack output)
{
List<MetalPressRecipe> list = new ArrayList();
for(ComparableItemStack mold : recipeList.keySet())
{
Iterator<MetalPressRecipe> it = recipeList.get(mold).iterator();
while(it.hasNext())
{
MetalPressRecipe ir = it.next();
if(OreDictionary.itemMatches(ir.output, output, true))
{
list.add(ir);
it.remove();
}
}
}
return list;
}
public static boolean isValidMold(ItemStack itemStack)
{
if(itemStack==null)
return false;
return recipeList.containsKey(ApiUtils.createComparableItemStack(itemStack));
}
@Override
public int getMultipleProcessTicks()
{
return 0;
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt)
{
nbt.setTag("input", input.writeToNBT(new NBTTagCompound()));
nbt.setTag("mold", mold.writeToNBT(new NBTTagCompound()));
return nbt;
}
public static MetalPressRecipe loadFromNBT(NBTTagCompound nbt)
{
IngredientStack input = IngredientStack.readFromNBT(nbt.getCompoundTag("input"));
ComparableItemStack mold = ComparableItemStack.readFromNBT(nbt.getCompoundTag("mold"));
List<MetalPressRecipe> list = recipeList.get(mold);
for(MetalPressRecipe recipe : list)
if(recipe.input.equals(input))
return recipe;
return null;
}
}

View file

@ -1,150 +0,0 @@
package blusunrize.immersiveengineering.api.crafting;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.google.common.collect.Lists;
import blusunrize.immersiveengineering.api.ApiUtils;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.OreDictionary;
public abstract class MultiblockRecipe implements IMultiblockRecipe, IJEIRecipe
{
protected List<IngredientStack> inputList;
@Override
public List<IngredientStack> getItemInputs()
{
return inputList;
}
protected List<ItemStack> outputList;
@Override
public List<ItemStack> getItemOutputs()
{
return outputList;
}
protected List<FluidStack> fluidInputList;
@Override
public List<FluidStack> getFluidInputs()
{
return fluidInputList;
}
protected List<FluidStack> fluidOutputList;
@Override
public List<FluidStack> getFluidOutputs()
{
return fluidOutputList;
}
int totalProcessTime;
@Override
public int getTotalProcessTime()
{
return this.totalProcessTime;
}
int totalProcessEnergy;
@Override
public int getTotalProcessEnergy()
{
return this.totalProcessEnergy;
}
// =========================
// JEI Integration
// =========================
public List<ItemStack>[] jeiItemInputList;
protected List<ItemStack> jeiTotalItemInputList;
public List<ItemStack>[] jeiItemOutputList;
protected List<ItemStack> jeiTotalItemOutputList;
protected List<FluidStack> jeiFluidInputList;
protected List<FluidStack> jeiFluidOutputList;
public void setupJEI()
{
if(inputList!=null)
{
this.jeiItemInputList = new ArrayList[inputList.size()];
this.jeiTotalItemInputList = new ArrayList();
for(int i=0; i<inputList.size(); i++)
{
IngredientStack ingr = inputList.get(i);
ArrayList list = new ArrayList();
if(ingr.oreName!=null)
for(ItemStack stack : OreDictionary.getOres(ingr.oreName))
list.add(ApiUtils.copyStackWithAmount(stack, ingr.inputSize));
else if(ingr.stackList!=null)
for(ItemStack stack : ingr.stackList)
list.add(ApiUtils.copyStackWithAmount(stack, ingr.inputSize));
else
list.add(ApiUtils.copyStackWithAmount(ingr.stack, ingr.inputSize));
this.jeiItemInputList[i] = list;
this.jeiTotalItemInputList.addAll(list);
}
}
else
this.jeiTotalItemInputList = Collections.emptyList();
if(outputList!=null)
{
this.jeiItemOutputList = new ArrayList[outputList.size()];
this.jeiTotalItemOutputList = new ArrayList();
for(int i=0; i<outputList.size(); i++)
{
ItemStack s = outputList.get(i);
ArrayList<ItemStack> list = Lists.newArrayList(s!=null?s.copy():null);
this.jeiItemOutputList[i] = list;
this.jeiTotalItemOutputList.addAll(list);
}
}
else
this.jeiTotalItemOutputList = Collections.emptyList();
if(fluidInputList!=null)
{
this.jeiFluidInputList = new ArrayList();
for(int i=0; i<fluidInputList.size(); i++)
{
FluidStack fs = fluidInputList.get(i);
if(fs!=null)
this.jeiFluidInputList.add(fs.copy());
}
}
else
this.jeiFluidInputList = Collections.emptyList();
if(fluidOutputList!=null)
{
this.jeiFluidOutputList = new ArrayList();
for(int i=0; i<fluidOutputList.size(); i++)
{
FluidStack fs = fluidOutputList.get(i);
if(fs!=null)
this.jeiFluidOutputList.add(fs.copy());
}
}
else
this.jeiFluidOutputList = Collections.emptyList();
}
@Override
public List<ItemStack> getJEITotalItemInputs()
{
return jeiTotalItemInputList;
}
@Override
public List<ItemStack> getJEITotalItemOutputs()
{
return jeiTotalItemOutputList;
}
@Override
public List<FluidStack> getJEITotalFluidInputs()
{
return jeiFluidInputList;
}
@Override
public List<FluidStack> getJEITotalFluidOutputs()
{
return jeiFluidOutputList;
}
}

View file

@ -1,122 +0,0 @@
package blusunrize.immersiveengineering.api.crafting;
import java.util.ArrayList;
import java.util.List;
import com.google.common.collect.Lists;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidStack;
/**
* @author BluSunrize - 02.03.2016
*
* The recipe for the Refinery
*/
public class RefineryRecipe extends MultiblockRecipe
{
public static float energyModifier = 1;
public static float timeModifier = 1;
public final FluidStack output;
public final FluidStack input0;
public final FluidStack input1;
public RefineryRecipe(FluidStack output, FluidStack input0, FluidStack input1, int energy)
{
this.output = output;
this.input0 = input0;
this.input1 = input1;
this.totalProcessEnergy = (int)Math.floor(energy*energyModifier);
this.totalProcessTime = (int)Math.floor(1*timeModifier);
this.fluidInputList = Lists.newArrayList(this.input0,this.input1);
this.fluidOutputList = Lists.newArrayList(this.output);
}
public static ArrayList<RefineryRecipe> recipeList = new ArrayList();
public static RefineryRecipe addRecipe(FluidStack output, FluidStack input0, FluidStack input1, int energy)
{
RefineryRecipe r = new RefineryRecipe(output, input0, input1, energy);
recipeList.add(r);
return r;
}
public static RefineryRecipe findRecipe(FluidStack input0, FluidStack input1)
{
for(RefineryRecipe recipe : recipeList)
{
if(input0!=null)
{
if(recipe.input0!=null && input0.containsFluid(recipe.input0))
{
if((recipe.input1==null&&input1==null) || (recipe.input1!=null&&input1!=null&&input1.containsFluid(recipe.input1)))
return recipe;
}
if(recipe.input1!=null && input0.containsFluid(recipe.input1))
{
if((recipe.input0==null&&input1==null) || (recipe.input0!=null&&input1!=null&&input1.containsFluid(recipe.input0)))
return recipe;
}
}
else if(input1!=null)
{
if(recipe.input0!=null && input1.containsFluid(recipe.input0) && recipe.input1==null)
return recipe;
if(recipe.input1!=null && input1.containsFluid(recipe.input1) && recipe.input0==null)
return recipe;
}
}
return null;
}
public static List<RefineryRecipe> findIncompleteRefineryRecipe(FluidStack input0, FluidStack input1)
{
if(input0==null && input1==null)
return null;
List<RefineryRecipe> list = Lists.newArrayList();
for(RefineryRecipe recipe : recipeList)
{
if(input0!=null && input1==null)
{
if(input0.isFluidEqual(recipe.input0) || input0.isFluidEqual(recipe.input1))
{
list.add(recipe);
break;
}
}
else if(input0==null && input1!=null)
{
if(input1.isFluidEqual(recipe.input0) || input1.isFluidEqual(recipe.input1))
{
list.add(recipe);
break;
}
}
else if( (input0.isFluidEqual(recipe.input0)&&input1.isFluidEqual(recipe.input1)) || (input0.isFluidEqual(recipe.input1)&&input1.isFluidEqual(recipe.input0)) )
{
list.add(recipe);
break;
}
}
return list;
}
@Override
public int getMultipleProcessTicks()
{
return 0;
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt)
{
nbt.setTag("input0", input0.writeToNBT(new NBTTagCompound()));
nbt.setTag("input1", input1.writeToNBT(new NBTTagCompound()));
return nbt;
}
public static RefineryRecipe loadFromNBT(NBTTagCompound nbt)
{
FluidStack input0 = FluidStack.loadFluidStackFromNBT(nbt.getCompoundTag("input0"));
FluidStack input1 = FluidStack.loadFluidStackFromNBT(nbt.getCompoundTag("input1"));
return findRecipe(input0, input1);
}
}

View file

@ -1,112 +0,0 @@
package blusunrize.immersiveengineering.api.crafting;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import com.google.common.collect.Lists;
import blusunrize.immersiveengineering.api.ApiUtils;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
/**
* @author BluSunrize - 20.02.2016
*
* The recipe for the Squeezer
*/
public class SqueezerRecipe extends MultiblockRecipe
{
public static float energyModifier = 1;
public static float timeModifier = 1;
public final IngredientStack input;
public final FluidStack fluidOutput;
public final ItemStack itemOutput;
public SqueezerRecipe(FluidStack fluidOutput, ItemStack itemOutput, Object input, int energy)
{
this.fluidOutput = fluidOutput;
this.itemOutput = itemOutput;
this.input = ApiUtils.createIngredientStack(input);
this.totalProcessEnergy = (int)Math.floor(energy*energyModifier);
this.totalProcessTime = (int)Math.floor(80*timeModifier);
this.inputList = Lists.newArrayList(this.input);
this.fluidOutputList = Lists.newArrayList(this.fluidOutput);
this.outputList = Lists.newArrayList(this.itemOutput);
}
public SqueezerRecipe setInputSize(int size)
{
this.input.inputSize = size;
return this;
}
public static ArrayList<SqueezerRecipe> recipeList = new ArrayList();
public static SqueezerRecipe addRecipe(FluidStack fluidOutput, ItemStack itemOutput, Object input, int energy)
{
SqueezerRecipe r = new SqueezerRecipe(fluidOutput, itemOutput, input, energy);
recipeList.add(r);
return r;
}
public static SqueezerRecipe findRecipe(ItemStack input)
{
if(input==null)
return null;
for(SqueezerRecipe recipe : recipeList)
if(recipe.input.matches(input))
return recipe;
return null;
}
// public static List<SqueezerRecipe> removeRecipes(ItemStack output)
// {
// List<SqueezerRecipe> list = new ArrayList();
// for(ComparableItemStack mold : recipeList.keySet())
// {
// Iterator<SqueezerRecipe> it = recipeList.get(mold).iterator();
// while(it.hasNext())
// {
// SqueezerRecipe ir = it.next();
// if(OreDictionary.itemMatches(ir.output, output, true))
// {
// list.add(ir);
// it.remove();
// }
// }
// }
// return list;
// }
@Override
public int getMultipleProcessTicks()
{
return 0;
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt)
{
nbt.setTag("input", input.writeToNBT(new NBTTagCompound()));
return nbt;
}
public static SqueezerRecipe loadFromNBT(NBTTagCompound nbt)
{
IngredientStack input = IngredientStack.readFromNBT(nbt.getCompoundTag("input"));
for(SqueezerRecipe recipe : recipeList)
if(recipe.input.equals(input))
return recipe;
return null;
}
public static Map<String, Integer> getFluidValuesSorted(Fluid f, boolean inverse)
{
HashMap<String, Integer> map = new HashMap<String, Integer>();
for(SqueezerRecipe recipe : recipeList)
if(recipe.fluidOutput!=null && recipe.fluidOutput.getFluid()==f)
{
ItemStack is = recipe.input.getExampleStack();
map.put(is.getDisplayName(), recipe.fluidOutput.amount);
}
return ApiUtils.sortMap(map, inverse);
}
}

View file

@ -1,175 +0,0 @@
package blusunrize.immersiveengineering.api.energy;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import blusunrize.immersiveengineering.api.ApiUtils;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
/**
* @author BluSunrize - 23.04.2015
*
* The Fuel Handler for the Diesel Generator. Use this to register custom fuels
*/
public class DieselHandler
{
static HashMap<String, Integer> dieselGenBurnTime = new HashMap<String, Integer>();
static Set<Fluid> drillFuel = new HashSet<Fluid>();
/**
* @param fuel the fluid to be used as fuel
* @param time the total burn time gained from 1000 mB
*/
public static void registerFuel(Fluid fuel, int time)
{
if(fuel!=null)
dieselGenBurnTime.put(fuel.getName(), time);
}
public static int getBurnTime(Fluid fuel)
{
if(fuel!=null)
return dieselGenBurnTime.get(fuel.getName());
return 0;
}
public static boolean isValidFuel(Fluid fuel)
{
if(fuel!=null)
return dieselGenBurnTime.containsKey(fuel.getName());
return false;
}
public static HashMap<String, Integer> getFuelValues()
{
return dieselGenBurnTime;
}
public static Map<String, Integer> getFuelValuesSorted(boolean inverse)
{
return ApiUtils.sortMap(dieselGenBurnTime, inverse);
}
public static void registerDrillFuel(Fluid fuel)
{
if(fuel!=null)
drillFuel.add(fuel);
}
public static boolean isValidDrillFuel(Fluid fuel)
{
return fuel!=null && drillFuel.contains(fuel);
}
// static HashMap<String, Integer> ethanolOutput = new HashMap<String, Integer>();
// /**
// * @param input either itemstack or OreDictionary name
// * @param output the output of ethanol in mB per item
// */
// public static void registerEthanolSource(Object input, int output)
// {
// if(input instanceof String)
// ethanolOutput.put((String)input, output);
// else
// {
// if(input instanceof Item)
// input = new ItemStack((Item)input);
// if(input instanceof Block)
// input = new ItemStack((Block)input);
// if(input instanceof ItemStack && !ApiUtils.nameFromStack((ItemStack)input).isEmpty())
// ethanolOutput.put(ApiUtils.nameFromStack((ItemStack)input)+"::"+((ItemStack)input).getItemDamage(), output);
// }
// }
// public static int getEthanolOutput(ItemStack stack)
// {
// for(Map.Entry<String,Integer> e : ethanolOutput.entrySet())
// if(ApiUtils.compareToOreName(stack, e.getKey()))
// return e.getValue();
// else
// {
// int lIndx = e.getKey().lastIndexOf("::");
// if(lIndx>0)
// {
// String key = e.getKey().substring(0,lIndx);
// try{
// int reqMeta = Integer.parseInt(e.getKey().substring(lIndx+2));
// if(key.equals(ApiUtils.nameFromStack(stack)) && (reqMeta==OreDictionary.WILDCARD_VALUE || reqMeta==stack.getItemDamage()))
// return e.getValue();
// }catch(Exception exception){}
// }
// }
// return 0;
// }
// public static HashMap<String, Integer> getEthanolValues()
// {
// return ethanolOutput;
// }
// public static Map<String, Integer> getEthanolValuesSorted(boolean inverse)
// {
// return ApiUtils.sortMap(ethanolOutput, inverse);
// }
public static class RefineryRecipe
{
public final FluidStack input0;
public final FluidStack input1;
public final FluidStack output;
public RefineryRecipe(FluidStack input0, FluidStack input1, FluidStack output)
{
this.input0 = input0;
this.input1 = input1;
this.output = output;
}
}
public static ArrayList<RefineryRecipe> refineryList = new ArrayList<RefineryRecipe>();
public static void addRefineryRecipe(FluidStack input0, FluidStack input1, FluidStack output)
{
refineryList.add(new RefineryRecipe(input0, input1, output));
}
public static RefineryRecipe findIncompleteRefineryRecipe(FluidStack input0, FluidStack input1)
{
if(input0==null && input1==null)
return null;
for(RefineryRecipe recipe : refineryList)
{
if(input0!=null && input1==null)
{
if(input0.isFluidEqual(recipe.input0) || input0.isFluidEqual(recipe.input1))
return recipe;
}
else if(input0==null && input1!=null)
{
if(input1.isFluidEqual(recipe.input0) || input1.isFluidEqual(recipe.input1))
return recipe;
}
else if( (input0.isFluidEqual(recipe.input0)&&input1.isFluidEqual(recipe.input1)) || (input0.isFluidEqual(recipe.input1)&&input1.isFluidEqual(recipe.input0)) )
return recipe;
}
return null;
}
public static RefineryRecipe findRefineryRecipe(FluidStack input0, FluidStack input1)
{
if(input0==null || input1==null)
return null;
for(RefineryRecipe recipe : refineryList)
{
if( (input0.isFluidEqual(recipe.input0)&&input1.isFluidEqual(recipe.input1)) || (input0.isFluidEqual(recipe.input1)&&input1.isFluidEqual(recipe.input0)) )
return recipe;
}
return null;
}
// public static List<RefineryRecipe> removeFermenterRecipes(ItemStack stack)
// {
// List<RefineryRecipe> list = new ArrayList();
// Iterator<RefineryRecipe> it = fermenterList.iterator();
// while(it.hasNext())
// {
// RefineryRecipe ir = it.next();
// if(OreDictionary.itemMatches(ir.output, stack, true))
// {
// list.add(ir);
// it.remove();
// }
// }
// return list;
// }
}

View file

@ -1,51 +0,0 @@
package blusunrize.immersiveengineering.api.energy;
import java.util.HashMap;
import java.util.Map;
import blusunrize.immersiveengineering.api.ApiUtils;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
/**
* @author BluSunrize - 08.05.2015
*
* The temperature registry to allow additional blocks to work with the Thermoelectric Generator<br>
* Register either OreDictionary names or
*/
public class ThermoelectricHandler
{
static HashMap<String, Integer> temperatureMap = new HashMap<String, Integer>();
public static void registerSourceInKelvin(String source, int value)
{
temperatureMap.put(source, value);
}
public static void registerSourceInCelsius(String source, int value)
{
temperatureMap.put(source, value+273);
}
/** 'murica!
*/
public static void registerSourceInFarenheit(String source, int value)
{
temperatureMap.put(source, (int)Math.round((value-32)/1.8D +273) );
}
public static int getTemperature(Block block, int meta)
{
ItemStack stack = new ItemStack(block, 1, meta);
if (stack.getItem()!=null)
for(int oreID : OreDictionary.getOreIDs(stack))
if(temperatureMap.containsKey(OreDictionary.getOreName(oreID)))
return temperatureMap.get(OreDictionary.getOreName(oreID));
// if(temperatureMap.containsKey(ApiUtils.nameFromStack(new ItemStack(block, 1, meta))+"::"+meta))
// return temperatureMap.get(ApiUtils.nameFromStack(new ItemStack(block, 1, meta))+"::"+meta);
return -1;
}
public static Map<String, Integer> getThermalValuesSorted(boolean inverse)
{
return ApiUtils.sortMap(temperatureMap, inverse);
}
}

View file

@ -1,124 +0,0 @@
package blusunrize.immersiveengineering.api.energy.immersiveflux;
import net.minecraft.nbt.NBTTagCompound;
/**
* A simple storage object for IF and an example implementation of {@link IFluxStorage}.
*
* @author BluSunrize - 18.01.2016
*
*/
public class FluxStorage implements IFluxStorage
{
protected int energy;
protected int capacity;
protected int limitReceive;
protected int limitExtract;
public FluxStorage(int capacity, int limitReceive, int limitExtract)
{
this.capacity = capacity;
this.limitReceive = limitReceive;
this.limitExtract = limitExtract;
}
public FluxStorage(int capacity, int limitTransfer)
{
this(capacity, limitTransfer, limitTransfer);
}
public FluxStorage(int capacity)
{
this(capacity, capacity, capacity);
}
public FluxStorage readFromNBT(NBTTagCompound nbt)
{
this.energy = nbt.getInteger("ifluxEnergy");
if(energy>capacity)
energy = capacity;
return this;
}
public NBTTagCompound writeToNBT(NBTTagCompound nbt)
{
if(energy<0)
energy = 0;
nbt.setInteger("ifluxEnergy", energy);
return nbt;
}
public void setCapacity(int capacity)
{
this.capacity = capacity;
if(energy>capacity)
energy = capacity;
}
public void setLimitTransfer(int limitTransfer)
{
setLimitReceive(limitTransfer);
setMaxExtract(limitTransfer);
}
public void setLimitReceive(int limitReceive)
{
this.limitReceive = limitReceive;
}
public void setMaxExtract(int limitExtract)
{
this.limitExtract = limitExtract;
}
public int getLimitReceive()
{
return limitReceive;
}
public int getLimitExtract()
{
return limitExtract;
}
public void setEnergy(int energy)
{
this.energy = energy;
if (this.energy>capacity)
this.energy = capacity;
else if (this.energy<0)
this.energy = 0;
}
public void modifyEnergyStored(int energy)
{
this.energy += energy;
if(this.energy>capacity)
this.energy = capacity;
else if(this.energy<0)
this.energy = 0;
}
@Override
public int receiveEnergy(int energy, boolean simulate)
{
int received = Math.min(capacity-this.energy, Math.min(this.limitReceive, energy));
if(!simulate)
this.energy += received;
return received;
}
@Override
public int extractEnergy(int energy, boolean simulate)
{
int extracted = Math.min(this.energy, Math.min(this.limitExtract, energy));
if(!simulate)
this.energy -= extracted;
return extracted;
}
@Override
public int getEnergyStored()
{
return energy;
}
@Override
public int getMaxEnergyStored()
{
return capacity;
}
}

View file

@ -1,53 +0,0 @@
package blusunrize.immersiveengineering.api.energy.immersiveflux;
/**
* An advanced implementation of {@link IFluxStorage}, keeps track of the last 20 in- and outputs to allow transfer evaluation.
*
* @author BluSunrize - 02.02.2016
*
*/
public class FluxStorageAdvanced extends FluxStorage
{
int averageInsertion=0;
int averageExtraction=0;
public FluxStorageAdvanced(int capacity, int limitReceive, int limitExtract)
{
super(capacity, limitReceive, limitExtract);
}
public FluxStorageAdvanced(int capacity, int limitTransfer)
{
super(capacity, limitTransfer);
}
public FluxStorageAdvanced(int capacity)
{
super(capacity, capacity, capacity);
}
@Override
public int receiveEnergy(int energy, boolean simulate)
{
int received = super.receiveEnergy(energy,simulate);
if(!simulate)
averageInsertion = averageInsertion/2 + received/2;
return received;
}
@Override
public int extractEnergy(int energy, boolean simulate)
{
int extracted = super.extractEnergy(energy, simulate);
if(!simulate)
averageExtraction = averageInsertion/2 + extracted/2;
return extracted;
}
public int getAverageInsertion()
{
return averageInsertion;
}
public int getAverageExtraction()
{
return averageExtraction;
}
}

View file

@ -1,20 +0,0 @@
package blusunrize.immersiveengineering.api.energy.immersiveflux;
import javax.annotation.Nullable;
import net.minecraft.util.EnumFacing;
/**
* An interface to be implemented by TileEntities that can connect to an IF network
*
* @author BluSunrize - 18.01.2016
*
*/
public interface IFluxConnection
{
/**
* @param from The direction the check is performed from, null for unknown.
* @return If the TileEntity can connect.
*/
boolean canConnectEnergy(@Nullable EnumFacing from);
}

View file

@ -1,42 +0,0 @@
package blusunrize.immersiveengineering.api.energy.immersiveflux;
import net.minecraft.item.ItemStack;
/**
* An interface to be implemented by Items that can store IF and allow external modification of their storage.
*
* @author BluSunrize - 18.01.2016
*
*/
public interface IFluxContainerItem
{
/**
* Inserts energy into the Item. Returns the amount that was accepted.
* @param container The ItemStack of the container item
* @param energy Maximum amount of energy to be inserted.
* @param simulate If TRUE, the process is simulated and will not increase the storage.
* @return Amount of energy that was, or would have been, if simulated, accepted.
*/
int receiveEnergy(ItemStack container, int energy, boolean simulate);
/**
* Extracts energy from the Item. Returns the amount that was extracted.
* @param container The ItemStack of the container item
* @param energy Maximum amount of energy to be extracted.
* @param simulate If TRUE, the process is simulated and will not decrease the storage.
* @return Amount of energy that was, or would have been, if simulated, extracted.
*/
int extractEnergy(ItemStack container, int energy, boolean simulate);
/**
* @param container The ItemStack of the container item
* @return The amount of energy stored in the Tile.
*/
int getEnergyStored(ItemStack container);
/**
* @param container The ItemStack of the container item
* @return The maximum amount of energy that can be stored in the Tile.
*/
int getMaxEnergyStored(ItemStack container);
}

View file

@ -1,35 +0,0 @@
package blusunrize.immersiveengineering.api.energy.immersiveflux;
import javax.annotation.Nullable;
import net.minecraft.util.EnumFacing;
/**
* An interface to be implemented by TileEntities that can provide IF.
*
* @author BluSunrize - 18.01.2016
*
*/
public interface IFluxProvider extends IFluxConnection
{
/**
* Extracts energy from the TileEntity. Returns the amount that was extracted.
* @param from The direction the energy is inserted from, null for unknown. Unknown directions should ALWAYS work.
* @param energy Maximum amount of energy to be extracted.
* @param simulate If TRUE, the process is simulated and will not decrease the storage.
* @return Amount of energy that was, or would have been, if simulated, extracted.
*/
int extractEnergy(@Nullable EnumFacing from, int energy, boolean simulate);
/**
* @param from The direction the check is performed from, null for unknown.
* @return The amount of energy stored in the Tile.
*/
int getEnergyStored(@Nullable EnumFacing from);
/**
* @param from The direction the check is performed from, null for unknown.
* @return The maximum amount of energy that can be stored in the Tile.
*/
int getMaxEnergyStored(@Nullable EnumFacing from);
}

View file

@ -1,35 +0,0 @@
package blusunrize.immersiveengineering.api.energy.immersiveflux;
import javax.annotation.Nullable;
import net.minecraft.util.EnumFacing;
/**
* An interface to be implemented by TileEntities that can receive IF.
*
* @author BluSunrize - 18.01.2016
*
*/
public interface IFluxReceiver extends IFluxConnection
{
/**
* Inserts energy into the TileEntity. Returns the amount that was accepted.
* @param from The direction the energy is inserted from, null for unknown. Unknown directions should ALWAYS work.
* @param energy Maximum amount of energy to be inserted.
* @param simulate If TRUE, the process is simulated and will not increase the storage.
* @return Amount of energy that was, or would have been, if simulated, accepted.
*/
int receiveEnergy(@Nullable EnumFacing from, int energy, boolean simulate);
/**
* @param from The direction the check is performed from, null for unknown.
* @return The amount of energy stored in the Tile.
*/
int getEnergyStored(@Nullable EnumFacing from);
/**
* @param from The direction the check is performed from, null for unknown.
* @return The maximum amount of energy that can be stored in the Tile.
*/
int getMaxEnergyStored(@Nullable EnumFacing from);
}

View file

@ -1,37 +0,0 @@
package blusunrize.immersiveengineering.api.energy.immersiveflux;
/**
* An interface to implement for an object that stores ImmersiveFlux<br>
* See {@link FluxStorage} for an example implementation
*
* @author BluSunrize - 18.01.2016
*
*/
public interface IFluxStorage
{
/**
* Inserts energy into the storage. Returns the amount that was accepted.
* @param energy Maximum amount of energy to be inserted.
* @param simulate If TRUE, the process is simulated and will not increase the storage.
* @return Amount of energy that was, or would have been, if simulated, accepted.
*/
int receiveEnergy(int energy, boolean simulate);
/**
* Extracts energy from the storage. Returns the amount that was extracted.
* @param energy Maximum amount of energy to be extracted.
* @param simulate If TRUE, the process is simulated and will not decrease the storage.
* @return Amount of energy that was, or would have been, if simulated, extracted.
*/
int extractEnergy(int energy, boolean simulate);
/**
* @return The amount of energy stored.
*/
int getEnergyStored();
/**
* @return The maximum amount of energy that can be stored.
*/
int getMaxEnergyStored();
}

View file

@ -1,10 +0,0 @@
@API(owner = "ImmersiveEngineering", apiVersion = "1.0", provides = "ImmersiveEngineering|ImmersiveFluxAPI")
package blusunrize.immersiveengineering.api.energy.immersiveflux;
import net.minecraftforge.fml.common.API;
/**
* Shoutout to Team CoFH for the amazing RedstoneFlux system.<br>
* Due to a lack of an official 1.8 version, IE has been move to its own, RF-inspired energy system, dubbed ImmersiveFlux.
*
*/

View file

@ -1,122 +0,0 @@
package blusunrize.immersiveengineering.api.energy.wires;
import blusunrize.immersiveengineering.api.TargetingInfo;
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection;
import blusunrize.immersiveengineering.common.util.IELogger;
import blusunrize.immersiveengineering.common.util.Utils;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.FMLCommonHandler;
public class IICProxy implements IImmersiveConnectable
{
private boolean canEnergyPass;
private int dim;
private BlockPos pos;
public IICProxy(boolean allowPass, int dimension, BlockPos _pos)
{
canEnergyPass = allowPass;
dim = dimension;
pos = _pos;
}
public IICProxy(TileEntity te)
{
if (!(te instanceof IImmersiveConnectable))
throw new IllegalArgumentException("Can't create an IICProxy for a null/non-IIC TileEntity");
dim = te.getWorld().provider.getDimension();
canEnergyPass = ((IImmersiveConnectable)te).allowEnergyToPass(null);
pos = Utils.toCC(te);
}
@Override
public boolean allowEnergyToPass(Connection c)
{
return canEnergyPass;
}
public BlockPos getPos()
{
return pos;
}
public int getDimension()
{
return dim;
}
@Override
public void removeCable(Connection connection)
{
//this will load the chunk the TE is in for 1 tick since it needs to be notified about the removed wires
World w = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(dim);
if (w==null)
{
IELogger.warn("Tried to remove a wire in dimension "+dim+" which does not exist");
return;
}
TileEntity te = w.getTileEntity(pos);
if (!(te instanceof IImmersiveConnectable))
return;
((IImmersiveConnectable)te).removeCable(connection);
}
@Override
public boolean canConnect()
{
return false;
}
@Override
public boolean isEnergyOutput()
{
return false;
}
@Override
public int outputEnergy(int amount, boolean simulate, int energyType)
{
return 0;
}
@Override
public boolean canConnectCable(WireType cableType, TargetingInfo target)
{
return false;
}
@Override
public void connectCable(WireType cableType, TargetingInfo target)
{}
@Override
public WireType getCableLimiter(TargetingInfo target)
{
return null;
}
@Override
public void onEnergyPassthrough(int amount)
{}
@Override
public Vec3d getRaytraceOffset(IImmersiveConnectable link)
{
return null;
}
@Override
public Vec3d getConnectionOffset(Connection con)
{
return null;
}
public static IICProxy readFromNBT(NBTTagCompound nbt)
{
return new IICProxy(nbt.getBoolean("pass"), nbt.getInteger("dim"), new BlockPos(nbt.getInteger("x"), nbt.getInteger("y"), nbt.getInteger("z")));
}
public NBTTagCompound writeToNBT()
{
NBTTagCompound ret = new NBTTagCompound();
ret.setInteger("dim", dim);
ret.setInteger("x", pos.getX());
ret.setInteger("y", pos.getY());
ret.setInteger("z", pos.getZ());
ret.setBoolean("pass", canEnergyPass);
return ret;
}
@Override
public BlockPos getConnectionMaster(WireType cableType, TargetingInfo target)
{
return pos;
}
}

View file

@ -1,92 +0,0 @@
package blusunrize.immersiveengineering.api.energy.wires;
import java.util.Set;
import com.google.common.collect.ImmutableSet;
import blusunrize.immersiveengineering.api.ApiUtils;
import blusunrize.immersiveengineering.api.TargetingInfo;
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
/**
* @author BluSunrize - 08.03.2015
*
* An interface to be implemented by TileEntities, to allow them to connect to the IE net
*/
public interface IImmersiveConnectable
{
/**
* @return if wires can directly connect to this
*/
boolean canConnect();
/**
* @return if the tile can in or output energy from/to the network
*/
boolean isEnergyOutput();
/**
* @param amount The amount of power input, in RF
* @param simulate whether to actually perform the action or just simulate energy consumption
* @param energyType 0 for RF, 1 for EU
* @return the amount of power that was output
*/
int outputEnergy(int amount, boolean simulate, int energyType);
/**
* @return a blockPos to do the connection check for.<br>For multiblocks like transformers
*/
BlockPos getConnectionMaster(WireType cableType, TargetingInfo target);
/**
* @return whether you can connect the given CableType to the tile
*/
boolean canConnectCable(WireType cableType, TargetingInfo target);
/**
* fired when a cable is attached, use to limit the cables attached to one type
*/
void connectCable(WireType cableType, TargetingInfo target);
/**
* get the CableType limiter of the tile
*/
WireType getCableLimiter(TargetingInfo target);
/**
* return false to stop checking for available outputs from this point onward
* @param con: the connection through which energy enters. May be null, in that
* case true should be returned if and only if all connections allow energy to pass
*/
boolean allowEnergyToPass(Connection con);
/**
* fired for every not-simulated energy packet passing through. Used for energy meter and stuff
*/
void onEnergyPassthrough(int amount);
/**
* used to reset the CableType limiter of the tile, provided it matches the given argument
* acts as a wildcard, meaning if connection.CableType is null, you /always/ reset the limiter
*/
void removeCable(Connection connection);
/**
* @return the offset used when RayTracing to or from this block. This vector is based from the blocks /origin/
*/
Vec3d getRaytraceOffset(IImmersiveConnectable link);
/**
* Used for rendering only
* @return Where the cable should attach
*/
Vec3d getConnectionOffset(Connection con);
/**
* returns a set of Blocks to be ignored when raytracing
*/
default Set<BlockPos> getIgnored(IImmersiveConnectable other)
{
return ImmutableSet.of(ApiUtils.toBlockPos(this));
}
}

View file

@ -1,13 +0,0 @@
package blusunrize.immersiveengineering.api.energy.wires;
import net.minecraft.item.ItemStack;
/**
* @author BluSunrize - 26.06.2015
*
* An Interface to be implemented by Items that can be used to connect two connectors
*/
public interface IWireCoil
{
WireType getWireType(ItemStack stack);
}

View file

@ -1,564 +0,0 @@
package blusunrize.immersiveengineering.api.energy.wires;
import blusunrize.immersiveengineering.api.ApiUtils;
import blusunrize.immersiveengineering.api.DimensionBlockPos;
import blusunrize.immersiveengineering.api.TargetingInfo;
// import blusunrize.immersiveengineering.client.models.smart.ConnModelReal;
import blusunrize.immersiveengineering.common.IESaveData;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.relauncher.Side;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import static blusunrize.immersiveengineering.api.ApiUtils.*;
import static java.util.Collections.newSetFromMap;
public class ImmersiveNetHandler
{
public static ImmersiveNetHandler INSTANCE;
public Map<Integer, ConcurrentHashMap<BlockPos, Set<Connection>>> directConnections = new ConcurrentHashMap<>();
public Map<BlockPos, Set<AbstractConnection>> indirectConnections = new ConcurrentHashMap<>();
public Map<Integer, HashMap<Connection, Integer>> transferPerTick = new HashMap<>();
public Map<DimensionBlockPos, IICProxy> proxies = new ConcurrentHashMap<>();
private ConcurrentHashMap<BlockPos, Set<Connection>> getMultimap(int dimension)
{
if (directConnections.get(dimension) == null)
{
ConcurrentHashMap<BlockPos, Set<Connection>> mm = new ConcurrentHashMap<BlockPos, Set<Connection>>();
directConnections.put(dimension, mm);
}
return directConnections.get(dimension);
}
public HashMap<Connection, Integer> getTransferedRates(int dimension)
{
if (!transferPerTick.containsKey(dimension))
transferPerTick.put(dimension, new HashMap<Connection,Integer>());
return transferPerTick.get(dimension);
}
public void addConnection(World world, BlockPos node, BlockPos connection, int distance, WireType cableType)
{
if(!getMultimap(world.provider.getDimension()).containsKey(node))
getMultimap(world.provider.getDimension()).put(node, newSetFromMap(new ConcurrentHashMap<Connection, Boolean>()));
getMultimap(world.provider.getDimension()).get(node).add(new Connection(node, connection, cableType, distance));
if(!getMultimap(world.provider.getDimension()).containsKey(connection))
getMultimap(world.provider.getDimension()).put(connection, newSetFromMap(new ConcurrentHashMap<Connection, Boolean>()));
getMultimap(world.provider.getDimension()).get(connection).add(new Connection(connection, node, cableType, distance));
resetCachedIndirectConnections();
if(world.isBlockLoaded(node))
world.addBlockEvent(node, world.getBlockState(node).getBlock(),-1,0);
if(world.isBlockLoaded(connection))
world.addBlockEvent(connection, world.getBlockState(connection).getBlock(),-1,0);
IESaveData.setDirty(world.provider.getDimension());
}
public void addConnection(World world, BlockPos node, Connection con)
{
if(!getMultimap(world.provider.getDimension()).containsKey(node))
getMultimap(world.provider.getDimension()).put(node, newSetFromMap(new ConcurrentHashMap<Connection, Boolean>()));
getMultimap(world.provider.getDimension()).get(node).add(con);
resetCachedIndirectConnections();
IESaveData.setDirty(world.provider.getDimension());
}
public void addConnection(int world, BlockPos node, Connection con)
{
if(!getMultimap(world).containsKey(node))
getMultimap(world).put(node, newSetFromMap(new ConcurrentHashMap<Connection, Boolean>()));
getMultimap(world).get(node).add(con);
resetCachedIndirectConnections();
IESaveData.setDirty(world);
}
public void removeConnection(World world, Connection con)
{
if(con==null||world==null)
return;
for (Set<Connection> conl : getMultimap(world.provider.getDimension()).values())
{
Iterator<Connection> it = conl.iterator();
while(it.hasNext())
{
Connection itCon = it.next();
if(con.hasSameConnectors(itCon))
{
it.remove();
IImmersiveConnectable iic = toIIC(itCon.end, world);
if(iic!=null)
iic.removeCable(itCon);
iic = toIIC(itCon.start, world);
if(iic!=null)
iic.removeCable(itCon);
if(world.isBlockLoaded(itCon.start))
world.addBlockEvent(itCon.start, world.getBlockState(itCon.start).getBlock(),-1,0);
if(world.isBlockLoaded(itCon.end))
world.addBlockEvent(itCon.end, world.getBlockState(itCon.end).getBlock(),-1,0);
}
}
}
resetCachedIndirectConnections();
IESaveData.setDirty(world.provider.getDimension());
}
public Set<Integer> getRelevantDimensions()
{
return directConnections.keySet();
}
public Collection<Connection> getAllConnections(World world)
{
Set<Connection> ret = newSetFromMap(new ConcurrentHashMap<Connection, Boolean>());
for (Set<Connection> conlist : getMultimap(world.provider.getDimension()).values())
ret.addAll(conlist);
return ret;
}
public synchronized Set<Connection> getConnections(World world, BlockPos node)
{
if(world!=null && world.provider!=null)
{
ConcurrentHashMap<BlockPos, Set<Connection>> map = getMultimap(world.provider.getDimension());
return map.get(node);
}
return null;
}
public void clearAllConnections(World world)
{
getMultimap(world.provider.getDimension()).clear();
}
public void clearAllConnections(int world)
{
getMultimap(world).clear();
}
public void clearConnectionsOriginatingFrom(BlockPos node, World world)
{
if(getMultimap(world.provider.getDimension()).containsKey(node))
getMultimap(world.provider.getDimension()).get(node).clear();
resetCachedIndirectConnections();
}
public void resetCachedIndirectConnections()
{
/* @TODO need proper API
if(FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER)
indirectConnections.clear();
else
ConnModelReal.cache.clear();
/**/
}
/**
* Clears all connections to and from this node.
*/
public void clearAllConnectionsFor(BlockPos node, World world, boolean doDrops)
{
if(getMultimap(world.provider.getDimension()).containsKey(node))
getMultimap(world.provider.getDimension()).get(node).clear();
IImmersiveConnectable iic = toIIC(node, world);
if(iic!=null)
iic.removeCable(null);
// ConcurrentSkipListSet<Connection> itlist = new ConcurrentSkipListSet<Connection>();
// for (ConcurrentSkipListSet<Connection> conl : getMultimap(world.provider.getDimension()).values())
// itlist.addAll(conl);
// Iterator<Connection> it = itlist.iterator();
for (Set<Connection> conl : getMultimap(world.provider.getDimension()).values())
{
Iterator<Connection> it = conl.iterator();
while(it.hasNext())
{
Connection con = it.next();
if(node.equals(con.start) || node.equals(con.end))
{
it.remove();
IImmersiveConnectable other;
if (node.equals(con.start))
other = toIIC(con.end, world);
else
other = toIIC(con.start, world);
if (iic!=null)
iic.removeCable(con);
if (other!=null)
other.removeCable(con);
if(node.equals(con.end))
{
double dx = node.getX()+.5+Math.signum(con.start.getX()-con.end.getX());
double dy = node.getY()+.5+Math.signum(con.start.getY()-con.end.getY());
double dz = node.getZ()+.5+Math.signum(con.start.getZ()-con.end.getZ());
if(doDrops&&world.getGameRules().getBoolean("doTileDrops"))
world.spawnEntityInWorld(new EntityItem(world, dx,dy,dz, con.cableType.getWireCoil()));
if(world.isBlockLoaded(con.start))
world.addBlockEvent(con.start, world.getBlockState(con.start).getBlock(),-1,0);
}
else
if(world.isBlockLoaded(con.end))
world.addBlockEvent(con.end, world.getBlockState(con.end).getBlock(),-1,0);
}
}
}
if(world.isBlockLoaded(node))
world.addBlockEvent(node, world.getBlockState(node).getBlock(),-1,0);
IESaveData.setDirty(world.provider.getDimension());
resetCachedIndirectConnections();
}
public void setProxy(DimensionBlockPos pos, IICProxy p)
{
if (p==null)
proxies.remove(pos);
else
proxies.put(pos, p);
}
public void addProxy(IICProxy p)
{
if (p==null)
return;
setProxy(new DimensionBlockPos(p.getPos(), p.getDimension()), p);
}
/**
* Clears all connections to and from this node.
* The TargetingInfo must not be null!
*/
public void clearAllConnectionsFor(BlockPos node, World world, TargetingInfo target)
{
IImmersiveConnectable iic = toIIC(node, world);
WireType type = target==null?null : iic.getCableLimiter(target);
if(type==null)
return;
for (Set<Connection> conl : getMultimap(world.provider.getDimension()).values())
{
Iterator<Connection> it = conl.iterator();
while(it.hasNext())
{
Connection con = it.next();
if(con.cableType==type)
if(node.equals(con.start) || node.equals(con.end))
{
it.remove();
IImmersiveConnectable other;
if (node.equals(con.start))
other = toIIC(con.end, world);
else
other = toIIC(con.start, world);
if (iic!=null)
iic.removeCable(con);
if (other!=null)
other.removeCable(con);
if(node.equals(con.end))
{
double dx = node.getX()+.5+Math.signum(con.start.getX()-con.end.getX());
double dy = node.getY()+.5+Math.signum(con.start.getY()-con.end.getY());
double dz = node.getZ()+.5+Math.signum(con.start.getZ()-con.end.getZ());
if(world.getGameRules().getBoolean("doTileDrops"))
world.spawnEntityInWorld(new EntityItem(world, dx,dy,dz, con.cableType.getWireCoil()));
if(world.isBlockLoaded(con.start))
world.addBlockEvent(con.start, world.getBlockState(con.start).getBlock(),-1,0);
}
else
if(world.isBlockLoaded(con.end))
world.addBlockEvent(con.end, world.getBlockState(con.end).getBlock(),-1,0);
}
}
}
if(world.isBlockLoaded(node))
world.addBlockEvent(node, world.getBlockState(node).getBlock(),-1,0);
IESaveData.setDirty(world.provider.getDimension());
resetCachedIndirectConnections();
}
/*
public static List<IImmersiveConnectable> getValidEnergyOutputs(BlockPos node, World world)
{
List<IImmersiveConnectable> openList = new ArrayList<IImmersiveConnectable>();
List<IImmersiveConnectable> closedList = new ArrayList<IImmersiveConnectable>();
List<BlockPos> checked = new ArrayList<BlockPos>();
HashMap<BlockPos,BlockPos> backtracker = new HashMap<BlockPos,BlockPos>();
checked.add(node);
for(Connection con : getConnections(world, node))
if(toIIC(con.end, world)!=null)
{
openList.add(toIIC(con.end, world));
backtracker.put(con.end, node);
}
IImmersiveConnectable next = null;
final int closedListMax = 1200;
while(closedList.size()<closedListMax && !openList.isEmpty())
{
next = openList.get(0);
if(!checked.contains(toCC(next)))
{
if(next.isEnergyOutput())
{
BlockPos last = toCC(next);
WireType averageType = null;
int distance = 0;
List<Connection> connectionParts = new ArrayList<Connection>();
while(last!=null)
{
BlockPos prev = last;
last = backtracker.get(last);
if(last!=null)
{
for(Connection conB : getConnections(world, prev))
if(conB.end.equals(toCC(last)))
{
connectionParts.add(conB);
distance += conB.length;
if(averageType==null || averageType.ordinal()>conB.cableType.ordinal())
averageType = conB.cableType;
break;
}
}
}
closedList.add(next);
}
for(Connection con : getConnections(world, toCC(next)))
if(toIIC(con.end, world)!=null && !checked.contains(con.end) && !closedList.contains(toIIC(con.end, world)) && !openList.contains(toIIC(con.end, world)))
{
openList.add(toIIC(con.end, world));
backtracker.put(con.end, toCC(next));
}
checked.add(toCC(next));
}
openList.remove(0);
}
return closedList;
}
*/
public Set<AbstractConnection> getIndirectEnergyConnections(BlockPos node, World world)
{
return getIndirectEnergyConnections(node, world, false);
}
/**
* return values are cached if and only if ignoreIsEnergyOutput is false
*/
public Set<AbstractConnection> getIndirectEnergyConnections(BlockPos node, World world, boolean ignoreIsEnergyOutput)
{
if(!ignoreIsEnergyOutput&&indirectConnections.containsKey(node))
return indirectConnections.get(node);
List<IImmersiveConnectable> openList = new ArrayList<IImmersiveConnectable>();
Set<AbstractConnection> closedList = newSetFromMap(new ConcurrentHashMap<AbstractConnection, Boolean>());
List<BlockPos> checked = new ArrayList<BlockPos>();
HashMap<BlockPos,BlockPos> backtracker = new HashMap<BlockPos,BlockPos>();
checked.add(node);
Set<Connection> conL = getConnections(world, node);
if(conL!=null)
for(Connection con : conL)
{
IImmersiveConnectable end = toIIC(con.end, world);
if(end!=null)
{
openList.add(end);
backtracker.put(con.end, node);
}
}
IImmersiveConnectable next = null;
final int closedListMax = 1200;
while(closedList.size()<closedListMax && !openList.isEmpty())
{
next = openList.get(0);
if(!checked.contains(toBlockPos(next)))
{
if(ignoreIsEnergyOutput||next.isEnergyOutput())
{
BlockPos last = toBlockPos(next);
WireType averageType = null;
int distance = 0;
List<Connection> connectionParts = new ArrayList<Connection>();
while(last!=null)
{
BlockPos prev = last;
last = backtracker.get(last);
if(last!=null)
{
Set<Connection> conLB = getConnections(world, last);
if(conLB!=null)
for(Connection conB : conLB)
if(conB.end.equals(prev))
{
connectionParts.add(0, conB);
distance += conB.length;
if(averageType==null || conB.cableType.getTransferRate()<averageType.getTransferRate())
averageType = conB.cableType;
break;
}
}
}
closedList.add(new AbstractConnection(toBlockPos(node), toBlockPos(next), averageType, distance, connectionParts.toArray(new Connection[connectionParts.size()])));
}
Set<Connection> conLN = getConnections(world, toBlockPos(next));
if(conLN!=null)
for(Connection con : conLN)
if(next.allowEnergyToPass(con))
{
IImmersiveConnectable end = toIIC(con.end, world);
if(end!=null && !checked.contains(con.end) && !openList.contains(end))
{
openList.add(end);
backtracker.put(con.end, toBlockPos(next));
}
}
checked.add(toBlockPos(next));
}
openList.remove(0);
}
if(!ignoreIsEnergyOutput&&FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER)
{
if(!indirectConnections.containsKey(node))
indirectConnections.put(node, newSetFromMap(new ConcurrentHashMap<AbstractConnection, Boolean>()));
indirectConnections.get(node).addAll(closedList);
}
return closedList;
}
public static class Connection implements Comparable<Connection>
{
public BlockPos start;
public BlockPos end;
public WireType cableType;
public int length;
public Vec3d[] catenaryVertices;
public static final int vertices = 17;
public Connection(BlockPos start, BlockPos end, WireType cableType, int length)
{
this.start=start;
this.end=end;
this.cableType=cableType;
this.length=length;
}
public boolean hasSameConnectors(Connection o) {
if(!(o instanceof Connection))
return false;
Connection con = o;
boolean n0 = start.equals(con.start)&&end.equals(con.end);
boolean n1 =start.equals(con.end)&&end.equals(con.start);
return n0||n1;
}
public Vec3d[] getSubVertices(World world)
{
if(catenaryVertices==null)
{
Vec3d vStart = new Vec3d(start.getX(),start.getY(),start.getZ());
Vec3d vEnd = new Vec3d(end.getX(), end.getY(), end.getZ());
IImmersiveConnectable iicStart = toIIC(start, world);
IImmersiveConnectable iicEnd = toIIC(end, world);
if(iicStart!=null)
vStart = addVectors(vStart, iicStart.getConnectionOffset(this));
if(iicEnd!=null)
vEnd = addVectors(vEnd, iicEnd.getConnectionOffset(this));
catenaryVertices = getConnectionCatenary(this, vStart, vEnd);
}
return catenaryVertices;
}
public NBTTagCompound writeToNBT()
{
NBTTagCompound tag = new NBTTagCompound();
if(start!=null)
tag.setIntArray("start", new int[]{start.getX(),start.getY(),start.getZ()});
if(end!=null)
tag.setIntArray("end", new int[]{end.getX(),end.getY(),end.getZ()});
tag.setString("cableType", cableType.getUniqueName());
tag.setInteger("length", length);
return tag;
}
public static Connection readFromNBT(NBTTagCompound tag)
{
if(tag==null)
return null;
int[] iStart = tag.getIntArray("start");
BlockPos start = new BlockPos(iStart[0],iStart[1],iStart[2]);
int[] iEnd = tag.getIntArray("end");
BlockPos end = new BlockPos(iEnd[0],iEnd[1],iEnd[2]);
WireType type = ApiUtils.getWireTypeFromNBT(tag, "cableType");
if(start!=null && end!=null && type!=null)
return new Connection(start,end, type, tag.getInteger("length"));
return null;
}
@Override
public int compareTo(Connection o)
{
if(equals(o))
return 0;
int distComp = Integer.compare(length, o.length);
int cableComp = -1*Integer.compare(cableType.getTransferRate(), o.cableType.getTransferRate());
if(cableComp!=0)
return cableComp;
if (distComp!=0)
return distComp;
if (start.getX()!=o.start.getX())
return start.getX()>o.start.getX()?1:-1;
if (start.getY()!=o.start.getY())
return start.getY()>o.start.getY()?1:-1;
if (start.getZ()!=o.start.getZ())
return start.getZ()>o.start.getZ()?1:-1;
if (end.getX()!=o.end.getX())
return end.getX()>o.end.getX()?1:-1;
if (end.getY()!=o.end.getY())
return end.getY()>o.end.getY()?1:-1;
if (end.getZ()!=o.end.getZ())
return end.getZ()>o.end.getZ()?1:-1;
return 0;
}
}
public static class AbstractConnection extends Connection
{
public Connection[] subConnections;
public AbstractConnection(BlockPos start, BlockPos end, WireType cableType, int length, Connection... subConnections)
{
super(start,end,cableType,length);
this.subConnections=subConnections;
}
public float getPreciseLossRate(int energyInput, int connectorMaxInput)
{
float f = 0;
for(Connection c : subConnections)
{
float length = c.length/(float)c.cableType.getMaxLength();
float baseLoss = (float)c.cableType.getLossRatio();
float mod = (((connectorMaxInput-energyInput)/(float)connectorMaxInput)/.25f)*.1f;
f += length*(baseLoss+baseLoss*mod);
}
return Math.min(f,1);
}
public float getAverageLossRate()
{
float f = 0;
for(Connection c : subConnections)
{
float length = c.length/(float)c.cableType.getMaxLength();
float baseLoss = (float)c.cableType.getLossRatio();
f += length*baseLoss;
}
return Math.min(f,1);
}
}
}

View file

@ -1,134 +0,0 @@
package blusunrize.immersiveengineering.api.energy.wires;
import java.util.LinkedHashSet;
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
/**
* @author BluSunrize - 08.03.2015<br>
* Rewritten: 26.06.2015
* <br>
* The WireTypes of IE. Extend this to make your own
*/
public abstract class WireType
{
private static LinkedHashSet<WireType> values = new LinkedHashSet<WireType>();
public static LinkedHashSet<WireType> getValues()
{
return values;
}
public static WireType getValue(String name)
{
for(WireType type: values)
if(type!=null && type.getUniqueName().equals(name))
return type;
return COPPER;
}
public WireType()
{
values.add(this);
}
public abstract String getUniqueName();
public abstract double getLossRatio();
public abstract int getTransferRate();
/**Try not to get to complex with determining colour here*/
public abstract int getColour(Connection connection);
/**Determines how saggy the wire is*/
public abstract double getSlack();
@SideOnly(Side.CLIENT)
public abstract TextureAtlasSprite getIcon(Connection connection);
public abstract int getMaxLength();
public abstract ItemStack getWireCoil();
public abstract double getRenderDiameter();
public abstract boolean isEnergyWire();
//THESE VALUES ARE FOR IE's OWN WIRES!
public static String[] uniqueNames = {"COPPER","ELECTRUM","STEEL","STRUCTURE_ROPE","STRUCTURE_STEEL"};
public static double[] wireLossRatio;
public static int[] wireTransferRate;
public static int[] wireColouration;
public static int[] wireLength;
public static Item ieWireCoil;
public static double[] renderDiameter = {.03125,.03125, .0625,.0625,.0625};
@SideOnly(Side.CLIENT)
public static TextureAtlasSprite iconDefaultWire;
public static WireType COPPER = new IEBASE(0);
public static WireType ELECTRUM = new IEBASE(1);
public static WireType STEEL = new IEBASE(2);
public static WireType STRUCTURE_ROPE = new IEBASE(3);
public static WireType STRUCTURE_STEEL = new IEBASE(4);
/**
* DO NOT SUBCLASS THIS.
* This is a core implementation as a base for IE's default wires
* DO NOT SUBCLASS THIS.
*/
private static class IEBASE extends WireType
{
final int ordinal;
public IEBASE(int ordinal)
{
super();
this.ordinal = ordinal;
}
@Override
public double getLossRatio()
{
return Math.abs(wireLossRatio[ordinal]);
}
@Override
public int getTransferRate()
{
return Math.abs(wireTransferRate[ordinal]);
}
@Override
public int getColour(Connection connection)
{
return wireColouration[ordinal];
}
@Override
public double getSlack()
{
return 1.005;
}
@Override
@SideOnly(Side.CLIENT)
public TextureAtlasSprite getIcon(Connection connection)
{
return iconDefaultWire;
}
@Override
public int getMaxLength()
{
return wireLength[ordinal];
}
@Override
public ItemStack getWireCoil()
{
return new ItemStack(ieWireCoil,1,ordinal);
}
@Override
public String getUniqueName()
{
return uniqueNames[ordinal];
}
@Override
public double getRenderDiameter()
{
return renderDiameter[ordinal];
}
@Override
public boolean isEnergyWire()
{
return ordinal<3;
}
}
}

View file

@ -1,9 +0,0 @@
package blusunrize.immersiveengineering.api.fluid;
import net.minecraft.util.EnumFacing;
public interface IFluidPipe
{
boolean canOutputPressurized(boolean consumePower);
boolean hasOutputConnection(EnumFacing side);
}

View file

@ -1,5 +0,0 @@
@API(owner = "ImmersiveEngineering", apiVersion = "1.0", provides = "ImmersiveEngineering|API")
package blusunrize.immersiveengineering.api;
import net.minecraftforge.fml.common.API;

View file

@ -1,24 +0,0 @@
package blusunrize.immersiveengineering.api.shader;
import net.minecraft.item.ItemStack;
/**
* @author BluSunrize - 29.10.2015
*
* To be implemented by items can accept shaders
*/
public interface IShaderEquipableItem
{
/**
* @return a string representing which kind of ShaderCase this item will accept
*/
String getShaderType();
/**
* needs to be integrated with the internal inventory of the item
*/
void setShaderItem(ItemStack stack, ItemStack shader);
/**
* needs to be integrated with the internal inventory of the item
*/
ItemStack getShaderItem(ItemStack stack);
}

View file

@ -1,8 +0,0 @@
package blusunrize.immersiveengineering.api.shader;
import net.minecraft.item.ItemStack;
public interface IShaderItem
{
ShaderCase getShaderCase(ItemStack shader, ItemStack item, String shaderType);
}

View file

@ -1,95 +0,0 @@
package blusunrize.immersiveengineering.api.shader;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.item.ItemStack;
/**
* @author BluSunrize - 29.10.2015
*
* To be implemented into new ShaderCases for new items<br>
* Pre-configured ones exist (ShaderCaseRevolver.class) but when a new, shader-ready item is implemented, it'll need a shadercase.
*/
public abstract class ShaderCase
{
protected final int[] colourUnderlying;
protected final int[] colourPrimary;
protected final int[] colourSecondary;
protected int[] colourOverlay;
protected static final int[] defaultWhite = {255,255,255,255};
protected String overlayType="0";
protected String baseTexturePath="";
public ShaderCase(String overlayType, int[] colourUnderlying, int[] colourPrimary, int[] colourSecondary, String baseTexturePath)
{
this.overlayType = overlayType;
this.colourUnderlying = colourUnderlying;
this.colourPrimary = colourPrimary;
this.colourSecondary = colourSecondary;
this.colourOverlay = defaultWhite;
this.baseTexturePath = baseTexturePath;
}
public int[] getUnderlyingColour()
{
return colourUnderlying;
}
public int[] getPrimaryColour()
{
return colourPrimary;
}
public int[] getSecondaryColour()
{
return colourSecondary;
}
public String getOverlayType()
{
return overlayType;
}
public String getBaseTexturePath()
{
return baseTexturePath;
}
public ShaderCase setBaseTexturePath(String path)
{
baseTexturePath = path;
return this;
}
public ShaderCase setOverlayColour(int... col)
{
colourOverlay = col;
return this;
}
/**
* @return A string representing which item this shader case applies to. e.g.: "revolver"
*/
public abstract String getShaderType();
/**
* @return how many renderpasses are required for the part of the model
*/
public abstract int getPasses(ItemStack shader, ItemStack item, String modelPart);
/**
* @return which icon is to be used for the given pass and model part. These obviously need to be stitched on the given sheet (mind the revolvers!)
*/
public abstract TextureAtlasSprite getReplacementSprite(ItemStack shader, ItemStack item, String modelPart, int pass);
/**
* Called upon texutre stitching. Replacement icons are stitched from this method.<br>
* Make sure to compare against the sheetID, the revolver sheet ID can be found in IEApi.class
*/
public abstract void stichTextures(TextureMap map, int sheetID);
/**
* @return the RGBA values to be appleid to the given part in the given pass
*/
public abstract int[] getRGBAColourModifier(ItemStack shader, ItemStack item, String modelPart, int pass);
/**
* @param pre indicates whether this is before or after the part was rendered
* @return make specific changes to the render, like GL calls
*/
public abstract void modifyRender(ItemStack shader, ItemStack item, String modelPart, int pass, boolean pre, boolean inventory);
}

View file

@ -1,60 +0,0 @@
package blusunrize.immersiveengineering.api.shader;
import blusunrize.immersiveengineering.api.ApiUtils;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.item.ItemStack;
public class ShaderCaseBalloon extends ShaderCase
{
public String additionalTexture = null;
public ShaderCaseBalloon(String overlayType, int[] colourPrimary, int[] colourSecondary, String additionalTexture)
{
super(overlayType, defaultWhite,colourPrimary,colourSecondary, "immersiveengineering:blocks/shaders/balloon_");
this.additionalTexture = additionalTexture;
}
@Override
public String getShaderType()
{
return "balloon";
}
@Override
public int getPasses(ItemStack shader, ItemStack item, String modelPart)
{
return additionalTexture!=null?3:2;
}
@Override
public TextureAtlasSprite getReplacementSprite(ItemStack shader, ItemStack item, String modelPart, int pass)
{
return pass==2?i_balloonAdditional: pass==1?i_balloonOverlay: i_balloonBase;
}
@Override
public int[] getRGBAColourModifier(ItemStack shader, ItemStack item, String modelPart, int pass)
{
if(pass==2 && additionalTexture!=null)
return colourOverlay;
return pass==1?colourSecondary : colourPrimary;
}
public TextureAtlasSprite i_balloonBase;
public TextureAtlasSprite i_balloonOverlay;
public TextureAtlasSprite i_balloonAdditional;
@Override
public void stichTextures(TextureMap map, int sheetID)
{
i_balloonBase = ApiUtils.getRegisterSprite(map, "immersiveengineering:blocks/shaders/balloon_0");
i_balloonOverlay = ApiUtils.getRegisterSprite(map, this.baseTexturePath+"1_"+this.overlayType);
if(this.additionalTexture!=null)
i_balloonAdditional = ApiUtils.getRegisterSprite(map, this.baseTexturePath+additionalTexture);
}
@Override
public void modifyRender(ItemStack shader, ItemStack item, String modelPart, int pass, boolean pre, boolean inventory)
{
}
}

View file

@ -1,103 +0,0 @@
package blusunrize.immersiveengineering.api.shader;
import blusunrize.immersiveengineering.api.ApiUtils;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.item.ItemStack;
public class ShaderCaseChemthrower extends ShaderCase
{
public String additionalTexture = null;
public int glowLayer = -1;
public boolean renderCageOnBase = true;
public boolean tanksUncoloured = true;
public ShaderCaseChemthrower(String overlayType, int[] colourGrip, int[] colourPrimary, int[] colourSecondary, boolean cageOnBase, boolean tanksUncoloured, String additionalTexture)
{
super(overlayType, colourGrip,colourPrimary,colourSecondary,"immersiveengineering:items/shaders/chemthrower_");
this.additionalTexture = additionalTexture;
this.renderCageOnBase = cageOnBase;
this.tanksUncoloured = tanksUncoloured;
}
@Override
public String getShaderType()
{
return "chemthrower";
}
@Override
public int getPasses(ItemStack shader, ItemStack item, String modelPart)
{
int i = additionalTexture!=null?1:0;
if(modelPart.equals("cage"))
return (renderCageOnBase?2:1)+i;
if(modelPart.equals("base"))
return 3+i;
if(modelPart.equals("tanks"))
return (tanksUncoloured?1:2)+i;
return 2+i;
}
@Override
public TextureAtlasSprite getReplacementSprite(ItemStack shader, ItemStack item, String modelPart, int pass)
{
int maxPass = getPasses(shader, item, modelPart);
boolean hasUncoloured = modelPart.equals("base") || (tanksUncoloured&&modelPart.equals("tanks"));
if(pass==maxPass-1 && hasUncoloured)//uncoloured
return i_chemthrowerUncoloured;
if(pass==maxPass-(hasUncoloured?2:1) && i_chemthrowerAdditional!=null)
return i_chemthrowerAdditional;
if(modelPart.equals("cage"))
return pass==0&&renderCageOnBase?i_chemthrowerBase:i_chemthrowerOverlay;
return pass==0?i_chemthrowerBase: i_chemthrowerOverlay;
}
@Override
public int[] getRGBAColourModifier(ItemStack shader, ItemStack item, String modelPart, int pass)
{
int maxPass = getPasses(shader, item, modelPart);
boolean hasUncoloured = modelPart.equals("base") || (tanksUncoloured&&modelPart.equals("tanks"));
if(pass==maxPass-1 && hasUncoloured)//uncoloured
return defaultWhite;
if(pass==maxPass-(hasUncoloured?2:1) && i_chemthrowerAdditional!=null)
return colourOverlay;
int i=getTextureType(modelPart,pass); //0 == grip, 1==main, 2==detail
if(i==0)
return colourUnderlying;
if(i==1)
return colourPrimary;
if(i==2)
return colourSecondary;
return defaultWhite;
}
public int getTextureType(String modelPart, int pass)
{
//0 == grip, 1==main, 2==detail
if(modelPart.equals("grip"))
return pass==0?0:pass+1;
return pass+1;
}
public TextureAtlasSprite i_chemthrowerBase;
public TextureAtlasSprite i_chemthrowerOverlay;
public TextureAtlasSprite i_chemthrowerUncoloured;
public TextureAtlasSprite i_chemthrowerAdditional;
@Override
public void stichTextures(TextureMap map, int sheetID)
{
i_chemthrowerBase = ApiUtils.getRegisterSprite(map, "immersiveengineering:items/shaders/chemthrower_0");
i_chemthrowerOverlay = ApiUtils.getRegisterSprite(map, this.baseTexturePath+"1_"+this.overlayType);
i_chemthrowerUncoloured = ApiUtils.getRegisterSprite(map, "immersiveengineering:items/shaders/chemthrower_uncoloured");
if(this.additionalTexture!=null)
i_chemthrowerAdditional = ApiUtils.getRegisterSprite(map, this.baseTexturePath+additionalTexture);
}
@Override
public void modifyRender(ItemStack shader, ItemStack item, String modelPart, int pass, boolean pre, boolean inventory)
{
}
}

View file

@ -1,95 +0,0 @@
package blusunrize.immersiveengineering.api.shader;
import blusunrize.immersiveengineering.api.ApiUtils;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.item.ItemStack;
public class ShaderCaseDrill extends ShaderCase
{
public String additionalTexture = null;
public ShaderCaseDrill(String overlayType, int[] colourGrip, int[] colourPrimary, int[] colourSecondary, String additionalTexture)
{
super(overlayType, colourGrip,colourPrimary,colourSecondary, "immersiveengineering:items/shaders/drill_diesel_");
this.additionalTexture = additionalTexture;
}
@Override
public String getShaderType()
{
return "drill";
}
@Override
public int getPasses(ItemStack shader, ItemStack item, String modelPart)
{
if(modelPart.equals("drill_head")||modelPart.equals("upgrade_damage0")||modelPart.equals("upgrade_damage1")||modelPart.equals("upgrade_damage2")||modelPart.equals("upgrade_damage3")||modelPart.equals("upgrade_damage4"))
return 1;
if(modelPart.equals("upgrade_speed")||modelPart.equals("upgrade_waterproof"))
return 2;
int i = additionalTexture!=null?1:0;
return 3+i;
}
@Override
public TextureAtlasSprite getReplacementSprite(ItemStack shader, ItemStack item, String modelPart, int pass)
{
if(modelPart.equals("drill_head")||modelPart.equals("upgrade_damage0")||modelPart.equals("upgrade_damage1")||modelPart.equals("upgrade_damage2")||modelPart.equals("upgrade_damage3")||modelPart.equals("upgrade_damage4"))
return null;
int maxPass = getPasses(shader, item, modelPart);
if(pass==maxPass-1)//uncoloured
return i_drillUncoloured;
if(pass==maxPass-2 && i_drillAdditional!=null)
return i_drillAdditional;
return pass==0?i_drillBase: i_drillOverlay;
}
@Override
public int[] getRGBAColourModifier(ItemStack shader, ItemStack item, String modelPart, int pass)
{
int maxPass = getPasses(shader, item, modelPart);
if(pass==maxPass-1)
return defaultWhite;
if(pass==maxPass-2 && i_drillAdditional!=null)
return colourOverlay;
int i=getTextureType(modelPart,pass); //0 == grip, 1==main, 2==detail
if(i==0)
return colourUnderlying;
if(i==1)
return colourPrimary;
if(i==2)
return colourSecondary;
return defaultWhite;
}
public int getTextureType(String modelPart, int pass)
{
//0 == grip, 1==main, 2==detail
if(modelPart.equals("drill_grip"))
return pass==0?0:pass+1;
return pass+1;
}
public TextureAtlasSprite i_drillBase;
public TextureAtlasSprite i_drillOverlay;
public TextureAtlasSprite i_drillUncoloured;
public TextureAtlasSprite i_drillAdditional;
@Override
public void stichTextures(TextureMap map, int sheetID)
{
i_drillBase = ApiUtils.getRegisterSprite(map, "immersiveengineering:items/shaders/drill_diesel_0");
i_drillOverlay = ApiUtils.getRegisterSprite(map, this.baseTexturePath+"1_"+this.overlayType);
i_drillUncoloured = ApiUtils.getRegisterSprite(map, "immersiveengineering:items/shaders/drill_diesel_uncoloured");
if(this.additionalTexture!=null)
i_drillAdditional = ApiUtils.getRegisterSprite(map, this.baseTexturePath+additionalTexture);
}
@Override
public void modifyRender(ItemStack shader, ItemStack item, String modelPart, int pass, boolean pre, boolean inventory)
{
}
}

View file

@ -1,72 +0,0 @@
package blusunrize.immersiveengineering.api.shader;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.entity.item.EntityMinecart;
import net.minecraft.item.ItemStack;
public class ShaderCaseMinecart extends ShaderCase
{
public static Set<Class<? extends EntityMinecart>> invalidMinecartClasses = new HashSet();
public String additionalTexture = null;
public boolean[] overlaySides = {true, true,true,true,true, true,true};
public boolean[] mirrorSideForPass = {true,true,true,true};
/**
* @param colourUnderlying is never used but is needed to colour the shader item
*/
public ShaderCaseMinecart(String overlayType, int colourUnderlying[], int[] colourPrimary, int[] colourSecondary, String additionalTexture)
{
super(overlayType, colourUnderlying,colourPrimary,colourSecondary, "immersiveengineering:textures/models/shaders/minecart_");
this.additionalTexture = additionalTexture;
if(overlayType.equals("1") || overlayType.equals("2") || overlayType.equals("7"))
{
overlaySides[1] = false;
overlaySides[2] = false;
}
}
@Override
public String getShaderType()
{
return "minecart";
}
@Override
public int getPasses(ItemStack shader, ItemStack item, String modelPart)
{
return additionalTexture!=null?4:3;
}
@Override
public TextureAtlasSprite getReplacementSprite(ItemStack shader, ItemStack item, String modelPart, int pass)
{
return null;
}
@Override
public int[] getRGBAColourModifier(ItemStack shader, ItemStack item, String modelPart, int pass)
{
if(pass==2 && additionalTexture!=null)
return colourOverlay;
if(pass==0)
return colourPrimary;
if(pass==1)
return colourSecondary;
return defaultWhite;
}
@Override
public void stichTextures(TextureMap map, int sheetID)
{
}
@Override
public void modifyRender(ItemStack shader, ItemStack item, String modelPart, int pass, boolean pre, boolean inventory)
{
}
}

View file

@ -1,93 +0,0 @@
package blusunrize.immersiveengineering.api.shader;
import blusunrize.immersiveengineering.api.ApiUtils;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.item.ItemStack;
public class ShaderCaseRailgun extends ShaderCase
{
public String additionalTexture = null;
public ShaderCaseRailgun(String overlayType, int[] colourGrip, int[] colourPrimary, int[] colourSecondary, String additionalTexture)
{
super(overlayType, colourGrip,colourPrimary,colourSecondary, "immersiveengineering:items/shaders/railgun_");
this.additionalTexture = additionalTexture;
}
@Override
public String getShaderType()
{
return "railgun";
}
@Override
public int getPasses(ItemStack shader, ItemStack item, String modelPart)
{
if(modelPart.equals("sled")||modelPart.equals("wires")||modelPart.equals("tubes"))
return 1;
boolean hasUncoloured = modelPart.equals("barrel")||modelPart.equals("frame")||modelPart.equals("upgrade_speed")||modelPart.equals("upgrade_scope");
return 2+(additionalTexture!=null?1:0)+(hasUncoloured?1:0);
}
@Override
public TextureAtlasSprite getReplacementSprite(ItemStack shader, ItemStack item, String modelPart, int pass)
{
int maxPass = getPasses(shader, item, modelPart);
boolean hasUncoloured = modelPart.equals("sled")||modelPart.equals("wires")||modelPart.equals("tubes")||modelPart.equals("frame")||modelPart.equals("barrel")||modelPart.equals("upgrade_speed")||modelPart.equals("upgrade_scope");
if(hasUncoloured && pass==maxPass-1)//uncoloured
return i_railgunUncoloured;
if(pass==maxPass-(hasUncoloured?2:1) && i_railgunAdditional!=null)
return i_railgunAdditional;
return pass==0?i_railgunBase: i_railgunOverlay;
}
@Override
public int[] getRGBAColourModifier(ItemStack shader, ItemStack item, String modelPart, int pass)
{
int maxPass = getPasses(shader, item, modelPart);
boolean hasUncoloured = modelPart.equals("sled")||modelPart.equals("wires")||modelPart.equals("tubes")||modelPart.equals("frame")||modelPart.equals("barrel")||modelPart.equals("upgrade_speed")||modelPart.equals("upgrade_scope");
if(hasUncoloured&&pass==maxPass-1)
return defaultWhite;
if(pass==maxPass-(hasUncoloured?2:1) && i_railgunAdditional!=null)
return colourOverlay;
int i=getTextureType(modelPart,pass); //0 == grip, 1==main, 2==detail
if(i==0)
return colourUnderlying;
if(i==1)
return colourPrimary;
if(i==2)
return colourSecondary;
return defaultWhite;
}
public int getTextureType(String modelPart, int pass)
{
//0 == grip, 1==main, 2==detail
if(modelPart.equals("grip"))
return pass==0?0:pass+1;
return pass+1;
}
public TextureAtlasSprite i_railgunBase;
public TextureAtlasSprite i_railgunOverlay;
public TextureAtlasSprite i_railgunUncoloured;
public TextureAtlasSprite i_railgunAdditional;
@Override
public void stichTextures(TextureMap map, int sheetID)
{
i_railgunBase = ApiUtils.getRegisterSprite(map, "immersiveengineering:items/shaders/railgun_0");
i_railgunOverlay = ApiUtils.getRegisterSprite(map, this.baseTexturePath+"1_"+this.overlayType);
i_railgunUncoloured = ApiUtils.getRegisterSprite(map, "immersiveengineering:items/shaders/railgun_uncoloured");
if(this.additionalTexture!=null)
i_railgunAdditional = ApiUtils.getRegisterSprite(map, this.baseTexturePath+additionalTexture);
}
@Override
public void modifyRender(ItemStack shader, ItemStack item, String modelPart, int pass, boolean pre, boolean inventory)
{
}
}

View file

@ -1,159 +0,0 @@
package blusunrize.immersiveengineering.api.shader;
import org.lwjgl.opengl.GL11;
import blusunrize.immersiveengineering.api.ApiUtils;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.item.ItemStack;
public class ShaderCaseRevolver extends ShaderCase
{
public int[] colourBlade = new int[4];
public String additionalTexture = null;
public ShaderCaseRevolver(String overlayType, int[] colourGrip, int[] colourPrimary, int[] colourSecondary, int[] colourBlade, String additionalTexture)
{
super(overlayType, colourGrip,colourPrimary,colourSecondary, "immersiveengineering:revolvers/shaders/revolver_");
this.colourBlade = colourBlade;
this.additionalTexture = additionalTexture;
}
@Override
public String getShaderType()
{
return "revolver";
}
@Override
public int getPasses(ItemStack shader, ItemStack item, String modelPart)
{
int i = additionalTexture!=null?1:0;
if(modelPart.equals("cosmetic_compensator"))
return 1+i;
if(modelPart.equals("bayonet_attachment") || modelPart.equals("player_bayonet")||modelPart.equals("dev_bayonet") || modelPart.equals("player_mag")||modelPart.equals("dev_mag"))
return 2+i;
return 3+i;
}
@Override
public TextureAtlasSprite getReplacementSprite(ItemStack shader, ItemStack item, String modelPart, int pass)
{
int maxPass = getPasses(shader, item, modelPart);
boolean hasUncoloured = modelPart.equals("barrel")||modelPart.equals("dev_scope")||modelPart.equals("player_mag")||modelPart.equals("dev_mag")||modelPart.equals("player_electro_0")||modelPart.equals("player_electro_1");
if(pass==maxPass-1 && hasUncoloured)//uncoloured
return i_revolverUncoloured;
if(pass==maxPass-(hasUncoloured?2:1) && i_revolverAdditional!=null)
return i_revolverAdditional;
switch(modelPart)
{
case "revolver_frame":
return pass==0?i_revolverGrip: pass==1?i_revolverBase: i_revolverOverlay;
case "barrel":
case "dev_scope":
case "player_mag":
case "dev_mag":
case "player_electro_0":
case "player_electro_1":
case "player_bayonet":
case "dev_bayonet":
return pass==0?i_revolverBase: i_revolverOverlay;
case "bayonet_attachment":
return pass==0?i_revolverGrip: i_revolverOverlay;
case "cosmetic_compensator":
return i_revolverOverlay;
}
return i_revolverBase;
}
@Override
public int[] getRGBAColourModifier(ItemStack shader, ItemStack item, String modelPart, int pass)
{
int maxPass = getPasses(shader, item, modelPart);
boolean hasUncoloured = modelPart.equals("barrel")||modelPart.equals("dev_scope")||modelPart.equals("player_mag")||modelPart.equals("dev_mag")||modelPart.equals("player_electro_0")||modelPart.equals("player_electro_1");
if(hasUncoloured&&pass==maxPass-1)
return defaultWhite;
if(pass==maxPass-(hasUncoloured?2:1) && i_revolverAdditional!=null)
return colourOverlay;
int i=getTextureType(modelPart,pass); //0 == grip, 1==main, 2==detail, 3==blade
if(i==0)
return colourUnderlying;
if(i==1)
return colourPrimary;
if(i==2)
return colourSecondary;
if(i==3)
return colourBlade;
return defaultWhite;
}
public int getTextureType(String modelPart, int pass)
{
int i=0; //0 == grip, 1==main, 2==detail, 3==blade
switch(modelPart)
{
case "revolver_frame":
i=pass;
break;
case "barrel":
case "dev_scope":
case "player_mag":
case "dev_mag":
case "player_electro_0":
case "player_electro_1":
i=pass+1;
break;
case "cosmetic_compensator":
i=2;
break;
case "bayonet_attachment":
if(pass==1)
i=2;
break;
case "player_bayonet":
case "dev_bayonet":
i=pass==1?2:3;
break;
}
return i;
}
public TextureAtlasSprite i_revolverBase;
public TextureAtlasSprite i_revolverOverlay;
public TextureAtlasSprite i_revolverGrip;
public TextureAtlasSprite i_revolverUncoloured;
public TextureAtlasSprite i_revolverAdditional;
@Override
public void stichTextures(TextureMap map, int sheetID)
{
// i_revolverBase = map.registerSprite(new ResourceLocation("immersiveengineering:revolvers/shaders/revolver_0"));
// i_revolverOverlay = map.registerSprite(new ResourceLocation(this.baseTexturePath+"1_"+this.overlayType));
// i_revolverGrip = map.registerSprite(new ResourceLocation("immersiveengineering:revolvers/shaders/revolver_grip"));
// i_revolverUncoloured = map.registerSprite(new ResourceLocation("immersiveengineering:revolvers/shaders/revolver_uncoloured"));
// if(this.additionalTexture!=null)
// i_revolverAdditional = map.registerSprite(new ResourceLocation(this.baseTexturePath+additionalTexture));
i_revolverBase = ApiUtils.getRegisterSprite(map, "immersiveengineering:revolvers/shaders/revolver_0");
i_revolverOverlay = ApiUtils.getRegisterSprite(map, this.baseTexturePath+"1_"+this.overlayType);
i_revolverGrip = ApiUtils.getRegisterSprite(map, "immersiveengineering:revolvers/shaders/revolver_grip");
i_revolverUncoloured = ApiUtils.getRegisterSprite(map, "immersiveengineering:revolvers/shaders/revolver_uncoloured");
if(this.additionalTexture!=null)
i_revolverAdditional = ApiUtils.getRegisterSprite(map, this.baseTexturePath+additionalTexture);
}
@Override
public void modifyRender(ItemStack shader, ItemStack item, String modelPart, int pass, boolean pre, boolean inventory)
{
if(modelPart.equals("cosmetic_compensator"))
{
if(pre)
GL11.glDisable(GL11.GL_CULL_FACE);
else
GL11.glEnable(GL11.GL_CULL_FACE);
}
}
}

View file

@ -1,196 +0,0 @@
package blusunrize.immersiveengineering.api.tool;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import net.minecraft.block.Block;
import net.minecraft.block.BlockFire;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityBlaze;
import net.minecraft.entity.monster.EntityEnderman;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import net.minecraftforge.fluids.Fluid;
public class ChemthrowerHandler
{
public static HashMap<String, ChemthrowerEffect> effectMap = new HashMap<String, ChemthrowerEffect>();
public static HashSet<String> flammableList = new HashSet<String>();
public static HashSet<String> gasList = new HashSet<String>();
/**
* registers a special effect to a fluid. Fluids without an effect simply do damage based on temperature
*/
public static void registerEffect(Fluid fluid, ChemthrowerEffect effect)
{
if(fluid!=null)
registerEffect(fluid.getName(),effect);
}
/**
* registers a special effect to a fluid. Fluids without an effect simply do damage based on temperature
*/
public static void registerEffect(String fluidName, ChemthrowerEffect effect)
{
effectMap.put(fluidName, effect);
}
public static ChemthrowerEffect getEffect(Fluid fluid)
{
if(fluid!=null)
return getEffect(fluid.getName());
return null;
}
public static ChemthrowerEffect getEffect(String fluidName)
{
return effectMap.get(fluidName);
}
/**
* registers a fluid to allow the chemical thrower to ignite it upon dispersal
*/
public static void registerFlammable(Fluid fluid)
{
if(fluid!=null)
registerFlammable(fluid.getName());
}
/**
* registers a fluid to allow the chemical thrower to ignite it upon dispersal
*/
public static void registerFlammable(String fluidName)
{
flammableList.add(fluidName);
}
public static boolean isFlammable(Fluid fluid)
{
if(fluid!=null)
return flammableList.contains(fluid.getName());
return false;
}
public static boolean isFlammable(String fluidName)
{
return flammableList.contains(fluidName);
}
/**
* registers a fluid to be dispersed like a gas. This is only necessary if the fluid itself isn't designated as a gas
*/
public static void registerGas(Fluid fluid)
{
if(fluid!=null)
registerGas(fluid.getName());
}
/**
* registers a fluid to be dispersed like a gas. This is only necessary if the fluid itself isn't designated as a gas
*/
public static void registerGas(String fluidName)
{
gasList.add(fluidName);
}
public static boolean isGas(Fluid fluid)
{
if(fluid!=null)
return gasList.contains(fluid.getName());
return false;
}
public static boolean isGas(String fluidName)
{
return gasList.contains(fluidName);
}
public abstract static class ChemthrowerEffect
{
public abstract void applyToEntity(EntityLivingBase target, EntityPlayer shooter, ItemStack thrower, Fluid fluid);
public abstract void applyToBlock(World worldObj, RayTraceResult mop, EntityPlayer shooter, ItemStack thrower, Fluid fluid);
}
public static class ChemthrowerEffect_Damage extends ChemthrowerEffect
{
DamageSource source;
float damage;
public ChemthrowerEffect_Damage(DamageSource source, float damage)
{
this.source = source;
this.damage = damage;
}
@Override
public void applyToEntity(EntityLivingBase target, EntityPlayer shooter, ItemStack thrower, Fluid fluid)
{
if(this.source!=null)
{
if(target.attackEntityFrom(source, damage))
{
target.hurtResistantTime = (int)(target.hurtResistantTime*.75);
if(source.isFireDamage() && !target.isImmuneToFire())
target.setFire(fluid.isGaseous()?2:5);
}
}
}
@Override
public void applyToBlock(World worldObj, RayTraceResult mop, EntityPlayer shooter, ItemStack thrower, Fluid fluid)
{
}
}
public static class ChemthrowerEffect_Potion extends ChemthrowerEffect_Damage
{
PotionEffect[] potionEffects;
float[] effectChances;
public ChemthrowerEffect_Potion(DamageSource source, float damage, PotionEffect... effects)
{
super(source, damage);
this.potionEffects = effects;
this.effectChances = new float[potionEffects.length];
for(int i=0; i<this.effectChances.length; i++)
this.effectChances[i] = 1;
}
public ChemthrowerEffect_Potion(DamageSource source, float damage, Potion potion, int duration, int amplifier)
{
this(source, damage, new PotionEffect(potion,duration,amplifier));
}
public ChemthrowerEffect_Potion setEffectChance(int effectIndex, float chance)
{
if(effectIndex>=0 && effectIndex<this.effectChances.length)
this.effectChances[effectIndex] = chance;
return this;
}
@Override
public void applyToEntity(EntityLivingBase target, EntityPlayer shooter, ItemStack thrower, Fluid fluid)
{
super.applyToEntity(target, shooter, thrower, fluid);
if(this.potionEffects!=null && this.potionEffects.length>0)
for(int iEffect=0; iEffect<this.potionEffects.length; iEffect++)
if(target.getRNG().nextFloat() < this.effectChances[iEffect])
{
PotionEffect e = this.potionEffects[iEffect];
PotionEffect newEffect = new PotionEffect(e.getPotion(),e.getDuration(),e.getAmplifier());
newEffect.setCurativeItems(new ArrayList(e.getCurativeItems()));
target.addPotionEffect(newEffect);
}
}
}
public static class ChemthrowerEffect_Extinguish extends ChemthrowerEffect
{
@Override
public void applyToEntity(EntityLivingBase target, EntityPlayer shooter, ItemStack thrower, Fluid fluid)
{
if(target.isBurning())
target.extinguish();
if(target instanceof EntityBlaze || target instanceof EntityEnderman)
if(target.attackEntityFrom(DamageSource.drown, 3))
target.hurtResistantTime = (int)(target.hurtResistantTime*.75);
}
@Override
public void applyToBlock(World worldObj, RayTraceResult mop, EntityPlayer shooter, ItemStack thrower, Fluid fluid)
{
Block b = worldObj.getBlockState(mop.getBlockPos().offset(mop.sideHit)).getBlock();
if(b instanceof BlockFire)
worldObj.setBlockToAir(mop.getBlockPos().offset(mop.sideHit));
}
}
}

View file

@ -1,150 +0,0 @@
package blusunrize.immersiveengineering.api.tool;
import java.util.HashMap;
import net.minecraft.block.Block;
import net.minecraft.block.BlockFurnace;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityFurnace;
public class ExternalHeaterHandler
{
//These are set on IE loading
public static int defaultFurnaceEnergyCost;
public static int defaultFurnaceSpeedupCost;
/**
* @author BluSunrize - 09.12.2015
*
* An interface to be implemented by TileEntities that want to allow direct interaction with the external heater
*/
public interface IExternalHeatable
{
/**
* Called each tick<br>
* Handle fueling as well as possible smelting speed increases here
* @param energyAvailable the amount of RF the furnace heater has stored and can supply
* @param redstone whether a redstone signal is applied to the furnace heater. To keep the target warm, but not do speed increases
* @return the amount of RF consumed that tick. Should be lower or equal to "energyAvailable", obviously
*/
int doHeatTick(int energyAvailable, boolean redstone);
}
public static HashMap<Class<? extends TileEntity>, HeatableAdapter> adapterMap = new HashMap<Class<? extends TileEntity>, HeatableAdapter>();
/**
* @author BluSunrize - 09.12.2015
*
* An adapter to appyl to TileEntities that can't implement the IExternalHeatable interface
*/
public abstract static class HeatableAdapter<E extends TileEntity>
{
/**
* Called each tick<br>
* Handle fueling as well as possible smelting speed increases here
* @param energyAvailable the amount of RF the furnace heater has stored and can supply
* @param canHeat whether a redstone signal is applied to the furnace heater. To keep the target warm, but not do speed increases
* @return the amount of RF consumed that tick. Should be lower or equal to "energyAvailable", obviously
*/
public abstract int doHeatTick(E tileEntity, int energyAvailable, boolean canHeat);
}
/**
* registers a HeatableAdapter to a TileEnttiy class. Should really only be used when implementing the interface is not an option
*/
public static void registerHeatableAdapter(Class<? extends TileEntity> c, HeatableAdapter adapter)
{
adapterMap.put(c, adapter);
}
/**
* @return a HeatableAdapter for the given TileEntity class
*/
public static HeatableAdapter getHeatableAdapter(Class<? extends TileEntity> c)
{
HeatableAdapter adapter = adapterMap.get(c);
if(adapter == null && c!=TileEntity.class && c.getSuperclass()!=TileEntity.class)
{
adapter = getHeatableAdapter((Class<? extends TileEntity>)c.getSuperclass());
adapterMap.put(c, adapter);
}
return adapter;
}
public static class DefaultFurnaceAdapter extends HeatableAdapter<TileEntityFurnace>
{
boolean canCook(TileEntityFurnace tileEntity)
{
ItemStack input = tileEntity.getStackInSlot(0);
if(input == null)
return false;
ItemStack output = FurnaceRecipes.instance().getSmeltingResult(input);
if(output == null)
return false;
ItemStack existingOutput = tileEntity.getStackInSlot(2);
if(existingOutput==null)
return true;
if(!existingOutput.isItemEqual(output))
return false;
int stackSize = existingOutput.stackSize+output.stackSize;
return stackSize<=tileEntity.getInventoryStackLimit() && stackSize<=output.getMaxStackSize();
}
@Override
public int doHeatTick(TileEntityFurnace tileEntity, int energyAvailable, boolean redstone)
{
int energyConsumed = 0;
boolean canCook = canCook(tileEntity);
if(canCook||redstone)
{
boolean burning = tileEntity.isBurning();
int burnTime = tileEntity.getField(0);
if(burnTime<200)
{
int heatAttempt = 4;
int heatEnergyRatio = Math.max(1, defaultFurnaceEnergyCost);
int energyToUse = Math.min(energyAvailable, heatAttempt*heatEnergyRatio);
int heat = energyToUse/heatEnergyRatio;
if(heat>0)
{
tileEntity.setField(0, burnTime+heat);
energyConsumed += heat*heatEnergyRatio;
if(!burning)
updateFurnace(tileEntity, tileEntity.getField(0)>0);
}
}
if(canCook&&tileEntity.getField(0)>=200&&tileEntity.getField(2)<199)
{
int energyToUse = defaultFurnaceSpeedupCost;
if(energyAvailable-energyConsumed > energyToUse)
{
energyConsumed += energyToUse;
tileEntity.setField(2, tileEntity.getField(2)+1);
}
}
}
return energyConsumed;
}
public void updateFurnace(TileEntity tileEntity, boolean active)
{
Block containing = tileEntity.getBlockType();
if(containing==Blocks.FURNACE)
BlockFurnace.setState(active, tileEntity.getWorld(), tileEntity.getPos());
// else
{
//Fix for Natura, might work on other furnaces that extend the vanilla one and use the variable name "active". Let's hope. xD
NBTTagCompound nbt = new NBTTagCompound();
tileEntity.writeToNBT(nbt);
nbt.setBoolean("active", active);
nbt.setBoolean("Active", active);
tileEntity.readFromNBT(nbt);
IBlockState state = tileEntity.getWorld().getBlockState(tileEntity.getPos());
tileEntity.getWorld().notifyBlockUpdate(tileEntity.getPos(), state,state, 3);
}
}
}
}

View file

@ -1,18 +0,0 @@
package blusunrize.immersiveengineering.api.tool;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
/**
* @author BluSunrize - 24.03.2015
*
* An interface to be generated by Items which makes them valid bullets for the revolver
*/
public interface IBullet
{
boolean canSpawnBullet(ItemStack bulletStack);
void spawnBullet(EntityPlayer player, ItemStack bulletStack, boolean electro);
ItemStack getCasing(ItemStack stack);
}

View file

@ -1,70 +0,0 @@
package blusunrize.immersiveengineering.api.tool;
import blusunrize.immersiveengineering.api.tool.IConfigurableTool.ToolConfig.ToolConfigBoolean;
import blusunrize.immersiveengineering.api.tool.IConfigurableTool.ToolConfig.ToolConfigFloat;
import net.minecraft.item.ItemStack;
/**
* @author BluSunrize - 10.03.2016
*
* Similar to upgradeable tools, configurable tools can be put in the workbench to change their options<br>
*/
public interface IConfigurableTool
{
boolean canConfigure(ItemStack stack);
/**
* Boolean options are checkboxes where checked equals true
*/
ToolConfigBoolean[] getBooleanOptions(ItemStack stack);
/**
* Float options are sliders
*/
ToolConfigFloat[] getFloatOptions(ItemStack stack);
/**
* Apply and store the config option on the given stack
*/
void applyConfigOption(ItemStack stack, String key, Object value);
/**
* @return a TRANSLATED name for the config option. Try to keep this short.
*/
String fomatConfigName(ItemStack stack, ToolConfig config);
/**
* @return a TRANSLATED name for the config option, displayed when hovering over it
*/
String fomatConfigDescription(ItemStack stack, ToolConfig config);
abstract class ToolConfig
{
public int x;
public int y;
public String name;
protected ToolConfig(String name, int x, int y)
{
this.name = name;
this.x = x;
this.y = y;
}
public static class ToolConfigBoolean extends ToolConfig
{
public boolean value;
public ToolConfigBoolean(String name, int x, int y, boolean value)
{
super(name, x, y);
this.value = value;
}
}
public static class ToolConfigFloat extends ToolConfig
{
public float value;
public ToolConfigFloat(String name, int x, int y, float value)
{
super(name, x, y);
this.value = value;
}
}
}
}

View file

@ -1,66 +0,0 @@
package blusunrize.immersiveengineering.api.tool;
import com.google.common.collect.ImmutableList;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
/**
* @author BluSunrize - 28.05.2015
*
* An interface for items to make custom drill heads
*/
public interface IDrillHead
{
/**Called before a block is broken by the head
* Return true to prevent the block from being broken
*/
boolean beforeBlockbreak(ItemStack drill, ItemStack head, EntityPlayer player);
/**Called after a block is broken by the head
* Damage should not be applied here but in the specific method.
*/
void afterBlockbreak(ItemStack drill, ItemStack head, EntityPlayer player);
/**@return A list of BlockPos that will be dug in addition to the targeted block
*/
ImmutableList<BlockPos> getExtraBlocksDug(ItemStack head, World world, EntityPlayer player, RayTraceResult mop);
/**@return The mining level of the drill
*/
int getMiningLevel(ItemStack head);
/**@return The speed of the drill
*/
float getMiningSpeed(ItemStack head);
/**@return The damage the head does when equipped on the drill
*/
float getAttackDamage(ItemStack head);
/**@return The current damage of the drill head
* Used to determine whether the head can be used
*/
int getHeadDamage(ItemStack head);
/**@return The maximum damage of the dril head
* Used to determine whether the head can be used
*/
int getMaximumHeadDamage(ItemStack head);
/**Apply damage to the drill head here
*/
void damageHead(ItemStack head, int damage);
/**Return the texture of the drill head
* Look at IE's default texture for the UV layout
* This IIcon should be stitched in the item sheet
*/
@SideOnly(Side.CLIENT)
TextureAtlasSprite getDrillTexture(ItemStack drill, ItemStack head);
}

View file

@ -1,17 +0,0 @@
package blusunrize.immersiveengineering.api.tool;
import net.minecraft.item.ItemStack;
/**
* @author BluSunrize - 27.10.2015
*
* An item that contains an internal inventory, like drill or revolver
*/
public interface IInternalStorageItem
{
ItemStack[] getContainedItems(ItemStack stack);
void setContainedItems(ItemStack stack, ItemStack[] stackList);
int getInternalSlots(ItemStack stack);
}

View file

@ -1,11 +0,0 @@
package blusunrize.immersiveengineering.api.tool;
import net.minecraft.item.ItemStack;
/**
* Items that implement this will be allowed in the toolbox
*/
public interface ITool
{
boolean isTool(ItemStack item);
}

View file

@ -1,32 +0,0 @@
package blusunrize.immersiveengineering.api.tool;
import java.util.HashMap;
import java.util.Set;
import net.minecraft.item.ItemStack;
/**
* @author BluSunrize - 29.05.2015
*
* Upgrades for the drill (and possibly other items) are handled by this interface
*/
public interface IUpgrade
{
/**
* @return the upgrade types this item provides
* Returns a set so an item can be used for multiple items
*/
Set<String> getUpgradeTypes(ItemStack upgrade);
/**
* @return whether the upgrade can be applied to the parsed target item
* This should fired after comparing UpradeTypes, so you don't have to account for that
*/
boolean canApplyUpgrades(ItemStack target, ItemStack upgrade);
/**
* Applies the modifications to a HashMap. Do <b>NOT</b> apply upgrades to the target directly<br>
* Valid modifications you can apply are Byte, byte[], Boolean, Integer, int[], Float, Double, String
*/
void applyUpgrades(ItemStack target, ItemStack upgrade, HashMap<String, Object> modifications);
}

View file

@ -1,45 +0,0 @@
package blusunrize.immersiveengineering.api.tool;
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.minecraft.nbt.NBTTagCompound;
/**
* @author BluSunrize - 27.10.2015
*
* Upgradeable tools like Drill and Revolver implement this.<br>
* Since this is an interface, upgrade- and inventory-management need to be handled by the item implementing this
*/
public interface IUpgradeableTool extends IInternalStorageItem
{
/**
* @return an NBTTagCompound containing the upgrades as keys and their values<br>
* Examples include "speed" for the mining speed of the drill or "bullets" for extended magazines on the revolver
*/
NBTTagCompound getUpgrades(ItemStack stack);
void clearUpgrades(ItemStack stack);
/**
* Iterate through the stored items and apply upgrades. For an example implementation, see ItemUpgradeableTool in the IE source
*/
void recalculateUpgrades(ItemStack stack);
/**
* @return false to prevent this item from being removed from the workbench. Used by blueprints for example.
*/
boolean canTakeFromWorkbench(ItemStack stack);
void removeFromWorkbench(EntityPlayer player, ItemStack stack);
boolean canModify(ItemStack stack);
/**
* @return an array of Slots to display in the workbench when this item is placed in it
*/
Slot[] getWorkbenchSlots(Container container, ItemStack stack, IInventory invItem);
}

View file

@ -1,54 +0,0 @@
package blusunrize.immersiveengineering.api.tool;
import java.util.HashMap;
import blusunrize.immersiveengineering.api.ApiUtils;
import blusunrize.immersiveengineering.api.ComparableItemStack;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
public class RailgunHandler
{
public static HashMap<ComparableItemStack, RailgunProjectileProperties> projectilePropertyMap = new HashMap<ComparableItemStack, RailgunProjectileProperties>();
public static RailgunProjectileProperties registerProjectileProperties(ComparableItemStack stack, double damage, double gravity)
{
RailgunProjectileProperties properties = new RailgunProjectileProperties(damage, gravity);
projectilePropertyMap.put(stack, properties);
return properties;
}
public static RailgunProjectileProperties registerProjectileProperties(ItemStack stack, double damage, double gravity)
{
return registerProjectileProperties(ApiUtils.createComparableItemStack(stack), damage, gravity);
}
public static RailgunProjectileProperties getProjectileProperties(ItemStack stack)
{
return projectilePropertyMap.get(ApiUtils.createComparableItemStack(stack));
}
public static class RailgunProjectileProperties
{
public double damage;
public double gravity;
public int[][] colourMap = {{0x686868,0xa4a4a4,0xa4a4a4,0xa4a4a4,0x686868}};
public RailgunProjectileProperties(double damage, double gravity)
{
this.damage = damage;
this.gravity = gravity;
}
public RailgunProjectileProperties setColourMap(int[][] map)
{
this.colourMap = map;
return this;
}
/**
* @return true to cancel normal damage application
*/
public boolean overrideHitEntity(Entity entityHit, Entity shooter)
{
return false;
}
}
}

View file

@ -1,68 +0,0 @@
package blusunrize.immersiveengineering.api.tool;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiPredicate;
import java.util.function.Predicate;
import blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable;
import blusunrize.immersiveengineering.api.energy.wires.IWireCoil;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTool;
import net.minecraft.world.World;
public class ToolboxHandler {
private static final List<Predicate<ItemStack>> tools = new ArrayList<>();
private static final List<Predicate<ItemStack>> foods = new ArrayList<>();
private static final List<BiPredicate<ItemStack, World>> wiring = new ArrayList<>();
static {
tools.add((s)->(s.getItem() instanceof ITool && ((ITool) s.getItem()).isTool(s)));
tools.add((s)->(s.getItem() instanceof ItemTool));
foods.add((s)->(s.getItem() instanceof ItemFood));
wiring.add((s, w)->(s.getItem() instanceof IWireCoil));
wiring.add((s, w)->
{
Block b = Block.getBlockFromItem(s.getItem());
int meta = s.getItemDamage();
IBlockState defaultState = b==null?null:b.getStateFromMeta(meta);
return b!=null&&b.hasTileEntity(defaultState)&&(b.createTileEntity(w, defaultState) instanceof IImmersiveConnectable);
}
);
}
public static boolean isTool(ItemStack s)
{
for (Predicate<ItemStack> p:tools)
if (p.test(s))
return true;
return false;
}
public static void addToolType(Predicate<ItemStack> in)
{
tools.add(in);
}
public static boolean isFood(ItemStack s)
{
for (Predicate<ItemStack> p:foods)
if (p.test(s))
return true;
return false;
}
public static void addFoodType(Predicate<ItemStack> in)
{
foods.add(in);
}
public static boolean isWiring(ItemStack s, World w)
{
for (BiPredicate<ItemStack, World> p:wiring)
if (p.test(s, w))
return true;
return false;
}
public static void addWiringType(BiPredicate<ItemStack, World> in)
{
wiring.add(in);
}
}

View file

@ -1,33 +0,0 @@
package blusunrize.immersiveengineering.api.tool;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
/**
* @author BluSunrize - 25.12.2015
*
* A handler for IZoomTool fucntionality, allowing items to function as providers for zooming in
*/
public class ZoomHandler
{
public static float fovZoom = 1;
public static boolean isZooming = false;
/**
* @author BluSunrize - 25.12.2015
*
* An interface to be implemented by items to allow zooming in
*/
public interface IZoomTool
{
/**
* @return whether this item is valid for zooming in
*/
boolean canZoom(ItemStack stack, EntityPlayer player);
/**
* @return the different steps of zoom the item has, sorted from low to high
*/
float[] getZoomSteps(ItemStack stack, EntityPlayer player);
}
}

View file

@ -1,161 +0,0 @@
package blusunrize.immersiveengineering.common;
import java.util.Map;
import blusunrize.immersiveengineering.api.DimensionChunkCoords;
import blusunrize.immersiveengineering.api.energy.wires.IICProxy;
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler;
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection;
import blusunrize.immersiveengineering.api.shader.ShaderRegistry;
import blusunrize.immersiveengineering.api.tool.ExcavatorHandler;
import blusunrize.immersiveengineering.api.tool.ExcavatorHandler.MineralWorldInfo;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;
import net.minecraft.world.WorldSavedData;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.relauncher.Side;
public class IESaveData extends WorldSavedData
{
// private static HashMap<Integer, IESaveData> INSTANCE = new HashMap<Integer, IESaveData>();
private static IESaveData INSTANCE;
public static final String dataName = "ImmersiveEngineering-SaveData";
public IESaveData(String s)
{
super(s);
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
int[] savedDimensions = nbt.getIntArray("savedDimensions");
for(int dim: savedDimensions)
{
NBTTagList connectionList = nbt.getTagList("connectionList"+dim, 10);
ImmersiveNetHandler.INSTANCE.clearAllConnections(dim);
for(int i=0; i<connectionList.tagCount(); i++)
{
NBTTagCompound conTag = connectionList.getCompoundTagAt(i);
Connection con = Connection.readFromNBT(conTag);
if(con!=null)
{
ImmersiveNetHandler.INSTANCE.addConnection(dim, con.start, con);
}
}
}
NBTTagList proxies = nbt.getTagList("iicProxies", 10);
for (int i = 0;i<proxies.tagCount();i++)
ImmersiveNetHandler.INSTANCE.addProxy(IICProxy.readFromNBT(proxies.getCompoundTagAt(i)));
// !!! EventHandler.validateConnsNextTick = true;
NBTTagList mineralList = nbt.getTagList("mineralDepletion", 10);
ExcavatorHandler.mineralCache.clear();
for(int i=0; i<mineralList.tagCount(); i++)
{
NBTTagCompound tag = mineralList.getCompoundTagAt(i);
DimensionChunkCoords coords = DimensionChunkCoords.readFromNBT(tag);
if(coords!=null)
{
MineralWorldInfo info = MineralWorldInfo.readFromNBT(tag.getCompoundTag("info"));
ExcavatorHandler.mineralCache.put(coords, info);
}
}
NBTTagList receivedShaderList = nbt.getTagList("receivedShaderList", 10);
for(int i=0; i<receivedShaderList.tagCount(); i++)
{
NBTTagCompound tag = receivedShaderList.getCompoundTagAt(i);
String player = tag.getString("player");
ShaderRegistry.receivedShaders.get(player).clear();
NBTTagList playerReceived = tag.getTagList("received", 8);
for(int j=0; j<playerReceived.tagCount(); j++)
{
String s = playerReceived.getStringTagAt(j);
if(s!=null && !s.isEmpty())
ShaderRegistry.receivedShaders.put(player, s);
}
}
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt)
{
Integer[] relDim = ImmersiveNetHandler.INSTANCE.getRelevantDimensions().toArray(new Integer[0]);
int[] savedDimensions = new int[relDim.length];
for(int ii=0; ii<relDim.length; ii++)
savedDimensions[ii] = relDim[ii];
nbt.setIntArray("savedDimensions", savedDimensions);
for(int dim: savedDimensions)
{
World world = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(dim);
if(world!=null)
{
NBTTagList connectionList = new NBTTagList();
for(Connection con : ImmersiveNetHandler.INSTANCE.getAllConnections(world))
{
connectionList.appendTag(con.writeToNBT());
}
nbt.setTag("connectionList"+dim, connectionList);
}
}
NBTTagList proxies = new NBTTagList();
for (IICProxy iic:ImmersiveNetHandler.INSTANCE.proxies.values())
proxies.appendTag(iic.writeToNBT());
nbt.setTag("iicProxies", proxies);
NBTTagList mineralList = new NBTTagList();
for(Map.Entry<DimensionChunkCoords,MineralWorldInfo> e: ExcavatorHandler.mineralCache.entrySet())
if(e.getKey()!=null && e.getValue()!=null)
{
NBTTagCompound tag = e.getKey().writeToNBT();
tag.setTag("info", e.getValue().writeToNBT());
mineralList.appendTag(tag);
}
nbt.setTag("mineralDepletion", mineralList);
NBTTagList receivedShaderList = new NBTTagList();
for(String player : ShaderRegistry.receivedShaders.keySet())
{
NBTTagCompound tag = new NBTTagCompound();
tag.setString("player", player);
NBTTagList playerReceived = new NBTTagList();
for(String shader : ShaderRegistry.receivedShaders.get(player))
if(shader!=null && !shader.isEmpty())
playerReceived.appendTag(new NBTTagString(shader));
tag.setTag("received", playerReceived);
receivedShaderList.appendTag(tag);
}
nbt.setTag("receivedShaderList", receivedShaderList);
return nbt;
}
public static void setDirty(int dimension)
{
// if(FMLCommonHandler.instance().getEffectiveSide()==Side.SERVER && INSTANCE.get(dimension)!=null)
// {
// INSTANCE.get(dimension).markDirty();
// }
if(FMLCommonHandler.instance().getEffectiveSide()==Side.SERVER && INSTANCE!=null)
INSTANCE.markDirty();
}
public static void setInstance(int dimension, IESaveData in)
{
// if(FMLCommonHandler.instance().getEffectiveSide()==Side.SERVER)
// INSTANCE.put(dimension, in);
if(FMLCommonHandler.instance().getEffectiveSide()==Side.SERVER)
INSTANCE=in;
}
}

View file

@ -1,36 +0,0 @@
package blusunrize.immersiveengineering.common.util;
import org.apache.logging.log4j.Level;
// !!! import blusunrize.immersiveengineering.ImmersiveEngineering;
import net.minecraftforge.fml.common.FMLLog;
public class IELogger
{
public static boolean debug = false;
public static void log(Level logLevel, Object object)
{
// !!! FMLLog.log(ImmersiveEngineering.MODID, logLevel, String.valueOf(object));
}
public static void error(Object object)
{
log(Level.ERROR, object);
}
public static void info(Object object)
{
log(Level.INFO, object);
}
public static void warn(Object object)
{
log(Level.WARN, object);
}
public static void debug(Object object)
{
// if(debug)
// log(Level.INFO, "[DEBUG:] "+object);
}
}

View file

@ -1,988 +0,0 @@
package blusunrize.immersiveengineering.common.util;
import blusunrize.immersiveengineering.api.ApiUtils;
import blusunrize.immersiveengineering.api.DirectionalBlockPos;
import blusunrize.immersiveengineering.api.Lib;
// !!! import blusunrize.immersiveengineering.common.util.inventory.IIEInventory;
import com.google.common.base.Charsets;
import com.google.common.collect.Lists;
import com.google.common.io.Resources;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParseException;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemDye;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraft.world.storage.loot.*;
import net.minecraft.world.storage.loot.conditions.LootCondition;
import net.minecraft.world.storage.loot.conditions.LootConditionManager;
import net.minecraft.world.storage.loot.functions.LootFunction;
import net.minecraft.world.storage.loot.functions.LootFunctionManager;
import net.minecraftforge.fluids.*;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemHandlerHelper;
import net.minecraftforge.oredict.OreDictionary;
import javax.annotation.Nullable;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URL;
import java.text.DecimalFormat;
import java.util.*;
public class Utils
{
public static boolean compareToOreName(ItemStack stack, String oreName)
{
if(!ApiUtils.isExistingOreName(oreName))
return false;
ItemStack comp = copyStackWithAmount(stack, 1);
List<ItemStack> s = OreDictionary.getOres(oreName);
for (ItemStack st:s)
if (ItemStack.areItemStacksEqual(comp, st))
return true;
return false;
}
public static boolean stackMatchesObject(ItemStack stack, Object o)
{
return stackMatchesObject(stack, o, false);
}
public static boolean stackMatchesObject(ItemStack stack, Object o, boolean checkNBT)
{
if(o instanceof ItemStack)
return OreDictionary.itemMatches((ItemStack)o, stack, false) && (!checkNBT || ((ItemStack)o).getItemDamage()==OreDictionary.WILDCARD_VALUE || ItemStack.areItemStackTagsEqual((ItemStack)o, stack));
else if(o instanceof ArrayList)
{
for(Object io : (ArrayList)o)
if(io instanceof ItemStack && OreDictionary.itemMatches((ItemStack)io, stack, false) && (!checkNBT || ((ItemStack)io).getItemDamage()==OreDictionary.WILDCARD_VALUE || ItemStack.areItemStackTagsEqual((ItemStack)io, stack)))
return true;
}
else if(o instanceof ItemStack[])
{
for(ItemStack io : (ItemStack[])o)
if(OreDictionary.itemMatches(io, stack, false) && (!checkNBT || io.getItemDamage()==OreDictionary.WILDCARD_VALUE || ItemStack.areItemStackTagsEqual(io, stack)))
return true;
}
else if(o instanceof String)
return compareToOreName(stack, (String)o);
return false;
}
public static ItemStack copyStackWithAmount(ItemStack stack, int amount)
{
if(stack==null)
return null;
ItemStack s2 = stack.copy();
s2.stackSize=amount;
return s2;
}
public static String[] dyeNames = {"Black","Red","Green","Brown","Blue","Purple","Cyan","LightGray","Gray","Pink","Lime","Yellow","LightBlue","Magenta","Orange","White"};
public static int getDye(ItemStack stack)
{
if(stack==null)
return -1;
if(stack.getItem().equals(Items.DYE))
return stack.getItemDamage();
for(int dye=0;dye<dyeNames.length;dye++)
if(compareToOreName(stack,"dye"+dyeNames[dye]))
return dye;
return -1;
}
public static boolean isDye(ItemStack stack)
{
if(stack==null)
return false;
if(stack.getItem().equals(Items.DYE))
return true;
for(int dye=0;dye<dyeNames.length;dye++)
if(compareToOreName(stack,"dye"+dyeNames[dye]))
return true;
return false;
}
public static FluidStack copyFluidStackWithAmount(FluidStack stack, int amount, boolean stripPressure)
{
if(stack==null)
return null;
FluidStack fs = new FluidStack(stack, amount);
if(stripPressure && fs.tag!=null && fs.tag.hasKey("pressurized"))
{
fs.tag.removeTag("pressurized");
if(fs.tag.hasNoTags())
fs.tag = null;
}
return fs;
}
static long UUIDBase = 109406000905L;
static long UUIDAdd = 01L;
public static UUID generateNewUUID()
{
UUID uuid = new UUID(UUIDBase,UUIDAdd);
UUIDAdd++;
return uuid;
}
public static BlockPos toCC(Object object)
{
return ApiUtils.toBlockPos(object);
}
public static DirectionalBlockPos toDirCC(Object object, EnumFacing direction)
{
if(object instanceof BlockPos)
return new DirectionalBlockPos((BlockPos)object, direction);
if(object instanceof TileEntity)
return new DirectionalBlockPos(((TileEntity)object).getPos(), direction);
return null;
}
public static boolean isBlockAt(World world, BlockPos pos, Block b, int meta)
{
IBlockState state = world.getBlockState(pos);
if(state.getBlock().equals(b))
return meta<0||meta==OreDictionary.WILDCARD_VALUE || state.getBlock().getMetaFromState(state)==meta;
return false;
}
public static boolean isOreBlockAt(World world, BlockPos pos, String oreName)
{
IBlockState state = world.getBlockState(pos);
ItemStack stack = new ItemStack(state.getBlock(),1,state.getBlock().getMetaFromState(state));
return compareToOreName(stack, oreName);
}
public static String formatDouble(double d, String s)
{
DecimalFormat df = new DecimalFormat(s);
return df.format(d);
}
public static String toScientificNotation(int value, String decimalPrecision, int useKilo)
{
float formatted = value>=1000000000?value/1000000000f : value>=1000000?value/1000000f: value>=useKilo?value/1000f: value;
String notation = value>=1000000000?"G" : value>=1000000?"M": value>=useKilo?"K": "";
return formatDouble(formatted, "0."+decimalPrecision)+notation;
}
public static String toCamelCase(String s)
{
return s.substring(0,1).toUpperCase() + s.substring(1).toLowerCase();
}
static Method m_getHarvestLevel = null;
public static String getHarvestLevelName(int lvl)
{
if(Loader.isModLoaded("TConstruct"))
{
try{
if(m_getHarvestLevel==null)
{
Class clazz = Class.forName("tconstruct.library.util");
if(clazz!=null)
m_getHarvestLevel = clazz.getDeclaredMethod("getHarvestLevelName", int.class);
}
if(m_getHarvestLevel!=null)
return (String)m_getHarvestLevel.invoke(null, lvl);
}catch(Exception e){}
}
return I18n.format(Lib.DESC_INFO+"mininglvl."+Math.max(-1, Math.min(lvl, 6)));
}
public static String getModVersion(String modid)
{
for(ModContainer container : Loader.instance().getActiveModList())
if(container.getModId().equalsIgnoreCase(modid))
return container.getVersion();
return "";
}
public static boolean tilePositionMatch(TileEntity tile0, TileEntity tile1)
{
return tile0.getPos().equals(tile1.getPos());
}
public static RayTraceResult getMovingObjectPositionFromPlayer(World world, EntityLivingBase living, boolean bool)
{
float f = 1.0F;
float f1 = living.prevRotationPitch + (living.rotationPitch - living.prevRotationPitch) * f;
float f2 = living.prevRotationYaw + (living.rotationYaw - living.prevRotationYaw) * f;
double d0 = living.prevPosX + (living.posX - living.prevPosX) * (double)f;
double d1 = living.prevPosY + (living.posY - living.prevPosY) * (double)f + (double)(world.isRemote ? living.getEyeHeight() - (living instanceof EntityPlayer?((EntityPlayer)living).getDefaultEyeHeight():0) : living.getEyeHeight()); // isRemote check to revert changes to ray trace position due to adding the eye height clientside and player yOffset differences
double d2 = living.prevPosZ + (living.posZ - living.prevPosZ) * (double)f;
Vec3d vec3 = new Vec3d(d0, d1, d2);
float f3 = MathHelper.cos(-f2 * 0.017453292F - (float)Math.PI);
float f4 = MathHelper.sin(-f2 * 0.017453292F - (float)Math.PI);
float f5 = -MathHelper.cos(-f1 * 0.017453292F);
float f6 = MathHelper.sin(-f1 * 0.017453292F);
float f7 = f4 * f5;
float f8 = f3 * f5;
double d3 = 5.0D;
if (living instanceof EntityPlayerMP)
d3 = ((EntityPlayerMP)living).interactionManager.getBlockReachDistance();
Vec3d vec31 = vec3.addVector((double)f7 * d3, (double)f6 * d3, (double)f8 * d3);
return world.rayTraceBlocks(vec3, vec31, bool, !bool, false);
}
public static boolean canBlocksSeeOther(World world, BlockPos cc0, BlockPos cc1, Vec3d pos0, Vec3d pos1)
{
HashSet<BlockPos> inter = rayTrace(pos0, pos1, world);
Iterator<BlockPos> it = inter.iterator();
while (it.hasNext()) {
BlockPos cc = it.next();
if (!cc.equals(cc0)&&!cc.equals(cc1))
return false;
}
return true;
}
public static boolean isHammer(ItemStack stack)
{
if(stack==null)
return false;
return stack.getItem().getToolClasses(stack).contains(Lib.TOOL_HAMMER);
}
public static Vec3d getFlowVector(World world, BlockPos pos)
{
IBlockState state = world.getBlockState(pos);
if(state.getBlock() instanceof BlockFluidBase)
return ((BlockFluidBase)state.getBlock()).getFlowVector(world, pos);
else if( !(state.getBlock() instanceof BlockLiquid))
return new Vec3d(0, 0, 0);
BlockLiquid block = (BlockLiquid)state.getBlock();
Vec3d vec3 = new Vec3d(0.0D, 0.0D, 0.0D);
Material mat = state.getMaterial();
int i = getEffectiveFlowDecay(world, pos, mat);
for(EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
{
BlockPos blockpos = pos.offset(enumfacing);
int j = getEffectiveFlowDecay(world, blockpos, mat);
if(j<0)
{
if(!world.getBlockState(blockpos).getMaterial().blocksMovement())
{
j = getEffectiveFlowDecay(world, blockpos.down(), mat);
if(j>=0)
{
int k = j - (i - 8);
vec3 = vec3.addVector((double)((blockpos.getX() - pos.getX()) * k), (double)((blockpos.getY() - pos.getY()) * k), (double)((blockpos.getZ() - pos.getZ()) * k));
}
}
}
else if(j>=0)
{
int l = j - i;
vec3 = vec3.addVector((double)((blockpos.getX() - pos.getX()) * l), (double)((blockpos.getY() - pos.getY()) * l), (double)((blockpos.getZ() - pos.getZ()) * l));
}
}
if(state.getValue(BlockLiquid.LEVEL).intValue()>=8)
{
for(EnumFacing enumfacing1 : EnumFacing.Plane.HORIZONTAL)
{
BlockPos blockpos1 = pos.offset(enumfacing1);
if(block.isBlockSolid(world, blockpos1, enumfacing1) || block.isBlockSolid(world, blockpos1.up(), enumfacing1))
{
vec3 = vec3.normalize().addVector(0.0D, -6.0D, 0.0D);
break;
}
}
}
return vec3.normalize();
}
static int getEffectiveFlowDecay(IBlockAccess world, BlockPos pos, Material mat)
{
IBlockState state = world.getBlockState(pos);
if(state.getMaterial() != mat)
return -1;
int l = state.getBlock().getMetaFromState(state);
if (l >= 8)
l = 0;
return l;
}
public static Vec3d addVectors(Vec3d vec0, Vec3d vec1)
{
return vec0.addVector(vec1.xCoord,vec1.yCoord,vec1.zCoord);
}
public static boolean isVecInEntityHead(EntityLivingBase entity, Vec3d vec)
{
if(entity.height/entity.width<2)//Crude check to see if the entity is bipedal or at least upright (this should work for blazes)
return false;
double d = vec.yCoord-(entity.posY+entity.getEyeHeight());
return Math.abs(d) < .25;
}
public static NBTTagCompound getRandomFireworkExplosion(Random rand, int preType)
{
NBTTagCompound tag = new NBTTagCompound();
NBTTagCompound expl = new NBTTagCompound();
expl.setBoolean("Flicker", true);
expl.setBoolean("Trail", true);
int[] colors = new int[rand.nextInt(8) + 1];
for (int i = 0; i < colors.length; i++)
{
int j = rand.nextInt(11)+1;
if(j>2)
j++;
if(j>6)
j+=2;
//no black, brown, light grey, grey or white
colors[i] = ItemDye.DYE_COLORS[j];
}
expl.setIntArray("Colors", colors);
int type = preType>=0?preType: rand.nextInt(4);
if(preType<0 && type==3)
type = 4;
expl.setByte("Type", (byte) type);
NBTTagList list = new NBTTagList();
list.appendTag(expl);
tag.setTag("Explosions", list);
return tag;
}
public static FluidStack drainFluidBlock(World world, BlockPos pos, boolean doDrain)
{
Block b = world.getBlockState(pos).getBlock();
Fluid f = FluidRegistry.lookupFluidForBlock(b);
if(f!=null)
{
if(b instanceof IFluidBlock)
{
if(((IFluidBlock)b).canDrain(world, pos))
return ((IFluidBlock) b).drain(world, pos, doDrain);
else
return null;
}
else
{
if(b.getMetaFromState(world.getBlockState(pos))==0)
{
if(doDrain)
world.setBlockToAir(pos);
return new FluidStack(f, 1000);
}
return null;
}
}
return null;
}
public static Fluid getRelatedFluid(World w, BlockPos pos)
{
Block b = w.getBlockState(pos).getBlock();
return FluidRegistry.lookupFluidForBlock(b);
}
public static boolean placeFluidBlock(World world, BlockPos pos, FluidStack fluid)
{
if(fluid==null || fluid.getFluid()==null)
return false;
IBlockState state = world.getBlockState(pos);
Block b = state.getBlock();
Block fluidBlock = fluid.getFluid().getBlock();
if(Blocks.WATER.equals(fluidBlock))
fluidBlock = Blocks.FLOWING_WATER;
else if(Blocks.LAVA.equals(fluidBlock))
fluidBlock = Blocks.FLOWING_LAVA;
boolean canPlace = b==null||b.isAir(state,world,pos)||b.isReplaceable(world,pos);
if(fluidBlock!=null && canPlace && fluid.amount>=1000)
{
boolean placed = false;
if ((fluidBlock instanceof BlockFluidBase))
{
BlockFluidBase blockFluid = (BlockFluidBase)fluidBlock;
placed = world.setBlockState(pos, fluidBlock.getStateFromMeta(blockFluid.getMaxRenderHeightMeta()));
}
else
placed = world.setBlockState(pos, fluidBlock.getDefaultState());
if(placed)
fluid.amount -= 1000;
return placed;
}
return false;
}
// public static Collection<ItemStack> getContainersFilledWith(FluidStack fluidStack)
// {
// List<ItemStack> containers = new ArrayList();
// for (FluidContainerRegistry.FluidContainerData data : FluidContainerRegistry.getRegisteredFluidContainerData())
// if(data.fluid.containsFluid(fluidStack))
// containers.add(data.filledContainer);
// return containers;
// }
// public static String nameFromStack(ItemStack stack)
// {
// if(stack==null)
// return "";
// try
// {
// return GameData.getItemRegistry().getNameForObject(stack.getItem());
// }
// catch (NullPointerException e) {}
// return "";
// }
public static IBlockState getStateFromItemStack(ItemStack stack)
{
if(stack==null||stack.getItem()==null)
return null;
Block block = getBlockFromItem(stack.getItem());
if(block!=null)
return block.getStateFromMeta(stack.getItemDamage());
return null;
}
public static Block getBlockFromItem(Item item)
{
if(item==Items.CAULDRON)
return Blocks.CAULDRON;
return Block.getBlockFromItem(item);
}
public static boolean canInsertStackIntoInventory(TileEntity inventory, ItemStack stack, EnumFacing side)
{
if(stack!=null && inventory!=null && inventory.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side))
{
IItemHandler handler = inventory.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side);
ItemStack temp = ItemHandlerHelper.insertItem(handler, stack.copy(), true);
if(temp==null || temp.stackSize<stack.stackSize)
return true;
}
return false;
}
public static ItemStack insertStackIntoInventory(TileEntity inventory, ItemStack stack, EnumFacing side)
{
if(stack!=null && inventory!=null && inventory.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side))
{
IItemHandler handler = inventory.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side);
ItemStack temp = ItemHandlerHelper.insertItem(handler, stack.copy(), true);
if(temp==null || temp.stackSize<stack.stackSize)
return ItemHandlerHelper.insertItem(handler, stack, false);
}
return stack;
}
public static ItemStack insertStackIntoInventory(TileEntity inventory, ItemStack stack, EnumFacing side, boolean simulate)
{
if(inventory!=null && stack!=null && inventory.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side))
{
IItemHandler handler = inventory.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side);
return ItemHandlerHelper.insertItem(handler, stack.copy(), simulate);
}
return stack;
}
public static void dropStackAtPos(World world, BlockPos pos, ItemStack stack, EnumFacing facing)
{
if(stack!=null)
{
EntityItem ei = new EntityItem(world, pos.getX()+.5,pos.getY()+.5,pos.getZ()+.5, stack.copy());
ei.motionY = 0.025000000372529D;
if(facing!=null)
{
ei.motionX = (0.075F * facing.getFrontOffsetX());
ei.motionZ = (0.075F * facing.getFrontOffsetZ());
}
world.spawnEntityInWorld(ei);
}
}
public static void dropStackAtPos(World world, BlockPos pos, ItemStack stack)
{
dropStackAtPos(world, pos, stack, null);
}
// public static ItemStack insertStackIntoInventory(IInventory inventory, ItemStack stack, EnumFacing side)
// {
// if (stack == null || inventory == null)
// return null;
// int stackSize = stack.stackSize;
// if (inventory instanceof ISidedInventory)
// {
// ISidedInventory sidedInv = (ISidedInventory) inventory;
// int slots[] = sidedInv.getSlotsForFace(side);
// if (slots == null)
// return stack;
// for (int i=0; i<slots.length && stack!=null; i++)
// {
// if (sidedInv.canInsertItem(slots[i], stack, side))
// {
// ItemStack existingStack = inventory.getStackInSlot(slots[i]);
// if(OreDictionary.itemMatches(existingStack, stack, true)&&ItemStack.areItemStackTagsEqual(stack, existingStack))
// stack = addToOccupiedSlot(sidedInv, slots[i], stack, existingStack);
// }
// }
// for (int i=0; i<slots.length && stack!=null; i++)
// if (inventory.getStackInSlot(slots[i]) == null && sidedInv.canInsertItem(slots[i], stack, side))
// stack = addToEmptyInventorySlot(sidedInv, slots[i], stack);
// }
// else
// {
// int invSize = inventory.getSizeInventory();
// for (int i=0; i<invSize && stack!=null; i++)
// {
// ItemStack existingStack = inventory.getStackInSlot(i);
// if (OreDictionary.itemMatches(existingStack, stack, true)&&ItemStack.areItemStackTagsEqual(stack, existingStack))
// stack = addToOccupiedSlot(inventory, i, stack, existingStack);
// }
// for (int i=0; i<invSize && stack!=null; i++)
// if (inventory.getStackInSlot(i) == null)
// stack = addToEmptyInventorySlot(inventory, i, stack);
// }
// if (stack == null || stack.stackSize != stackSize)
// inventory.markDirty();
// return stack;
// }
public static ItemStack addToEmptyInventorySlot(IInventory inventory, int slot, ItemStack stack)
{
if (!inventory.isItemValidForSlot(slot, stack)) {
return stack;
}
int stackLimit = inventory.getInventoryStackLimit();
inventory.setInventorySlotContents(slot, copyStackWithAmount(stack, Math.min(stack.stackSize, stackLimit)));
return stackLimit >= stack.stackSize ? null : stack.splitStack(stack.stackSize - stackLimit);
}
public static ItemStack addToOccupiedSlot(IInventory inventory, int slot, ItemStack stack, ItemStack existingStack)
{
int stackLimit = Math.min(inventory.getInventoryStackLimit(), stack.getMaxStackSize());
if (stack.stackSize + existingStack.stackSize > stackLimit) {
int stackDiff = stackLimit - existingStack.stackSize;
existingStack.stackSize = stackLimit;
stack.stackSize -= stackDiff;
inventory.setInventorySlotContents(slot, existingStack);
return stack;
}
existingStack.stackSize += Math.min(stack.stackSize, stackLimit);
inventory.setInventorySlotContents(slot, existingStack);
return stackLimit >= stack.stackSize ? null : stack.splitStack(stack.stackSize - stackLimit);
}
// public static boolean canInsertStackIntoInventory(IInventory inventory, ItemStack stack, EnumFacing side)
// {
// if(stack == null || inventory == null)
// return false;
// if(inventory instanceof ISidedInventory)
// {
// ISidedInventory sidedInv = (ISidedInventory) inventory;
// int slots[] = sidedInv.getSlotsForFace(side);
// if(slots == null)
// return false;
// for(int i=0; i<slots.length && stack!=null; i++)
// {
// if(sidedInv.canInsertItem(slots[i], stack, side) && sidedInv.isItemValidForSlot(slots[i], stack))
// {
// ItemStack existingStack = inventory.getStackInSlot(slots[i]);
// if(existingStack==null)
// return true;
// else
// if(OreDictionary.itemMatches(existingStack, stack, true)&&ItemStack.areItemStackTagsEqual(stack, existingStack))
// if(existingStack.stackSize+stack.stackSize<inventory.getInventoryStackLimit() && existingStack.stackSize+stack.stackSize<existingStack.getMaxStackSize())
// return true;
// }
// }
// }
// else
// {
// int invSize = inventory.getSizeInventory();
// for(int i=0; i<invSize && stack!=null; i++)
// if(inventory.isItemValidForSlot(i, stack))
// {
// ItemStack existingStack = inventory.getStackInSlot(i);
// if(existingStack==null)
// return true;
// else
// if(OreDictionary.itemMatches(existingStack, stack, true)&&ItemStack.areItemStackTagsEqual(stack, existingStack))
// if(existingStack.stackSize+stack.stackSize<inventory.getInventoryStackLimit() && existingStack.stackSize+stack.stackSize<existingStack.getMaxStackSize())
// return true;
// }
// }
// return false;
// }
public static ItemStack fillFluidContainer(IFluidHandler handler, ItemStack containerIn, ItemStack containerOut, @Nullable EntityPlayer player)
{
if(containerIn==null)
return null;
ItemStack full = FluidUtil.tryFillContainer(containerIn, handler, Integer.MAX_VALUE, player, false);
if(full!=null && (containerOut==null || OreDictionary.itemMatches(containerOut,full,true)))
{
if(containerOut.stackSize+full.stackSize<=containerOut.getMaxStackSize())
return null;
return FluidUtil.tryFillContainer(containerIn, handler, Integer.MAX_VALUE, player, true);
}
return null;
}
public static ItemStack drainFluidContainer(IFluidHandler handler, ItemStack containerIn, ItemStack containerOut, @Nullable EntityPlayer player)
{
if(containerIn==null)
return null;
ItemStack empty = FluidUtil.tryEmptyContainer(containerIn, handler, Integer.MAX_VALUE, player, false);
if(empty!=null && (containerOut==null || OreDictionary.itemMatches(containerOut,empty,true)))
{
if(containerOut.stackSize+empty.stackSize<=containerOut.getMaxStackSize())
return null;
return FluidUtil.tryEmptyContainer(containerIn, handler, Integer.MAX_VALUE, player, true);
}
return null;
}
// public static FluidStack getFluidFromItemStack(ItemStack stack)
// {
// if(stack==null)
// return null;
// FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(stack);
// if(fluid != null)
// return fluid;
// else if(stack.getItem() instanceof IFluidContainerItem)
// return ((IFluidContainerItem)stack.getItem()).getFluid(stack);
// return null;
// }
public static boolean isFluidRelatedItemStack(ItemStack stack)
{
if(stack==null)
return false;
return stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null);
}
public static IRecipe findRecipe(InventoryCrafting crafting, World world)
{
for (int i=0; i<CraftingManager.getInstance().getRecipeList().size(); i++)
{
IRecipe irecipe = CraftingManager.getInstance().getRecipeList().get(i);
if(irecipe.matches(crafting, world))
return irecipe;
}
return null;
}
public static class InventoryCraftingFalse extends InventoryCrafting
{
private static final Container nullContainer = new Container()
{
@Override
public void onCraftMatrixChanged(IInventory paramIInventory){}
@Override
public boolean canInteractWith(EntityPlayer p_75145_1_)
{
return false;
}
};
public InventoryCraftingFalse(int w, int h)
{
super(nullContainer, w, h);
}
}
public static HashSet<BlockPos> rayTrace(Vec3d start, Vec3d end, World world)
{
HashSet<BlockPos> ret = new HashSet<BlockPos>();
HashSet<BlockPos> checked = new HashSet<BlockPos>();
// x
if (start.xCoord>end.xCoord)
{
Vec3d tmp = start;
start = end;
end = tmp;
}
double min = start.xCoord;
double dif =end.xCoord-min;
double lengthAdd = Math.ceil(min)-start.xCoord;
Vec3d mov = start.subtract(end);
if (mov.xCoord!=0)
{
mov = scalarProd(mov, 1 / mov.xCoord);
ray(dif, mov, start, lengthAdd, ret, world, checked, Blocks.DIAMOND_ORE);
}
// y
if (mov.yCoord!=0)
{
if (start.yCoord>end.yCoord)
{
Vec3d tmp = start;
start = end;
end = tmp;
}
min = start.yCoord;
dif = end.yCoord-min;
lengthAdd = Math.ceil(min)-start.yCoord;
mov = start.subtract(end);
mov = scalarProd(mov, 1/mov.yCoord);
ray(dif, mov, start, lengthAdd, ret, world, checked, Blocks.IRON_ORE);
}
// z
if (mov.zCoord!=0)
{
if (start.zCoord>end.zCoord)
{
Vec3d tmp = start;
start = end;
end = tmp;
}
min = start.zCoord;
dif = end.zCoord - min;
lengthAdd = Math.ceil(min)-start.zCoord;
mov = start.subtract(end);
mov = scalarProd(mov, 1 / mov.zCoord);
ray(dif, mov, start, lengthAdd, ret, world, checked, Blocks.GOLD_ORE);
}
return ret;
}
private static void ray(double dif, Vec3d mov, Vec3d start, double lengthAdd, HashSet<BlockPos> ret, World world, HashSet<BlockPos> checked, Block tmp)
{
//Do NOT set this to true unless for debugging. Causes blocks to be placed along the traced ray
boolean place = false;
double standartOff = .0625;
for (int i = 0; i < dif; i++)
{
Vec3d pos = addVectors(start, scalarProd(mov, i + lengthAdd+standartOff));
Vec3d posNext = addVectors(start,
scalarProd(mov, i + 1 + lengthAdd+standartOff));
Vec3d posPrev = addVectors(start,
scalarProd(mov, i + lengthAdd-standartOff));
Vec3d posVeryPrev = addVectors(start,
scalarProd(mov, i - 1 + lengthAdd-standartOff));
BlockPos blockPos = new BlockPos((int) Math.floor(pos.xCoord),
(int) Math.floor(pos.yCoord), (int) Math.floor(pos.zCoord));
Block b;
IBlockState state;
if (!checked.contains(blockPos)&&i + lengthAdd+standartOff<dif)
{
state = world.getBlockState(blockPos);
b = state.getBlock();
if (b.canCollideCheck(state, false) && state.collisionRayTrace(world, blockPos, pos, posNext) != null)
ret.add(blockPos);
// if (place)
// world.setBlockState(blockPos, tmp);
checked.add(blockPos);
}
blockPos = new BlockPos((int) Math.floor(posPrev.xCoord), (int) Math.floor(posPrev.yCoord), (int) Math.floor(posPrev.zCoord));
if (!checked.contains(blockPos)&&i + lengthAdd-standartOff<dif)
{
state = world.getBlockState(blockPos);
b = state.getBlock();
if (b.canCollideCheck(state, false) && state.collisionRayTrace(world, blockPos, posVeryPrev, posPrev) != null)
ret.add(blockPos);
// if (place)
// world.setBlock(blockPos.posX, blockPos.posY, blockPos.posZ, tmp);
checked.add(blockPos);
}
}
}
public static Vec3d scalarProd(Vec3d v, double s)
{
return new Vec3d(v.xCoord*s, v.yCoord*s, v.zCoord*s);
}
public static BlockPos rayTraceForFirst(Vec3d start, Vec3d end, World w, Set<BlockPos> ignore)
{
HashSet<BlockPos> trace = rayTrace(start, end, w);
for (BlockPos cc:ignore)
trace.remove(cc);
if (start.xCoord!=end.xCoord)
trace = findMinOrMax(trace, start.xCoord>end.xCoord, 0);
if (start.yCoord!=end.yCoord)
trace = findMinOrMax(trace, start.yCoord>end.yCoord, 0);
if (start.zCoord!=end.zCoord)
trace = findMinOrMax(trace, start.zCoord>end.zCoord, 0);
if (trace.size()>0)
{
BlockPos ret = trace.iterator().next();
return ret;
}
return null;
}
public static HashSet<BlockPos> findMinOrMax(HashSet<BlockPos> in, boolean max, int coord) {
HashSet<BlockPos> ret = new HashSet<BlockPos>();
int currMinMax = max?Integer.MIN_VALUE:Integer.MAX_VALUE;
//find minimum
for (BlockPos cc:in)
{
int curr = (coord==0?cc.getX():(coord==1?cc.getY():cc.getY()));
if (max^(curr<currMinMax))
currMinMax = curr;
}
//fill ret set
for (BlockPos cc:in)
{
int curr = (coord==0?cc.getX():(coord==1?cc.getY():cc.getZ()));
if (curr==currMinMax)
ret.add(cc);
}
return ret;
}
/**
* get tile entity without loading currently unloaded chunks
* @return return value of {@link IBlockAccess#getTileEntity(BlockPos)} or always null if chunk is not loaded
*/
public static TileEntity getExistingTileEntity(World world, BlockPos pos)
{
if(world.isBlockLoaded(pos))
return world.getTileEntity(pos);
return null;
}
public static ItemStack[] readInventory(NBTTagList nbt, int size)
{
ItemStack[] inv = new ItemStack[size];
int max = nbt.tagCount();
for (int i = 0;i<max;i++)
{
NBTTagCompound itemTag = nbt.getCompoundTagAt(i);
int slot = itemTag.getByte("Slot") & 255;
if(slot>=0 && slot<size)
inv[slot] = ItemStack.loadItemStackFromNBT(itemTag);
}
return inv;
}
public static NBTTagList writeInventory(ItemStack[] inv)
{
NBTTagList invList = new NBTTagList();
for(int i=0; i<inv.length; i++)
if(inv[i] != null)
{
NBTTagCompound itemTag = new NBTTagCompound();
itemTag.setByte("Slot", (byte)i);
inv[i].writeToNBT(itemTag);
invList.appendTag(itemTag);
}
return invList;
}
public static void modifyInvStackSize(ItemStack[] inv, int slot, int amount)
{
if(slot>=0&&slot<inv.length && inv[slot]!=null)
{
inv[slot].stackSize += amount;
if(inv[slot].stackSize<=0)
inv[slot] = null;
}
}
public static void shuffleLootItems(List<ItemStack> stacks, int slotAmount, Random rand)
{
List<ItemStack> list = Lists.newArrayList();
Iterator<ItemStack> iterator = stacks.iterator();
while(iterator.hasNext())
{
ItemStack itemstack = iterator.next();
if(itemstack.stackSize <= 0)
iterator.remove();
else if(itemstack.stackSize > 1)
{
list.add(itemstack);
iterator.remove();
}
}
slotAmount = slotAmount - stacks.size();
while(slotAmount>0 && list.size()>0)
{
ItemStack itemstack2 = list.remove(MathHelper.getRandomIntegerInRange(rand, 0, list.size() - 1));
int i = MathHelper.getRandomIntegerInRange(rand, 1, itemstack2.stackSize / 2);
itemstack2.stackSize -= i;
ItemStack itemstack1 = itemstack2.copy();
itemstack1.stackSize = i;
if(itemstack2.stackSize>1 && rand.nextBoolean())
list.add(itemstack2);
else
stacks.add(itemstack2);
if(itemstack1.stackSize>1 && rand.nextBoolean())
list.add(itemstack1);
else
stacks.add(itemstack1);
}
stacks.addAll(list);
Collections.shuffle(stacks, rand);
}
private static final Gson GSON_INSTANCE = (new GsonBuilder()).registerTypeAdapter(RandomValueRange.class, new RandomValueRange.Serializer()).registerTypeAdapter(LootPool.class, new LootPool.Serializer()).registerTypeAdapter(LootTable.class, new LootTable.Serializer()).registerTypeHierarchyAdapter(LootEntry.class, new LootEntry.Serializer()).registerTypeHierarchyAdapter(LootFunction.class, new LootFunctionManager.Serializer()).registerTypeHierarchyAdapter(LootCondition.class, new LootConditionManager.Serializer()).registerTypeHierarchyAdapter(LootContext.EntityTarget.class, new LootContext.EntityTarget.Serializer()).create();
public static LootTable loadBuiltinLootTable(ResourceLocation resource)
{
URL url = Utils.class.getResource("/assets/" + resource.getResourceDomain() + "/loot_tables/" + resource.getResourcePath() + ".json");
if(url==null)
return LootTable.EMPTY_LOOT_TABLE;
else
{
String s;
try
{
s = Resources.toString(url, Charsets.UTF_8);
} catch(IOException ioexception)
{
// IELogger.warn(("Failed to load loot table " + resource.toString() + " from " + url.toString()));
ioexception.printStackTrace();
return LootTable.EMPTY_LOOT_TABLE;
}
try
{
return net.minecraftforge.common.ForgeHooks.loadLootTable(GSON_INSTANCE, resource, s, false);
} catch(JsonParseException jsonparseexception)
{
// IELogger.error(("Failed to load loot table " + resource.toString() + " from " + url.toString()));
jsonparseexception.printStackTrace();
return LootTable.EMPTY_LOOT_TABLE;
}
}
}
/*
public static int calcRedstoneFromInventory(IIEInventory inv)
{
if(inv==null)
return 0;
else
{
int i=0;
float f = 0.0F;
for(int j=0; j<inv.getInventory().length; ++j)
{
ItemStack itemstack = inv.getInventory()[j];
if(itemstack!=null)
{
f += (float)itemstack.stackSize / (float)Math.min(inv.getSlotLimit(j), itemstack.getMaxStackSize());
++i;
}
}
f = f/(float)inv.getInventory().length;
return MathHelper.floor_float(f * 14.0F) + (i > 0 ? 1 : 0);
}
}
/**/
}