aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core/util/minecraft
diff options
context:
space:
mode:
authorJordan Byrne <draknyte1@hotmail.com>2018-02-22 13:55:56 +1000
committerJordan Byrne <draknyte1@hotmail.com>2018-02-22 13:55:56 +1000
commit24905c16017decae4ee60ce4128b6d26de66baf5 (patch)
tree503cef5b6b77e04b11feea7563cd5f4ef5ef6942 /src/Java/gtPlusPlus/core/util/minecraft
parentc5ddbd07991eea29132efbd7f4131ab9a4a977cf (diff)
downloadGT5-Unofficial-24905c16017decae4ee60ce4128b6d26de66baf5.tar.gz
GT5-Unofficial-24905c16017decae4ee60ce4128b6d26de66baf5.tar.bz2
GT5-Unofficial-24905c16017decae4ee60ce4128b6d26de66baf5.zip
% Minor project cleanup.
Diffstat (limited to 'src/Java/gtPlusPlus/core/util/minecraft')
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/EnchantingUtils.java102
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java113
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/FluidUtils.java550
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/InventoryUtils.java60
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java717
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/MaterialUtils.java205
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/ModularArmourUtils.java159
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/NBTUtils.java453
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/PlayerUtils.java175
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/RecipeUtils.java479
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/ShapelessUtils.java55
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/UtilsMining.java214
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/gregtech/PollutionUtils.java54
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/gregtech/material/MaterialBuilder.java254
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/gregtech/recipehandlers/GregtechRecipe.java74
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/particles/BlockBreakParticles.java17
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/particles/EntityParticleFXMysterious.java17
17 files changed, 3698 insertions, 0 deletions
diff --git a/src/Java/gtPlusPlus/core/util/minecraft/EnchantingUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/EnchantingUtils.java
new file mode 100644
index 0000000000..2f273d5f7f
--- /dev/null
+++ b/src/Java/gtPlusPlus/core/util/minecraft/EnchantingUtils.java
@@ -0,0 +1,102 @@
+package gtPlusPlus.core.util.minecraft;
+
+import gtPlusPlus.api.objects.Logger;
+import net.minecraftforge.fluids.FluidRegistry;
+import net.minecraftforge.fluids.FluidStack;
+
+public class EnchantingUtils {
+
+
+ public static final int XP_PER_BOTTLE = 8;
+ public static final int RATIO = 20;
+ public static final int LIQUID_PER_XP_BOTTLE = 160;
+ public static final double RATIO_MOB_ESSENCE_TO_LIQUID_XP = 13.32;
+
+ public static int liquidToXpRatio(final int liquid) {
+ return liquid / RATIO;
+ }
+
+ public static int xpToLiquidRatio(final int xp) {
+ return xp * RATIO;
+ }
+
+ public static FluidStack getEssenceFromLiquidXp(final int xpAmount){
+ if (xpAmount <= 0){
+ return null;
+ }
+ return getMobEssence((int) (xpAmount*RATIO_MOB_ESSENCE_TO_LIQUID_XP));
+ }
+
+ public static FluidStack getLiquidXpFromEssence(final int essenceAmount){
+ if (essenceAmount <= 0){
+ return null;
+ }
+ return getLiquidXP((int) (essenceAmount/RATIO_MOB_ESSENCE_TO_LIQUID_XP));
+ }
+
+ public static int getLiquidForLevel(final int level) {
+ final int xp = getExperienceForLevel(level);
+ return xpToLiquidRatio(xp);
+ }
+
+ public static int getLevelForLiquid(final int liquid) {
+ final int xp = liquidToXpRatio(liquid);
+ return getLevelForExperience(xp);
+ }
+
+ public static int getExperienceForLevel(final int level) {
+ if (level == 0) {
+ return 0;
+ }
+ if ((level > 0) && (level < 16)) {
+ return level * 17;
+ }
+ if ((level > 15) && (level < 31)) {
+ return (int) (((1.5 * Math.pow(level, 2.0)) - (29.5 * level)) + 360.0);
+ }
+ return (int) (((3.5 * Math.pow(level, 2.0)) - (151.5 * level)) + 2220.0);
+ }
+
+ public static int getXpToNextLevel(final int level) {
+ final int levelXP = getLevelForExperience(level);
+ final int nextXP = getExperienceForLevel(level + 1);
+ return nextXP - levelXP;
+ }
+
+ public static int getLevelForExperience(final int experience) {
+ int i;
+ for (i = 0; getExperienceForLevel(i) <= experience; ++i) {
+ }
+ return i - 1;
+ }
+
+
+
+
+
+
+
+ //Xp Fluids
+ public static FluidStack getMobEssence(final int amount){
+ Logger.WARNING("Trying to get a fluid stack of Mob Essence.");
+ try {
+ return FluidRegistry.getFluidStack("mobessence", amount).copy();
+ }
+ catch (final Throwable e){
+ return null;
+ }
+
+ }
+
+ public static FluidStack getLiquidXP(final int amount){
+ Logger.WARNING("Trying to get a fluid stack of Liquid XP.");
+ try {
+ return FluidRegistry.getFluidStack("xpjuice", amount).copy();
+ }
+ catch (final Throwable e){
+ return null;
+ }
+
+ }
+
+}
diff --git a/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java
new file mode 100644
index 0000000000..b16089c0de
--- /dev/null
+++ b/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java
@@ -0,0 +1,113 @@
+package gtPlusPlus.core.util.minecraft;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import cpw.mods.fml.common.registry.EntityRegistry;
+import gregtech.api.util.GT_Utility;
+import gtPlusPlus.api.objects.minecraft.BlockPos;
+import gtPlusPlus.core.util.reflect.ReflectionUtils;
+import ic2.core.IC2Potion;
+import ic2.core.item.armor.ItemArmorHazmat;
+import net.minecraft.block.Block;
+import net.minecraft.entity.*;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.util.DamageSource;
+import net.minecraft.util.MathHelper;
+import net.minecraft.world.World;
+import net.minecraft.world.biome.BiomeGenBase;
+
+public class EntityUtils {
+
+ public static void setEntityOnFire(final Entity entity, final int length){
+ entity.setFire(length);
+ }
+
+ public static int getFacingDirection(final Entity entity){
+ final int d = MathHelper.floor_double((entity.rotationYaw * 4.0F) / 360 + 0.50) & 3;
+ return d;
+ }
+
+ @Deprecated
+ public static Block findBlockUnderEntityNonBoundingBox(final Entity parEntity){
+ final int blockX = MathHelper.floor_double(parEntity.posX);
+ final int blockY = MathHelper.floor_double(parEntity.posY-0.2D - parEntity.yOffset);
+ final int blockZ = MathHelper.floor_double(parEntity.posZ);
+ return parEntity.worldObj.getBlock(blockX, blockY, blockZ);
+ }
+
+ public static Block findBlockUnderEntity(final Entity parEntity){
+ final int blockX = MathHelper.floor_double(parEntity.posX);
+ final int blockY = MathHelper.floor_double(parEntity.boundingBox.minY)-1;
+ final int blockZ = MathHelper.floor_double(parEntity.posZ);
+ return parEntity.worldObj.getBlock(blockX, blockY, blockZ);
+ }
+
+ public static BlockPos findBlockPosUnderEntity(final Entity parEntity){
+ final int blockX = MathHelper.floor_double(parEntity.posX);
+ final int blockY = MathHelper.floor_double(parEntity.boundingBox.minY)-1;
+ final int blockZ = MathHelper.floor_double(parEntity.posZ);
+ return new BlockPos(blockX, blockY, blockZ);
+ }
+
+ //TODO
+ public static void registerEntityToBiomeSpawns(final Class<EntityLiving> classy, final EnumCreatureType EntityType, final BiomeGenBase baseBiomeGen){
+ EntityRegistry.addSpawn(classy, 6, 1, 5, EntityType, baseBiomeGen); //change the values to vary the spawn rarity, biome, etc.
+ }
+
+ public static boolean applyRadiationDamageToEntity(final int stackSize, final int radiationLevel, final World world, final Entity entityHolding){
+ if (!world.isRemote){
+ if ((radiationLevel > 0) && (entityHolding instanceof EntityLivingBase)) {
+ final EntityLivingBase entityLiving = (EntityLivingBase) entityHolding;
+ if (!((EntityPlayer) entityHolding).capabilities.isCreativeMode){
+ if (!ItemArmorHazmat.hasCompleteHazmat(entityLiving) && !GT_Utility.isWearingFullRadioHazmat(entityLiving)) {
+ int duration;
+ if (entityLiving.getActivePotionEffect(IC2Potion.radiation) != null){
+ //Utils.LOG_INFO("t");
+ duration = (radiationLevel*5)+entityLiving.getActivePotionEffect(IC2Potion.radiation).getDuration();
+ }
+ else {
+ //Utils.LOG_INFO("f");
+ duration = radiationLevel*30;
+ }
+ //IC2Potion.radiation.applyTo(entityLiving, duration, damage * 15);
+ GT_Utility.applyRadioactivity(entityLiving, radiationLevel, stackSize);
+ }
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+
+
+ /**
+ * Static Version of the method used in {@code doFireDamage(entity, int)} to save memory.
+ */
+ private static volatile Method dealFireDamage;
+
+ /**
+ * Reflective Call to do Fire Damage to an entity (Does not set entity on fire though)
+ */
+ public static boolean doFireDamage(Entity entity, int amount){
+ if (dealFireDamage == null){
+ try {
+ dealFireDamage = Entity.class.getDeclaredMethod("dealFireDamage", int.class);
+ dealFireDamage.setAccessible(true);
+ }
+ catch (NoSuchMethodException | SecurityException e) {}
+ }
+ else {
+ try {
+ dealFireDamage.invoke(entity, amount);
+ }
+ catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {}
+ }
+ return false;
+ }
+
+ public static void doDamage(Entity entity, DamageSource dmg, int i) {
+ entity.attackEntityFrom(dmg, i);
+ }
+
+}
diff --git a/src/Java/gtPlusPlus/core/util/minecraft/FluidUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/FluidUtils.java
new file mode 100644
index 0000000000..3e46b01fc7
--- /dev/null
+++ b/src/Java/gtPlusPlus/core/util/minecraft/FluidUtils.java
@@ -0,0 +1,550 @@
+package gtPlusPlus.core.util.minecraft;
+
+import gregtech.api.enums.Dyes;
+import gregtech.api.enums.GT_Values;
+import gregtech.api.enums.ItemList;
+import gregtech.api.util.GT_LanguageManager;
+import gtPlusPlus.api.objects.Logger;
+import gtPlusPlus.api.objects.minecraft.FluidGT6;
+import gtPlusPlus.core.fluids.GenericFluid;
+import gtPlusPlus.core.item.base.BaseItemComponent;
+import gtPlusPlus.core.item.base.cell.BaseItemCell;
+import gtPlusPlus.core.item.base.cell.BaseItemPlasmaCell;
+import gtPlusPlus.core.material.Material;
+import gtPlusPlus.core.material.MaterialStack;
+import gtPlusPlus.core.util.Utils;
+import gtPlusPlus.xmod.gregtech.api.enums.GregtechOrePrefixes.GT_Materials;
+import net.minecraft.init.Items;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraftforge.fluids.Fluid;
+import net.minecraftforge.fluids.FluidContainerRegistry;
+import net.minecraftforge.fluids.FluidRegistry;
+import net.minecraftforge.fluids.FluidStack;
+import net.minecraftforge.fluids.IFluidContainerItem;
+
+public class FluidUtils {
+
+ public static FluidStack getWater(final int amount){
+ return FluidUtils.getFluidStack("water", amount);
+ }
+
+ public static FluidStack getlava(final int amount){
+ return FluidUtils.getFluidStack("lava", amount);
+ }
+
+ public static FluidStack getMilk(final int amount){
+ return FluidUtils.getFluidStack("milk", amount);
+ }
+
+ public static FluidStack getFluidStack(final String fluidName, final int amount){
+ Logger.WARNING("Trying to get a fluid stack of "+fluidName);
+ try {
+ return FluidRegistry.getFluidStack(fluidName, amount).copy();
+ }
+ catch (final Throwable e){
+ return null;
+ }
+
+ }
+
+ public static FluidStack getFluidStack(final FluidStack vmoltenFluid, final int fluidAmount) {
+ Logger.WARNING("Trying to get a fluid stack of "+vmoltenFluid.getFluid().getName());
+ try {
+ return FluidRegistry.getFluidStack(vmoltenFluid.getFluid().getName(), fluidAmount).copy();
+ }
+ catch (final Throwable e){
+ return null;
+ }
+ }
+
+ public static FluidStack getFluidStack(final Fluid vFluid, final int fluidAmount) {
+ Logger.WARNING("Trying to get a fluid stack of "+vFluid.getName());
+ try {
+ return FluidRegistry.getFluidStack(vFluid.getName(), fluidAmount).copy();
+ }
+ catch (final Throwable e){
+ return null;
+ }
+ }
+
+ public static FluidStack[] getFluidStackArray(final String fluidName, final int amount){
+ Logger.WARNING("Trying to get a fluid stack of "+fluidName);
+ try {
+ final FluidStack[] singleFluid = {FluidRegistry.getFluidStack(fluidName, amount)};
+ return singleFluid;
+ }
+ catch (final Throwable e){
+ return null;
+ }
+
+ }
+
+ public static FluidStack[] getFluidStackArray(final FluidStack fluidName, final int amount){
+ Logger.WARNING("Trying to get a fluid stack of "+fluidName);
+ try {
+ final FluidStack[] singleFluid = {FluidRegistry.getFluidStack(fluidName.getLocalizedName(), amount)};
+ return singleFluid;
+ }
+ catch (final Throwable e){
+ return null;
+ }
+
+ }
+
+
+ /**
+ * @param String displayName
+ * @param String fluidName
+ * @param int meltingPointC Temp
+ * @param short[] rgba
+ * @param byte state
+ * States: 0 (Solid), 1 (Fluid), 2(Gas), 3(Plasma) 4(Fuel I think? Don't use.)
+ *
+ * @return short[]
+ */
+ public static Fluid generateFluid(final String displayName, final String fluidName, final int tempK, final short[] rgba ,final int aState){
+ Fluid generatedFluid = null;
+ switch (aState) {
+ case 0: {
+ generatedFluid = new GenericFluid(displayName, fluidName, 0, 100, tempK, 10000, false, rgba);
+ break;
+ }
+ default:
+ case 1:
+ case 4: {
+ generatedFluid = new GenericFluid(displayName, fluidName, 0, 100, tempK, 1000, false, rgba);
+ break;
+ }
+ case 2: {
+ generatedFluid = new GenericFluid(displayName, fluidName, 0, -100, tempK, 200, true, rgba);
+ break;
+ }
+ case 3: {
+ generatedFluid = new GenericFluid(displayName, fluidName, 15, -10000, tempK, 10, true, rgba);
+ break;
+ }
+ }
+ return generatedFluid;
+ }
+ /**
+ *
+ * @param String fluidName
+ * @param int meltingPointC Temp
+ * @param short[] rgba
+ * @param byte state
+ * States: 0 (Solid), 1 (Fluid), 2(Gas), 3(Plasma) 4(Fuel I think? Don't use.)
+ *
+ * @return short[]
+ */
+ public static Fluid generateFluid(final Material material ,final int aState){
+ final int tempK = material.getMeltingPointC();
+ Fluid generatedFluid = null;
+ switch (aState) {
+ case 0: {
+ generatedFluid = new GenericFluid(material, 0, 100, tempK, 10000, false);
+ break;
+ }
+ default:
+ case 1:
+ case 4: {
+ generatedFluid = new GenericFluid(material, 0, 100, tempK, 1000, false);
+ break;
+ }
+ case 2: {
+ generatedFluid = new GenericFluid(material, 0, -100, tempK, 200, true);
+ break;
+ }
+ case 3: {
+ generatedFluid = new GenericFluid(material, 15, -10000, tempK, 10, true);
+ break;
+ }
+ }
+ return generatedFluid;
+ }
+
+
+ public static Fluid addAutogeneratedMoltenFluid(final String materialNameFormatted, final short[] rgba, final int MeltingPoint) {
+ return addFluid("molten." + materialNameFormatted.toLowerCase(), "molten.autogenerated", "Molten " + materialNameFormatted, null, rgba, 1, (MeltingPoint <= 0L) ? 1000L : MeltingPoint, null, null, 0);
+ }
+
+ public static Fluid addAutogeneratedMoltenFluid(final GT_Materials aMaterial) {
+ return addFluid("molten." + aMaterial.name().toLowerCase(), "molten.autogenerated", "Molten " + aMaterial.name(), aMaterial, aMaterial.mMoltenRGBa, 1, (aMaterial.mMeltingPoint <= 0L) ? 1000L : aMaterial.mMeltingPoint, null, null, 0);
+ }
+
+ public static Fluid addFluid(final String aName, final String aLocalized, final GT_Materials aMaterial, final int aState, final long aTemperatureK) {
+ return addFluid(aName, aLocalized, aMaterial, aState, aTemperatureK, null, null, 0);
+ }
+
+ public static Fluid addFluid(final String aName, final String aLocalized, final GT_Materials aMaterial, final int aState, final long aTemperatureK, final ItemStack aFullContainer, final ItemStack aEmptyContainer, final int aFluidAmount) {
+ return addFluid(aName, aName.toLowerCase(), aLocalized, aMaterial, null, aState, aTemperatureK, aFullContainer, aEmptyContainer, aFluidAmount);
+ }
+
+ public static Fluid addFluid(String aName, final String aTexture, final String aLocalized, final GT_Materials aMaterial, final short[] aRGBa, final int aState, final long aTemperatureK, final ItemStack aFullContainer, final ItemStack aEmptyContainer, final int aFluidAmount) {
+ aName = Utils.sanitizeString(aName.toLowerCase());
+ Fluid rFluid = new FluidGT6(aName, aTexture, (aRGBa != null) ? aRGBa : Dyes._NULL.getRGBA());
+ GT_LanguageManager.addStringLocalization(rFluid.getUnlocalizedName(), (aLocalized == null) ? aName : aLocalized);
+ if (FluidRegistry.registerFluid(rFluid)) {
+ switch (aState) {
+ case 0: {
+ rFluid.setGaseous(false);
+ rFluid.setViscosity(10000);
+ break;
+ }
+ case 1:
+ case 4: {
+ rFluid.setGaseous(false);
+ rFluid.setViscosity(1000);
+ break;
+ }
+ case 2: {
+ rFluid.setGaseous(true);
+ rFluid.setDensity(-100);
+ rFluid.setViscosity(200);
+ break;
+ }
+ case 3: {
+ rFluid.setGaseous(true);
+ rFluid.setDensity(-10000);
+ rFluid.setViscosity(10);
+ rFluid.setLuminosity(15);
+ break;
+ }
+ }
+ }
+ else {
+ rFluid = FluidRegistry.getFluid(aName);
+ }
+ if ((rFluid.getTemperature() == new Fluid("test").getTemperature()) || (rFluid.getTemperature() <= 0)) {
+ rFluid.setTemperature((int) (aTemperatureK));
+ }
+ if (aMaterial != null) {
+ switch (aState) {
+ case 1: {
+ aMaterial.mFluid = (rFluid);
+ break;
+ }
+ case 2: {
+ aMaterial.mGas = (rFluid);
+ break;
+ }
+ case 3: {
+ aMaterial.mPlasma = (rFluid);
+ break;
+ }
+ }
+ }
+ if ((aFullContainer != null) && (aEmptyContainer != null) && !FluidContainerRegistry.registerFluidContainer(new FluidStack(rFluid, aFluidAmount), aFullContainer, aEmptyContainer)) {
+ GT_Values.RA.addFluidCannerRecipe(aFullContainer, container(aFullContainer, false), null, new FluidStack(rFluid, aFluidAmount));
+ }
+ return rFluid;
+ }
+
+ public static Fluid addGTFluid(final String aName, final String aLocalized, final short[] aRGBa, final int aState, final long aTemperatureK, final ItemStack aFullContainer, final ItemStack aEmptyContainer, final int aFluidAmount) {
+ return addGTFluid("molten."+aName, "molten.autogenerated", aLocalized, aRGBa, aState, aTemperatureK, aFullContainer, aEmptyContainer, aFluidAmount);
+ }
+
+ public static Fluid addGTFluidNonMolten(final String aName, final String aLocalized, final short[] aRGBa, final int aState, final long aTemperatureK, final ItemStack aFullContainer, final ItemStack aEmptyContainer, final int aFluidAmount) {
+ return addGTFluid("fluid."+aName, "fluid.autogenerated", aLocalized, aRGBa, aState, aTemperatureK, aFullContainer, aEmptyContainer, aFluidAmount);
+ }
+
+ public static Fluid addGTFluidNoPrefix(final String aName, final String aLocalized, final short[] aRGBa, final int aState, final long aTemperatureK, final ItemStack aFullContainer, final ItemStack aEmptyContainer, final int aFluidAmount) {
+ return addGTFluid(aName, "fluid.autogenerated", aLocalized, aRGBa, aState, aTemperatureK, aFullContainer, aEmptyContainer, aFluidAmount);
+ }
+
+ public static Fluid addGTPlasma(final Material aMaterial) {
+ if (aMaterial.getLocalizedName().toLowerCase().contains("clay") || (aMaterial.getComposites().size()>1) || aMaterial.getLocalizedName().toLowerCase().contains("wrought")){
+ return null;
+ }
+ Logger.INFO("Generating a "+aMaterial.getLocalizedName()+" Plasma Cell");
+ if (aMaterial.vComponentCount != 1){
+ Logger.INFO("Compound made from: ");
+ for (final MaterialStack x : aMaterial.getComposites()){
+ Logger.INFO(x.getStackMaterial().getLocalizedName());
+ }
+ Logger.INFO("Material is a composite, not generating plasma.");
+ return null;
+ }
+
+ ItemStack temp = null;
+ //Generate a Cell if we need to
+ if (ItemUtils.getItemStackOfAmountFromOreDictNoBroken("cellPlasma"+aMaterial.getUnlocalizedName(), 1) == null){
+ final Item temp2 = new BaseItemPlasmaCell(aMaterial);
+ temp = aMaterial.getPlasmaCell(1);
+ }
+ else {
+ temp = ItemUtils.getItemStackOfAmountFromOreDictNoBroken("cellPlasma"+aMaterial.getUnlocalizedName(), 1);
+ }
+ if (temp != null){
+ return addGTFluid(
+ "plasma." + Utils.sanitizeString(aMaterial.getLocalizedName().toLowerCase()),
+ "plasma.autogenerated",
+ aMaterial.getLocalizedName() + " Plasma",
+ aMaterial.getRGBA(),
+ 3,
+ 10000,
+ temp,
+ ItemList.Cell_Empty.get(1L, new Object[0]),
+ 1000);
+ }
+ return null;
+ }
+
+ public static Fluid addGTFluid(String aName, final String aTexture, final String aLocalized, final short[] aRGBa, final int aState, final long aTemperatureK, final ItemStack aFullContainer, final ItemStack aEmptyContainer, final int aFluidAmount) {
+ aName = Utils.sanitizeString(aName.toLowerCase());
+ Fluid rFluid = new FluidGT6(aName, aTexture, (aRGBa != null) ? aRGBa : Dyes._NULL.getRGBA());
+ GT_LanguageManager.addStringLocalization(rFluid.getUnlocalizedName(), (aLocalized == null) ? aName : aLocalized);
+ if (FluidRegistry.registerFluid(rFluid)) {
+ switch (aState) {
+ case 0: {
+ rFluid.setGaseous(false);
+ rFluid.setViscosity(10000);
+ break;
+ }
+ case 1:
+ case 4: {
+ rFluid.setGaseous(false);
+ rFluid.setViscosity(1000);
+ break;
+ }
+ case 2: {
+ rFluid.setGaseous(true);
+ rFluid.setDensity(-100);
+ rFluid.setViscosity(200);
+ break;
+ }
+ case 3: {
+ rFluid.setGaseous(true);
+ rFluid.setDensity(-10000);
+ rFluid.setViscosity(10);
+ rFluid.setLuminosity(15);
+ break;
+ }
+ }
+ }
+ else {
+ rFluid = FluidRegistry.getFluid(aName);
+ }
+ if ((rFluid.getTemperature() == new Fluid("test").getTemperature()) || (rFluid.getTemperature() <= 0)) {
+ rFluid.setTemperature((int) (aTemperatureK));
+ }
+ if ((aFullContainer != null) && (aEmptyContainer != null) && !FluidContainerRegistry.registerFluidContainer(new FluidStack(rFluid, aFluidAmount), aFullContainer, aEmptyContainer)) {
+ GT_Values.RA.addFluidCannerRecipe(aFullContainer, container(aFullContainer, false), null, new FluidStack(rFluid, aFluidAmount));
+ }
+ else {
+ //Utils.LOG_INFO("Failed creating recipes to fill/empty cells of "+aName+".");
+ }
+ return rFluid;
+ }
+
+ public static boolean valid(final Object aStack) {
+ return (aStack != null) && (aStack instanceof ItemStack) && (((ItemStack)aStack).getItem() != null) && (((ItemStack)aStack).stackSize >= 0);
+ }
+
+ public static boolean invalid(final Object aStack) {
+ return (aStack == null) || !(aStack instanceof ItemStack) || (((ItemStack)aStack).getItem() == null) || (((ItemStack)aStack).stackSize < 0);
+ }
+
+ public static boolean equal(final ItemStack aStack1, final ItemStack aStack2) {
+ return equal(aStack1, aStack2, false);
+ }
+
+ public static boolean equal(final ItemStack aStack1, final ItemStack aStack2, final boolean aIgnoreNBT) {
+ return (aStack1 != null) && (aStack2 != null) && equal_(aStack1, aStack2, aIgnoreNBT);
+ }
+
+ public static boolean equal_(final ItemStack aStack1, final ItemStack aStack2, final boolean aIgnoreNBT) {
+ return (aStack1.getItem() == aStack2.getItem()) && (aIgnoreNBT || ((aStack1.getTagCompound() == null == (aStack2.getTagCompound() == null)) && ((aStack1.getTagCompound() == null) || aStack1.getTagCompound().equals(aStack2.getTagCompound())))) && ((meta(aStack1) == meta(aStack2)) || (meta(aStack1) == 32767) || (meta(aStack2) == 32767));
+ }
+
+ public static ItemStack copy(final Object... aStacks) {
+ for (final Object tStack : aStacks) {
+ if (valid(tStack)) {
+ return ((ItemStack)tStack).copy();
+ }
+ }
+ return null;
+ }
+
+ public static ItemStack copyMeta(final long aMetaData, final Object... aStacks) {
+ final ItemStack rStack = copy(aStacks);
+ if (invalid(rStack)) {
+ return null;
+ }
+ return meta(rStack, aMetaData);
+ }
+
+ public static short meta(final ItemStack aStack) {
+ return (short)Items.feather.getDamage(aStack);
+ }
+
+ public static ItemStack meta(final ItemStack aStack, final long aMeta) {
+ Items.feather.setDamage(aStack, (short)aMeta);
+ return aStack;
+ }
+
+ public static ItemStack amount(final long aAmount, final Object... aStacks) {
+ final ItemStack rStack = copy(aStacks);
+ if (invalid(rStack)) {
+ return null;
+ }
+ rStack.stackSize = (int)aAmount;
+ return rStack;
+ }
+
+ public static ItemStack container(final ItemStack aStack, final boolean aCheckIFluidContainerItems) {
+ if (invalid(aStack)) {
+ return null;
+ }
+ if (aStack.getItem().hasContainerItem(aStack)) {
+ return aStack.getItem().getContainerItem(aStack);
+ }
+ if (equal(aStack, ItemList.Cell_Empty.get(1), true)) {
+ return null;
+ }
+ if (aCheckIFluidContainerItems && (aStack.getItem() instanceof IFluidContainerItem) && (((IFluidContainerItem)aStack.getItem()).getCapacity(aStack) > 0)) {
+ final ItemStack tStack = amount(1L, aStack);
+ ((IFluidContainerItem)aStack.getItem()).drain(tStack, Integer.MAX_VALUE, true);
+ if (!equal(aStack, tStack)) {
+ return tStack;
+ }
+ return null;
+ }
+ if (equal(aStack, ItemList.IC2_ForgeHammer.get(1)) || equal(aStack, ItemList.IC2_WireCutter.get(1))) {
+ return copyMeta(meta(aStack) + 1, aStack);
+ }
+ return null;
+ }
+
+ public static ItemStack container(final ItemStack aStack, final boolean aCheckIFluidContainerItems, final int aStacksize) {
+ return amount(aStacksize, container(aStack, aCheckIFluidContainerItems));
+ }
+
+ public final static Fluid generateFluid(final String unlocalizedName, final String localizedName, final int MeltingPoint, final short[] RGBA){
+ if ((FluidUtils.getFluidStack("molten"+"."+unlocalizedName.toLowerCase(), 1) == null) && (ItemUtils.getItemStackOfAmountFromOreDictNoBroken("dust"+Utils.sanitizeString(localizedName), 1) != null)){
+ Logger.WARNING("Generating our own fluid.");
+
+ //Generate a Cell if we need to
+ if (ItemUtils.getItemStackOfAmountFromOreDictNoBroken("cell"+unlocalizedName, 1) == null){
+ @SuppressWarnings("unused")
+ final
+ Item temp = new BaseItemComponent(unlocalizedName, localizedName, RGBA);
+ }
+
+ final Fluid gtFluid = FluidUtils.addGTFluid(
+ unlocalizedName,
+ "Molten "+localizedName,
+ RGBA,
+ 4,
+ MeltingPoint,
+ ItemUtils.getItemStackOfAmountFromOreDictNoBroken("cell"+unlocalizedName, 1),
+ ItemList.Cell_Empty.get(1L, new Object[0]),
+ 1000);
+
+ //Disable this, not sure why it exists //TODO
+ /*GT_Values.RA.addFluidExtractionRecipe(
+ ItemUtils.getItemStackOfAmountFromOreDictNoBroken("dust"+Utils.sanitizeString(localizedName), 1), //Input
+ null, //Input 2
+ FluidUtils.getFluidStack(gtFluid, 144), //Fluid Output
+ 0, //Chance
+ 1*20, //Duration
+ 16 //Eu Tick
+ );*/
+
+
+ return gtFluid;
+ }
+ Logger.INFO("FLUID GENERATION FAILED FOR "+localizedName);
+ return null;
+ }
+
+ public final static Fluid generateFluidNonMolten(final String unlocalizedName, final String localizedName, final int MeltingPoint, final short[] RGBA, final ItemStack dustStack, final ItemStack dustStack2){
+ return generateFluidNonMolten(unlocalizedName, localizedName, MeltingPoint, RGBA, dustStack, dustStack2, 144);
+ }
+
+ public final static Fluid generateFluidNonMolten(final String unlocalizedName, final String localizedName, final int MeltingPoint, final short[] RGBA, ItemStack dustStack, final ItemStack dustStack2, final int amountPerItem){
+ if (dustStack == null){
+ dustStack = ItemUtils.getItemStackOfAmountFromOreDictNoBroken("dust"+Utils.sanitizeString(localizedName), 1);
+ }
+ if ((FluidUtils.getFluidStack(unlocalizedName.toLowerCase(), 1) == null)/* && ((dustStack != null) || (dustStack2 != null))*/){
+ Logger.WARNING("Generating our own fluid.");
+
+ //Generate a Cell if we need to
+ if (ItemUtils.getItemStackOfAmountFromOreDictNoBroken("cell"+unlocalizedName, 1) == null){
+ @SuppressWarnings("unused")
+ final
+ Item temp = new BaseItemComponent(unlocalizedName, localizedName, RGBA);
+ }
+
+ final Fluid gtFluid = FluidUtils.addGTFluidNonMolten(
+ unlocalizedName,
+ localizedName,
+ RGBA,
+ 4,
+ MeltingPoint,
+ ItemUtils.getItemStackOfAmountFromOreDictNoBroken("cell"+unlocalizedName, 1),
+ ItemList.Cell_Empty.get(1L, new Object[0]),
+ 1000);
+
+ if (dustStack != null){
+ GT_Values.RA.addFluidExtractionRecipe(
+ dustStack, //Input
+ null, //Input 2
+ FluidUtils.getFluidStack(gtFluid, amountPerItem), //Fluid Output
+ 0, //Chance
+ 1*20, //Duration
+ 16 //Eu Tick
+ );
+ }
+ if (dustStack2 != null){
+ GT_Values.RA.addFluidExtractionRecipe(
+ dustStack2, //Input
+ null, //Input 2
+ FluidUtils.getFluidStack(gtFluid, amountPerItem), //Fluid Output
+ 0, //Chance
+ 1*20, //Duration
+ 16 //Eu Tick
+ );
+ }
+
+ return gtFluid;
+ }
+ Logger.INFO("FLUID GENERATION FAILED FOR "+localizedName);
+ return null;
+ }
+
+ public final static Fluid generateFluidNoPrefix(final String unlocalizedName, final String localizedName, final int MeltingPoint, final short[] RGBA){
+ Fluid gtFluid;
+ if (FluidUtils.getFluidStack(unlocalizedName.toLowerCase(), 1) == null){
+ Logger.WARNING("Generating our own fluid.");
+ gtFluid = FluidUtils.addGTFluidNoPrefix(
+ unlocalizedName,
+ localizedName,
+ RGBA,
+ 4,
+ MeltingPoint,
+ ItemUtils.getItemStackOfAmountFromOreDictNoBroken("cell"+unlocalizedName, 1),
+ ItemList.Cell_Empty.get(1L, new Object[0]),
+ 1000);
+ }
+ else {
+ gtFluid = FluidUtils.getFluidStack(unlocalizedName.toLowerCase(), 1).getFluid();
+ }
+ //Generate a Cell if we need to
+ if (ItemUtils.getItemStackOfAmountFromOreDictNoBroken("cell"+unlocalizedName, 1) == null){
+ new BaseItemCell(unlocalizedName, localizedName, RGBA, gtFluid);
+ }
+ return gtFluid;
+ }
+
+
+ public static FluidStack getMobEssence(final int amount){
+ return EnchantingUtils.getMobEssence(amount);
+ }
+
+ public static FluidStack getLiquidXP(final int amount){
+ return EnchantingUtils.getLiquidXP(amount);
+ }
+
+
+}
diff --git a/src/Java/gtPlusPlus/core/util/minecraft/InventoryUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/InventoryUtils.java
new file mode 100644
index 0000000000..0d4394d773
--- /dev/null
+++ b/src/Java/gtPlusPlus/core/util/minecraft/InventoryUtils.java
@@ -0,0 +1,60 @@
+package gtPlusPlus.core.util.minecraft;
+
+import java.util.Random;
+
+import net.minecraft.block.Block;
+import net.minecraft.entity.item.EntityItem;
+import net.minecraft.inventory.IInventory;
+import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.world.World;
+
+public class InventoryUtils {
+
+ private final static Random mRandom = new Random();
+
+ public static void dropInventoryItems(World world, int x, int y, int z, Block block){
+ Object tileentity = world.getTileEntity(x, y, z);
+
+ if (tileentity != null)
+ {
+ for (int i1 = 0; i1 < ((IInventory) tileentity).getSizeInventory(); ++i1)
+ {
+ ItemStack itemstack = ((IInventory) tileentity).getStackInSlot(i1);
+
+ if (itemstack != null)
+ {
+ float f = mRandom.nextFloat() * 0.8F + 0.1F;
+ float f1 = mRandom.nextFloat() * 0.8F + 0.1F;
+ EntityItem entityitem;
+
+ for (float f2 = mRandom.nextFloat() * 0.8F + 0.1F; itemstack.stackSize > 0; world.spawnEntityInWorld(entityitem))
+ {
+ int j1 = mRandom.nextInt(21) + 10;
+
+ if (j1 > itemstack.stackSize)
+ {
+ j1 = itemstack.stackSize;
+ }
+
+ itemstack.stackSize -= j1;
+ entityitem = new EntityItem(world, x + f, y + f1, z + f2, new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage()));
+ float f3 = 0.05F;
+ entityitem.motionX = (float)mRandom.nextGaussian() * f3;
+ entityitem.motionY = (float)mRandom.nextGaussian() * f3 + 0.2F;
+ entityitem.motionZ = (float)mRandom.nextGaussian() * f3;
+
+ if (itemstack.hasTagCompound())