aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gtPlusPlus/core/fluids
diff options
context:
space:
mode:
authorJakub <53441451+kuba6000@users.noreply.github.com>2022-08-29 16:04:28 +0200
committerGitHub <noreply@github.com>2022-08-29 16:04:28 +0200
commit7d1f51a8937e0a86486267437d444696e81e8aa0 (patch)
treea5b145e7271998f7b4b968a2212ed487e54a92b5 /src/main/java/gtPlusPlus/core/fluids
parent5267969156d30b4bb5f4cb2279ebb49db6bd40e2 (diff)
downloadGT5-Unofficial-7d1f51a8937e0a86486267437d444696e81e8aa0.tar.gz
GT5-Unofficial-7d1f51a8937e0a86486267437d444696e81e8aa0.tar.bz2
GT5-Unofficial-7d1f51a8937e0a86486267437d444696e81e8aa0.zip
Buildscript + Spotless (#318)
* Convert AES.java to readable class * Buildscript * Spotless
Diffstat (limited to 'src/main/java/gtPlusPlus/core/fluids')
-rw-r--r--src/main/java/gtPlusPlus/core/fluids/BlockFluidBase.java167
-rw-r--r--src/main/java/gtPlusPlus/core/fluids/FactoryFluid.java105
-rw-r--r--src/main/java/gtPlusPlus/core/fluids/FluidFactory.java349
-rw-r--r--src/main/java/gtPlusPlus/core/fluids/FluidPackage.java83
-rw-r--r--src/main/java/gtPlusPlus/core/fluids/FluidRegistryHandler.java80
-rw-r--r--src/main/java/gtPlusPlus/core/fluids/ItemGenericFluidBucket.java582
6 files changed, 685 insertions, 681 deletions
diff --git a/src/main/java/gtPlusPlus/core/fluids/BlockFluidBase.java b/src/main/java/gtPlusPlus/core/fluids/BlockFluidBase.java
index dc7c9c2e78..d8672dec2b 100644
--- a/src/main/java/gtPlusPlus/core/fluids/BlockFluidBase.java
+++ b/src/main/java/gtPlusPlus/core/fluids/BlockFluidBase.java
@@ -17,88 +17,87 @@ import net.minecraftforge.fluids.Fluid;
public class BlockFluidBase extends BlockFluidClassic {
- @SideOnly(Side.CLIENT)
- protected static IIcon stillIcon;
- @SideOnly(Side.CLIENT)
- protected static IIcon flowingIcon;
-
- protected final short[] mRGB;
-
-
- public BlockFluidBase(Fluid fluid, short[] aRGB) {
- this(fluid, Material.water, aRGB);
- }
-
- public BlockFluidBase(Fluid fluid, Material material, short[] aRGB) {
- super(fluid, material);
- mRGB = aRGB;
- this.setHardness(100.0F);
- this.setLightOpacity(3);
- this.disableStats();
- }
-
- @Override
- public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity ent) {
- if (!(ent instanceof EntityLivingBase)) {
- return;
- }
- /*EntityLivingBase player = (EntityLivingBase) ent;
- int pot = world.rand.nextInt(Potion.potionTypes.length);
- Potion.potionTypes[pot].performEffect(player, 40);*/
- }
-
- @Override
- public IIcon getIcon(int side, int meta) {
- return (side == 0 || side == 1) ? stillIcon : flowingIcon;
- }
-
- @SideOnly(Side.CLIENT)
- @Override
- public void registerBlockIcons(IIconRegister register) {
- if (stillIcon == null) {
- stillIcon = register.registerIcon(CORE.MODID+ ":" + "fluids/fluid.fluid.autogenerated.still");
- }
- if (flowingIcon == null) {
- flowingIcon = register.registerIcon(CORE.MODID+ ":" + "fluids/fluid.fluid.autogenerated.flowing");
- }
- }
-
- @Override
- public int getBlockColor() {
- if (mRGB != null && mRGB.length >= 3) {
- return Utils.rgbtoHexValue(mRGB[0], mRGB[1], mRGB[2]);
- }
- return super.getBlockColor();
- }
-
- @Override
- public int getRenderColor(int aMeta) {
- if (mRGB != null && mRGB.length >= 3) {
- return Utils.rgbtoHexValue(mRGB[0], mRGB[1], mRGB[2]);
- }
- return super.getRenderColor(aMeta);
- }
-
- @Override
- public boolean recolourBlock(World world, int x, int y, int z, ForgeDirection side, int colour) {
- // TODO Auto-generated method stub
- return super.recolourBlock(world, x, y, z, side, colour);
- }
-
- @Override
- public boolean canDisplace(IBlockAccess world, int x, int y, int z) {
- if (world.getBlock(x, y, z).getMaterial().isLiquid()) {
- return false;
- }
- return super.canDisplace(world, x, y, z);
- }
-
- @Override
- public boolean displaceIfPossible(World world, int x, int y, int z) {
- if (world.getBlock(x, y, z).getMaterial().isLiquid()) {
- return false;
- }
- return super.displaceIfPossible(world, x, y, z);
- }
-
+ @SideOnly(Side.CLIENT)
+ protected static IIcon stillIcon;
+
+ @SideOnly(Side.CLIENT)
+ protected static IIcon flowingIcon;
+
+ protected final short[] mRGB;
+
+ public BlockFluidBase(Fluid fluid, short[] aRGB) {
+ this(fluid, Material.water, aRGB);
+ }
+
+ public BlockFluidBase(Fluid fluid, Material material, short[] aRGB) {
+ super(fluid, material);
+ mRGB = aRGB;
+ this.setHardness(100.0F);
+ this.setLightOpacity(3);
+ this.disableStats();
+ }
+
+ @Override
+ public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity ent) {
+ if (!(ent instanceof EntityLivingBase)) {
+ return;
+ }
+ /*EntityLivingBase player = (EntityLivingBase) ent;
+ int pot = world.rand.nextInt(Potion.potionTypes.length);
+ Potion.potionTypes[pot].performEffect(player, 40);*/
+ }
+
+ @Override
+ public IIcon getIcon(int side, int meta) {
+ return (side == 0 || side == 1) ? stillIcon : flowingIcon;
+ }
+
+ @SideOnly(Side.CLIENT)
+ @Override
+ public void registerBlockIcons(IIconRegister register) {
+ if (stillIcon == null) {
+ stillIcon = register.registerIcon(CORE.MODID + ":" + "fluids/fluid.fluid.autogenerated.still");
+ }
+ if (flowingIcon == null) {
+ flowingIcon = register.registerIcon(CORE.MODID + ":" + "fluids/fluid.fluid.autogenerated.flowing");
+ }
+ }
+
+ @Override
+ public int getBlockColor() {
+ if (mRGB != null && mRGB.length >= 3) {
+ return Utils.rgbtoHexValue(mRGB[0], mRGB[1], mRGB[2]);
+ }
+ return super.getBlockColor();
+ }
+
+ @Override
+ public int getRenderColor(int aMeta) {
+ if (mRGB != null && mRGB.length >= 3) {
+ return Utils.rgbtoHexValue(mRGB[0], mRGB[1], mRGB[2]);
+ }
+ return super.getRenderColor(aMeta);
+ }
+
+ @Override
+ public boolean recolourBlock(World world, int x, int y, int z, ForgeDirection side, int colour) {
+ // TODO Auto-generated method stub
+ return super.recolourBlock(world, x, y, z, side, colour);
+ }
+
+ @Override
+ public boolean canDisplace(IBlockAccess world, int x, int y, int z) {
+ if (world.getBlock(x, y, z).getMaterial().isLiquid()) {
+ return false;
+ }
+ return super.canDisplace(world, x, y, z);
+ }
+
+ @Override
+ public boolean displaceIfPossible(World world, int x, int y, int z) {
+ if (world.getBlock(x, y, z).getMaterial().isLiquid()) {
+ return false;
+ }
+ return super.displaceIfPossible(world, x, y, z);
+ }
}
diff --git a/src/main/java/gtPlusPlus/core/fluids/FactoryFluid.java b/src/main/java/gtPlusPlus/core/fluids/FactoryFluid.java
index e3383aee91..59d0fd8839 100644
--- a/src/main/java/gtPlusPlus/core/fluids/FactoryFluid.java
+++ b/src/main/java/gtPlusPlus/core/fluids/FactoryFluid.java
@@ -1,4 +1,5 @@
package gtPlusPlus.core.fluids;
+
import gregtech.api.GregTech_API;
import gtPlusPlus.core.lib.CORE;
import net.minecraft.block.Block;
@@ -7,43 +8,67 @@ import net.minecraftforge.fluids.Fluid;
public class FactoryFluid extends Fluid implements Runnable {
- private final String mTextureName;
- private final short[] mRGBa;
-
- public FactoryFluid(String fluidName, final short[] aRGBa) {
- this(fluidName, null, Short.MIN_VALUE, Short.MIN_VALUE, Short.MIN_VALUE, Short.MIN_VALUE, false, EnumRarity.common, aRGBa);
- }
-
- public FactoryFluid(String fluidName, int luminosity, int density, int temp, int viscosity, final short[] aRGBa) {
- this(fluidName, null, luminosity, density, temp, viscosity, (density == Short.MIN_VALUE || density >= 0 ? false : true), EnumRarity.common, aRGBa);
- }
-
- public FactoryFluid(String fluidName, Block aBlock, int luminosity, int density, int temp, int viscosity, boolean gas, EnumRarity aRarity, final short[] aRGBa) {
- super(fluidName);
- this.mRGBa = aRGBa;
- this.setBlock(aBlock);
- if (luminosity != Short.MIN_VALUE)
- this.setLuminosity(luminosity);
- if (density != Short.MIN_VALUE)
- this.setDensity(density);
- if (temp != Short.MIN_VALUE)
- this.setTemperature(temp);
- if (viscosity != Short.MIN_VALUE)
- this.setViscosity(viscosity);
- this.setGaseous(gas);
- this.setRarity(aRarity);
- this.mTextureName = CORE.MODID+":fluids/fluid.fluid.autogenerated";
- GregTech_API.sGTBlockIconload.add(this);
- }
-
- @Override
- public int getColor() {
- return (Math.max(0, Math.min(255, this.mRGBa[0])) << 16) | (Math.max(0, Math.min(255, this.mRGBa[1])) << 8) | Math.max(0, Math.min(255, this.mRGBa[2]));
- }
-
- @Override
- public void run() {
- this.setIcons(GregTech_API.sBlockIcons.registerIcon(this.mTextureName));
- }
-
-} \ No newline at end of file
+ private final String mTextureName;
+ private final short[] mRGBa;
+
+ public FactoryFluid(String fluidName, final short[] aRGBa) {
+ this(
+ fluidName,
+ null,
+ Short.MIN_VALUE,
+ Short.MIN_VALUE,
+ Short.MIN_VALUE,
+ Short.MIN_VALUE,
+ false,
+ EnumRarity.common,
+ aRGBa);
+ }
+
+ public FactoryFluid(String fluidName, int luminosity, int density, int temp, int viscosity, final short[] aRGBa) {
+ this(
+ fluidName,
+ null,
+ luminosity,
+ density,
+ temp,
+ viscosity,
+ (density == Short.MIN_VALUE || density >= 0 ? false : true),
+ EnumRarity.common,
+ aRGBa);
+ }
+
+ public FactoryFluid(
+ String fluidName,
+ Block aBlock,
+ int luminosity,
+ int density,
+ int temp,
+ int viscosity,
+ boolean gas,
+ EnumRarity aRarity,
+ final short[] aRGBa) {
+ super(fluidName);
+ this.mRGBa = aRGBa;
+ this.setBlock(aBlock);
+ if (luminosity != Short.MIN_VALUE) this.setLuminosity(luminosity);
+ if (density != Short.MIN_VALUE) this.setDensity(density);
+ if (temp != Short.MIN_VALUE) this.setTemperature(temp);
+ if (viscosity != Short.MIN_VALUE) this.setViscosity(viscosity);
+ this.setGaseous(gas);
+ this.setRarity(aRarity);
+ this.mTextureName = CORE.MODID + ":fluids/fluid.fluid.autogenerated";
+ GregTech_API.sGTBlockIconload.add(this);
+ }
+
+ @Override
+ public int getColor() {
+ return (Math.max(0, Math.min(255, this.mRGBa[0])) << 16)
+ | (Math.max(0, Math.min(255, this.mRGBa[1])) << 8)
+ | Math.max(0, Math.min(255, this.mRGBa[2]));
+ }
+
+ @Override
+ public void run() {
+ this.setIcons(GregTech_API.sBlockIcons.registerIcon(this.mTextureName));
+ }
+}
diff --git a/src/main/java/gtPlusPlus/core/fluids/FluidFactory.java b/src/main/java/gtPlusPlus/core/fluids/FluidFactory.java
index d94fa35af7..af7a806d31 100644
--- a/src/main/java/gtPlusPlus/core/fluids/FluidFactory.java
+++ b/src/main/java/gtPlusPlus/core/fluids/FluidFactory.java
@@ -1,8 +1,5 @@
package gtPlusPlus.core.fluids;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
import cpw.mods.fml.common.eventhandler.Event.Result;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.registry.GameRegistry;
@@ -15,6 +12,8 @@ import gtPlusPlus.core.lib.CORE;
import gtPlusPlus.core.util.Utils;
import gtPlusPlus.core.util.minecraft.FluidUtils;
import gtPlusPlus.core.util.minecraft.ItemUtils;
+import java.util.LinkedHashMap;
+import java.util.Map;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
@@ -29,186 +28,176 @@ import net.minecraftforge.fluids.FluidRegistry;
public class FluidFactory {
- public static final Map<String, Fluid> mNameToFluidMap = new LinkedHashMap<String, Fluid>();
- public static final Map<String, ItemStack> mNameToBucketMap = new LinkedHashMap<String, ItemStack>();
- public static final Map<String, Block> mNameToBlockMap = new LinkedHashMap<String, Block>();
- public static final Map<String, Integer> mNameToMetaMap = new LinkedHashMap<String, Integer>();
-
- public static final Map<Fluid, String> mFluidToNameMap = new LinkedHashMap<Fluid, String>();
- public static final Map<Fluid, ItemStack> mFluidToBucketMap = new LinkedHashMap<Fluid, ItemStack>();
- public static final Map<Fluid, Block> mFluidToBlockMap = new LinkedHashMap<Fluid, Block>();
- public static final Map<Fluid, Integer> mFluidToMetaMap = new LinkedHashMap<Fluid, Integer>();
-
- public static final Map<ItemStack, Fluid> mBucketToFluidMap = new LinkedHashMap<ItemStack, Fluid>();
- public static final Map<ItemStack, String> mBucketToNameMap = new LinkedHashMap<ItemStack, String>();
- public static final Map<ItemStack, Block> mBucketToBlockMap = new LinkedHashMap<ItemStack, Block>();
- public static final Map<ItemStack, Integer> mBucketToMetaMap = new LinkedHashMap<ItemStack, Integer>();
-
- public static final Map<Block, String> mBlockToNameMap = new LinkedHashMap<Block, String>();
- public static final Map<Block, Fluid> mBlockToFluidMap = new LinkedHashMap<Block, Fluid>();
- public static final Map<Block, ItemStack> mBlockToBucketMap = new LinkedHashMap<Block, ItemStack>();
- public static final Map<Block, Integer> mBlockToMetaMap = new LinkedHashMap<Block, Integer>();
-
- public static final Map<Integer, String> mMetaToNameMap = new LinkedHashMap<Integer, String>();
- public static final Map<Integer, Fluid> mMetaToFluidMap = new LinkedHashMap<Integer, Fluid>();
- public static final Map<Integer, ItemStack> mMetaToBucketMap = new LinkedHashMap<Integer, ItemStack>();
- public static final Map<Integer, Block> mMetaToBlockMap = new LinkedHashMap<Integer, Block>();
-
-
- //Special Colour Handling
- public static final Map<Integer, Integer> mMetaToColourMap = new LinkedHashMap<Integer, Integer>();
-
-
- public static Item mGenericBucket;
- private static FluidPackage mErrorFluid;
- private static AutoMap<FluidPackage> mGeneratedFluids = new AutoMap<FluidPackage>();
-
- public static void preInit() {
-
- }
-
- public static void init() {
- mGenericBucket = new ItemGenericFluidBucket(Blocks.air);
- GameRegistry.registerItem(mGenericBucket, "gtpp.bucket.generic");
- for (FluidPackage y : mGeneratedFluids) {
- if (!y.valid()) {
- continue;
- }
- GameRegistry.registerBlock(y.mBlock, FluidItemBlock.class, "gtpp_" + y.mName);
- FluidContainerRegistry.registerFluidContainer(y.get(), y.mBucket, new ItemStack(Items.bucket));
- }
- Utils.registerEvent(BucketHandler.INSTANCE);
- }
-
- public static void postInit() {
-
- }
-
- /**
- * Generates a 'Water' type fluid.
- * @param aID - The Fluid ID (Must be unique)
- * @param aUnlocalName - Unlocalized Fluid Name
- * @param aRGB - a {@link Short[]} containing the RGB of the FluidPackage.
- * @return - A fully constructed & registered {@linkplain FluidPackage}
- */
- public static FluidPackage generate(int aID, String aUnlocalName, short[] aRGB) {
- return generate(aID, aUnlocalName, Short.MIN_VALUE, Short.MIN_VALUE, Short.MIN_VALUE, Short.MIN_VALUE, aRGB);
- }
-
- /**
- * Generate a {@link FluidPackage} from the data provided. This FluidPackage is automatically registered and handled internally.
- * Pass in {@link Short}.MIN_VALUE for any of the Fluid Fields (Besides ID, Name or RGB) and it will default to water values.
- * @param aID - The Fluid ID (Must be unique)
- * @param aUnlocalName - Unlocalized Fluid Name
- * @param luminosity - How bright is the fluid.
- * @param density - completely arbitrary; negative density indicates that the fluid is
+ public static final Map<String, Fluid> mNameToFluidMap = new LinkedHashMap<String, Fluid>();
+ public static final Map<String, ItemStack> mNameToBucketMap = new LinkedHashMap<String, ItemStack>();
+ public static final Map<String, Block> mNameToBlockMap = new LinkedHashMap<String, Block>();
+ public static final Map<String, Integer> mNameToMetaMap = new LinkedHashMap<String, Integer>();
+
+ public static final Map<Fluid, String> mFluidToNameMap = new LinkedHashMap<Fluid, String>();
+ public static final Map<Fluid, ItemStack> mFluidToBucketMap = new LinkedHashMap<Fluid, ItemStack>();
+ public static final Map<Fluid, Block> mFluidToBlockMap = new LinkedHashMap<Fluid, Block>();
+ public static final Map<Fluid, Integer> mFluidToMetaMap = new LinkedHashMap<Fluid, Integer>();
+
+ public static final Map<ItemStack, Fluid> mBucketToFluidMap = new LinkedHashMap<ItemStack, Fluid>();
+ public static final Map<ItemStack, String> mBucketToNameMap = new LinkedHashMap<ItemStack, String>();
+ public static final Map<ItemStack, Block> mBucketToBlockMap = new LinkedHashMap<ItemStack, Block>();
+ public static final Map<ItemStack, Integer> mBucketToMetaMap = new LinkedHashMap<ItemStack, Integer>();
+
+ public static final Map<Block, String> mBlockToNameMap = new LinkedHashMap<Block, String>();
+ public static final Map<Block, Fluid> mBlockToFluidMap = new LinkedHashMap<Block, Fluid>();
+ public static final Map<Block, ItemStack> mBlockToBucketMap = new LinkedHashMap<Block, ItemStack>();
+ public static final Map<Block, Integer> mBlockToMetaMap = new LinkedHashMap<Block, Integer>();
+
+ public static final Map<Integer, String> mMetaToNameMap = new LinkedHashMap<Integer, String>();
+ public static final Map<Integer, Fluid> mMetaToFluidMap = new LinkedHashMap<Integer, Fluid>();
+ public static final Map<Integer, ItemStack> mMetaToBucketMap = new LinkedHashMap<Integer, ItemStack>();
+ public static final Map<Integer, Block> mMetaToBlockMap = new LinkedHashMap<Integer, Block>();
+
+ // Special Colour Handling
+ public static final Map<Integer, Integer> mMetaToColourMap = new LinkedHashMap<Integer, Integer>();
+
+ public static Item mGenericBucket;
+ private static FluidPackage mErrorFluid;
+ private static AutoMap<FluidPackage> mGeneratedFluids = new AutoMap<FluidPackage>();
+
+ public static void preInit() {}
+
+ public static void init() {
+ mGenericBucket = new ItemGenericFluidBucket(Blocks.air);
+ GameRegistry.registerItem(mGenericBucket, "gtpp.bucket.generic");
+ for (FluidPackage y : mGeneratedFluids) {
+ if (!y.valid()) {
+ continue;
+ }
+ GameRegistry.registerBlock(y.mBlock, FluidItemBlock.class, "gtpp_" + y.mName);
+ FluidContainerRegistry.registerFluidContainer(y.get(), y.mBucket, new ItemStack(Items.bucket));
+ }
+ Utils.registerEvent(BucketHandler.INSTANCE);
+ }
+
+ public static void postInit() {}
+
+ /**
+ * Generates a 'Water' type fluid.
+ * @param aID - The Fluid ID (Must be unique)
+ * @param aUnlocalName - Unlocalized Fluid Name
+ * @param aRGB - a {@link Short[]} containing the RGB of the FluidPackage.
+ * @return - A fully constructed & registered {@linkplain FluidPackage}
+ */
+ public static FluidPackage generate(int aID, String aUnlocalName, short[] aRGB) {
+ return generate(aID, aUnlocalName, Short.MIN_VALUE, Short.MIN_VALUE, Short.MIN_VALUE, Short.MIN_VALUE, aRGB);
+ }
+
+ /**
+ * Generate a {@link FluidPackage} from the data provided. This FluidPackage is automatically registered and handled internally.
+ * Pass in {@link Short}.MIN_VALUE for any of the Fluid Fields (Besides ID, Name or RGB) and it will default to water values.
+ * @param aID - The Fluid ID (Must be unique)
+ * @param aUnlocalName - Unlocalized Fluid Name
+ * @param luminosity - How bright is the fluid.
+ * @param density - completely arbitrary; negative density indicates that the fluid is
* lighter than air. Default value is approximately the real-life density of water in kg/m^3.
- * @param temp - completely arbitrary; higher temperature indicates that the fluid is
+ * @param temp - completely arbitrary; higher temperature indicates that the fluid is
* hotter than air. Default value is approximately the real-life room temperature of water in degrees Kelvin
- * @param viscosity - completely arbitrary; negative values are not
+ * @param viscosity - completely arbitrary; negative values are not
* permissible. Default value is approximately the real-life density of water in m/s^2 (x10^-3). *
* Higher viscosity means that a fluid flows more slowly, like molasses.
* Lower viscosity means that a fluid flows more quickly, like helium.
- * @param aRGB - a {@link Short[]} containing the RGB of the FluidPackage.
- * @return - A fully constructed & registered {@linkplain FluidPackage}
- */
- public static FluidPackage generate(int aID, String aUnlocalName, int luminosity, int density, int temp,
- int viscosity, short[] aRGB) {
-
- FluidPackage aFluidToGenerate = null;
-
- // Check Load Phase for some Safety, only allow this to be called in Pre-Init.
- if (GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.PRE_INIT) {
- try {
- throw new GregtechException("Cannot generate Fluid Packages outside of Pre-Init!");
- } catch (GregtechException e) {
- e.printStackTrace();
- CORE.crash("Cannot generate Fluid Packages outside of Pre-Init!");
- }
- }
-
- Fluid aGenFluid = fluid(aUnlocalName, luminosity, density, temp, viscosity, aRGB);
- Block aGenBlock = block(aGenFluid, aRGB);
- ItemStack aGenBucket = bucket(aID);
-
- aFluidToGenerate = new FluidPackage(aID, aUnlocalName, aGenFluid, aGenBucket, aGenBlock);
-
- if (aFluidToGenerate != null && aFluidToGenerate.valid()) {
- FluidRegistry.registerFluid(aFluidToGenerate.get());
- mGeneratedFluids.put(aFluidToGenerate);
- }
- else {
- // Handle Bad generation
- if (mErrorFluid == null) {
- mErrorFluid = new FluidPackage(0, "", FluidUtils.getWater(1).getFluid(), ItemUtils.getSimpleStack(Items.water_bucket), Blocks.water);
- }
- return mErrorFluid;
- }
-
-
- return aFluidToGenerate;
- }
-
-
-
- private static Fluid fluid(String aUnlocalName, int luminosity, int density, int temp,
- int viscosity, short[] aRGB) {
- return new FactoryFluid(aUnlocalName, luminosity, density, temp, viscosity, aRGB);
- }
-
- private static ItemStack bucket(int aID) {
- return ItemGenericFluidBucket.registerFluidForBucket(aID);
- }
-
- private static Block block(Fluid aFluidForBlock, short[] aRGB) {
- if (aFluidForBlock != null) {
- FluidRegistry.registerFluid(aFluidForBlock);
- return new BlockFluidBase(aFluidForBlock, aRGB);
- }
- return Blocks.dirt;
- }
-
- /**
- * Copyright © SpaceToad, 2011 http://www.mod-buildcraft.com BuildCraft is
- * distributed under the terms of the Minecraft Mod Public License 1.0, or MMPL.
- * Please check the contents of the license located in
- * http://www.mod-buildcraft.com/MMPL-1.0.txt
- *
- * Modified version of the BC BucketHandler, except using ItemStacks > Items
- * (Why?)
- *
- * @author Alkalus
- */
-
- public static class BucketHandler {
-
- public static BucketHandler INSTANCE = new BucketHandler();
-
- private BucketHandler() {
-
- }
-
- @SubscribeEvent
- public void onBucketFill(FillBucketEvent event) {
- ItemStack result = fillCustomBucket(event.world, event.target);
- if (result == null) {
- return;
- }
- event.result = result;
- event.setResult(Result.ALLOW);
- }
-
- private ItemStack fillCustomBucket(World world, MovingObjectPosition pos) {
- Block block = world.getBlock(pos.blockX, pos.blockY, pos.blockZ);
- ItemStack bucket = mBlockToBucketMap.get(block);
- if (bucket != null && world.getBlockMetadata(pos.blockX, pos.blockY, pos.blockZ) == 0) {
- world.setBlockToAir(pos.blockX, pos.blockY, pos.blockZ);
- return ItemUtils.getSimpleStack(bucket, 1);
- } else {
- return null;
- }
- }
-
- }
-
+ * @param aRGB - a {@link Short[]} containing the RGB of the FluidPackage.
+ * @return - A fully constructed & registered {@linkplain FluidPackage}
+ */
+ public static FluidPackage generate(
+ int aID, String aUnlocalName, int luminosity, int density, int temp, int viscosity, short[] aRGB) {
+
+ FluidPackage aFluidToGenerate = null;
+
+ // Check Load Phase for some Safety, only allow this to be called in Pre-Init.
+ if (GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.PRE_INIT) {
+ try {
+ throw new GregtechException("Cannot generate Fluid Packages outside of Pre-Init!");
+ } catch (GregtechException e) {
+ e.printStackTrace();
+ CORE.crash("Cannot generate Fluid Packages outside of Pre-Init!");
+ }
+ }
+
+ Fluid aGenFluid = fluid(aUnlocalName, luminosity, density, temp, viscosity, aRGB);
+ Block aGenBlock = block(aGenFluid, aRGB);
+ ItemStack aGenBucket = bucket(aID);
+
+ aFluidToGenerate = new FluidPackage(aID, aUnlocalName, aGenFluid, aGenBucket, aGenBlock);
+
+ if (aFluidToGenerate != null && aFluidToGenerate.valid()) {
+ FluidRegistry.registerFluid(aFluidToGenerate.get());
+ mGeneratedFluids.put(aFluidToGenerate);
+ } else {
+ // Handle Bad generation
+ if (mErrorFluid == null) {
+ mErrorFluid = new FluidPackage(
+ 0,
+ "",
+ FluidUtils.getWater(1).getFluid(),
+ ItemUtils.getSimpleStack(Items.water_bucket),
+ Blocks.water);
+ }
+ return mErrorFluid;
+ }
+
+ return aFluidToGenerate;
+ }
+
+ private static Fluid fluid(
+ String aUnlocalName, int luminosity, int density, int temp, int viscosity, short[] aRGB) {
+ return new FactoryFluid(aUnlocalName, luminosity, density, temp, viscosity, aRGB);
+ }
+
+ private static ItemStack bucket(int aID) {
+ return ItemGenericFluidBucket.registerFluidForBucket(aID);
+ }
+
+ private static Block block(Fluid aFluidForBlock, short[] aRGB) {
+ if (aFluidForBlock != null) {
+ FluidRegistry.registerFluid(aFluidForBlock);
+ return new BlockFluidBase(aFluidForBlock, aRGB);
+ }
+ return Blocks.dirt;
+ }
+
+ /**
+ * Copyright © SpaceToad, 2011 http://www.mod-buildcraft.com BuildCraft is
+ * distributed under the terms of the Minecraft Mod Public License 1.0, or MMPL.
+ * Please check the contents of the license located in
+ * http://www.mod-buildcraft.com/MMPL-1.0.txt
+ *
+ * Modified version of the BC BucketHandler, except using ItemStacks > Items
+ * (Why?)
+ *
+ * @author Alkalus
+ */
+ public static class BucketHandler {
+
+ public static BucketHandler INSTANCE = new BucketHandler();
+
+ private BucketHandler() {}
+
+ @SubscribeEvent
+ public void onBucketFill(FillBucketEvent event) {
+ ItemStack result = fillCustomBucket(event.world, event.target);
+ if (result == null) {
+ return;
+ }
+ event.result = result;
+ event.setResult(Result.ALLOW);
+ }
+
+ private ItemStack fillCustomBucket(World world, MovingObjectPosition pos) {
+ Block block = world.getBlock(pos.blockX, pos.blockY, pos.blockZ);
+ ItemStack bucket = mBlockToBucketMap.get(block);
+ if (bucket != null && world.getBlockMetadata(pos.blockX, pos.blockY, pos.blockZ) == 0) {
+ world.setBlockToAir(pos.blockX, pos.blockY, pos.blockZ);
+ return ItemUtils.getSimpleStack(bucket, 1);
+ } else {
+ return null;
+ }
+ }
+ }
}
diff --git a/src/main/java/gtPlusPlus/core/fluids/FluidPackage.java b/src/main/java/gtPlusPlus/core/fluids/FluidPackage.java
index 29f831776b..10e54d794d 100644
--- a/src/main/java/gtPlusPlus/core/fluids/FluidPackage.java
+++ b/src/main/java/gtPlusPlus/core/fluids/FluidPackage.java
@@ -28,56 +28,53 @@ import net.minecraftforge.fluids.Fluid;
public class FluidPackage {
+ public final int mID;
+ public final String mName;
+ private final Fluid mFluid;
+ public final ItemStack mBucket;
+ public final Block mBlock;
- public final int mID;
- public final String mName;
- private final Fluid mFluid;
- public final ItemStack mBucket;
- public final Block mBlock;
+ public FluidPackage(int aID, String aName, Fluid aFluid, ItemStack aBucket, Block aBlock) {
- public FluidPackage(int aID, String aName, Fluid aFluid, ItemStack aBucket, Block aBlock) {
+ mNameToFluidMap.put(aName, aFluid);
+ mNameToBucketMap.put(aName, aBucket);
+ mNameToBlockMap.put(aName, aBlock);
+ mNameToMetaMap.put(aName, aID);
- mNameToFluidMap.put(aName, aFluid);
- mNameToBucketMap.put(aName, aBucket);
- mNameToBlockMap.put(aName, aBlock);
- mNameToMetaMap.put(aName, aID);
+ mFluidToNameMap.put(aFluid, aName);
+ mFluidToBucketMap.put(aFluid, aBucket);
+ mFluidToBlockMap.put(aFluid, aBlock);
+ mFluidToMetaMap.put(aFluid, aID);
- mFluidToNameMap.put(aFluid, aName);
- mFluidToBucketMap.put(aFluid, aBucket);
- mFluidToBlockMap.put(aFluid, aBlock);
- mFluidToMetaMap.put(aFluid, aID);
+ mBucketToFluidMap.put(aBucket, aFluid);
+ mBucketToNameMap.put(aBucket, aName);
+ mBucketToBlockMap.put(aBucket, aBlock);
+ mBucketToMetaMap.put(aBucket, aID);
- mBucketToFluidMap.put(aBucket, aFluid);
- mBucketToNameMap.put(aBucket, aName);
- mBucketToBlockMap.put(aBucket, aBlock);
- mBucketToMetaMap.put(aBucket, aID);
+ mBlockToNameMap.put(aBlock, aName);
+ mBlockToFluidMap.put(aBlock, aFluid);
+ mBlockToBucketMap.put(aBlock, aBucket);
+ mBlockToMetaMap.put(aBlock, aID);
- mBlockToNameMap.put(aBlock, aName);
- mBlockToFluidMap.put(aBlock, aFluid);
- mBlockToBucketMap.put(aBlock, aBucket);
- mBlockToMetaMap.put(aBlock, aID);
+ mMetaToNameMap.put(aID, aName);
+ mMetaToFluidMap.put(aID, aFluid);
+ mMetaToBucketMap.put(aID, aBucket);
+ mMetaToBlockMap.put(aID, aBlock);
- mMetaToNameMap.put(aID, aName);
- mMetaToFluidMap.put(aID, aFluid);
- mMetaToBucketMap.put(aID, aBucket);
- mMetaToBlockMap.put(aID, aBlock);
-
- mMetaToColourMap.put(aID, aFluid.getColor());
-
- mID = aID;
- mName = aName;
- mFluid = aFluid;
- mBucket = aBucket;
- mBlock = aBlock;
+ mMetaToColourMap.put(aID, aFluid.getColor());
- }
-
- public Fluid get() {
- return mFluid;
- }
-
- public boolean valid() {
- return mName != null && mName.length() > 0 && mFluid != null && mBucket != null && mBlock != null;
- }
+ mID = aID;
+ mName = aName;
+ mFluid = aFluid;
+ mBucket = aBucket;
+ mBlock = aBlock;
+ }
+ public Fluid get() {
+ return mFluid;
+ }
+
+ public boolean valid() {
+ return mName != null && mName.length() > 0 && mFluid != null && mBucket != null && mBlock != null;
+ }
}
diff --git a/src/main/java/gtPlusPlus/core/fluids/FluidRegistryHandler.java b/src/main/java/gtPlusPlus/core/fluids/FluidRegistryHandler.java
index bc4df596de..3a0f56c2a5 100644
--- a/src/main/java/gtPlusPlus/core/fluids/FluidRegistryHandler.java
+++ b/src/main/java/gtPlusPlus/core/fluids/FluidRegistryHandler.java
@@ -3,51 +3,49 @@ package gtPlusPlus.core.fluids;
import static gtPlusPlus.core.block.ModBlocks.*;
import cpw.mods.fml.common.registry.GameRegistry;
-
-import net.minecraft.block.material.Material;
-
import gtPlusPlus.core.block.general.fluids.BlockFluidSludge;
import gtPlusPlus.core.lib.CORE;
+import net.minecraft.block.material.Material;
import net.minecraftforge.fluids.FluidRegistry;
public class FluidRegistryHandler {
- //Fluids
- /**
- *
- * Luminosity .setLuminosity(luminosity)
- How much light does the fluid emit. Default: 0, Lava uses 15
- Density .setDensity(density)
- How dense is the fluid, the only effect is whether or not a fluid replaces another fluid when they flow into each other. Default: 1000, the density of water at 4 degrees Celsius in kg/m³
- Temperature .setTemperature(temp)
- How hot, or cold is the fluid. Has currently no effect. Default: 295, the "normal" room temperature in degrees Kelvin, this is approximately 72°F or 22°C.
- Viscosity .setViscosity(viscosity)
- How thick the fluid is. Determines how fast it flows. Default: 1000 for water, lava uses 6000
- Is Gaseous .setGaseous(boolean)
- Indicates if the fluid is gaseous. Used for rendering. Default: false
- *
- */
-
- public static void registerFluids(){
- run();
- }
-
- private static void run(){
- fluidSludge();
- }
-
- private static void fluidSludge(){
- //testFluid
- fluidSludge.setLuminosity(8);
- fluidSludge.setDensity(8196);
- fluidSludge.setTemperature(295);
- fluidSludge.setViscosity(3000);
- fluidSludge.setGaseous(false);
- fluidSludge.setUnlocalizedName("fluid.sludge");
- FluidRegistry.registerFluid(fluidSludge);
- blockFluidSludge = new BlockFluidSludge(fluidSludge, Material.cactus).setBlockName("fluidBlockSludge");
- GameRegistry.registerBlock(blockFluidSludge, CORE.MODID + "_" + blockFluidSludge.getUnlocalizedName().substring(5));
- fluidSludge.setUnlocalizedName(blockFluidSludge.getUnlocalizedName());
- }
-
+ // Fluids
+ /**
+ *
+ * Luminosity .setLuminosity(luminosity)
+ * How much light does the fluid emit. Default: 0, Lava uses 15
+ * Density .setDensity(density)
+ * How dense is the fluid, the only effect is whether or not a fluid replaces another fluid when they flow into each other. Default: 1000, the density of water at 4 degrees Celsius in kg/m³
+ * Temperature .setTemperature(temp)
+ * How hot, or cold is the fluid. Has currently no effect. Default: 295, the "normal" room temperature in degrees Kelvin, this is approximately 72°F or 22°C.
+ * Viscosity .setViscosity(viscosity)
+ * How thick the fluid is. Determines how fast it flows. Default: 1000 for water, lava uses 6000
+ * Is Gaseous .setGaseous(boolean)
+ * Indicates if the fluid is gaseous. Used for rendering. Default: false
+ *
+ */
+ public static void registerFluids() {
+ run();
+ }
+
+ private static void run() {
+ fluidSludge();
+ }
+
+ private static void fluidSludge() {
+ // testFluid
+ fluidSludge.setLuminosity(8);
+ fluidSludge.setDensity(8196);
+ fluidSludge.setTemperature(295);
+ fluidSludge.setViscosity(3000);
+ fluidSludge.setGaseous(false);
+ fluidSludge.setUnlocalizedName("fluid.sludge");
+ FluidRegistry.registerFluid(fluidSludge);
+ blockFluidSludge = new BlockFluidSludge(fluidSludge, Material.cactus).setBlockName("fluidBlockSludge");
+ GameRegistry.registerBlock(
+ blockFluidSludge,
+ CORE.MODID + "_" + blockFluidSludge.getUnlocalizedName().substring(5));
+ fluidSludge.setUnlocalizedName(blockFluidSludge.getUnlocalizedName());
+ }
}
diff --git a/src/main/java/gtPlusPlus/core/fluids/ItemGenericFluidBucket.java b/src/main/java/gtPlusPlus/core/fluids/ItemGenericFluidBucket.java
index 6354be632d..ed1cc112c3 100644
--- a/src/main/java/gtPlusPlus/core/fluids/ItemGenericFluidBucket.java
+++ b/src/main/java/gtPlusPlus/core/fluids/ItemGenericFluidBucket.java
@@ -1,14 +1,13 @@
package gtPlusPlus.core.fluids;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
import cpw.mods.fml.common.eventhandler.Event;
import gtPlusPlus.api.objects.GregtechException;
import gtPlusPlus.api.objects.data.AutoMap;
import gtPlusPlus.core.lib.CORE;
import gtPlusPlus.core.util.minecraft.ItemUtils;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
@@ -27,293 +26,290 @@ import net.minecraftforge.event.entity.player.FillBucketEvent;
public class ItemGenericFluidBucket extends ItemBucket {
- private static IIcon mBaseBucketTexture;
- private static IIcon mOverlayBucketTexture;
- private static AutoMap<Block> mInternalFluidCache = new AutoMap<Block>();
-
- public ItemGenericFluidBucket(Block aFluid) {
- super(aFluid);
- this.setContainerItem(Items.bucket);
- this.maxStackSize = 1;
- mInternalFluidCache.put(aFluid);
- }
-
- public static ItemStack registerFluidForBucket(int aID) {
-
- if (FluidFactory.mMetaToBucketMap.containsKey(aID)) {
- try {
- throw new GregtechException(""+aID+" is already registered! Unable to register fluid: "+FluidFactory.mMetaToFluidMap.get(aID).getLocalizedName());
- } catch (GregtechException e) {
- e.printStackTrace();
- CORE.crash(""+aID+" is already registered! Unable to register fluid: "+FluidFactory.mMetaToFluidMap.get(aID).getLocalizedName());
- }
- }
- mInternalFluidCache.put(FluidFactory.mMetaToBlockMap.get(aID));
- return ItemUtils.simpleMetaStack(FluidFactory.mGenericBucket, aID, 1);
- }
-
- Map<Integer, IIcon> mIconCache = new LinkedHashMap<Integer, IIcon>();
-
- /**
- * Called whenever this item is equipped and the right mouse button is pressed.
- * Args: itemStack, world, entityPlayer
- */
- public ItemStack onItemRightClick(ItemStack aStack, World aWorld, EntityPlayer aPlayer) {
-
- Block isFull = FluidFactory.mMetaToBlockMap.get(aStack.getItemDamage());
-
- boolean flag = isFull == Blocks.air;
- MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(aWorld, aPlayer, flag);
-
- if (movingobjectposition == null || isFull == null) {
- return aStack;
- } else {
- FillBucketEvent event = new FillBucketEvent(aPlayer, aStack, aWorld, movingobjectposition);
- if (MinecraftForge.EVENT_BUS.post(event)) {
- return aStack;
- }
-
- if (event.getResult() == Event.Result.ALLOW) {
- if (aPlayer.capabilities.isCreativeMode) {
- return aStack;
- }
-
- if (--aStack.stackSize <= 0) {
- return event.result;
- }
-
- if (!aPlayer.inventory.addItemStackToInventory(event.result)) {
- aPlayer.dropPlayerItemWithRandomChoice(event.result, false);
- }
-
- return aStack;
- }
- if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
- int i = movingobjectposition.blockX;
- int j = movingobjectposition.blockY;
- int k = movingobjectposition.blockZ;
-
- if (!aWorld.canMineBlock(aPlayer, i, j, k)) {
- return aStack;
- }
-
- if (flag) {
- if (!aPlayer.canPlayerEdit(i, j, k, movingobjectposition.sideHit, aStack)) {
- return aStack;
- }
-
- Material material = aWorld.getBlock(i, j, k).getMaterial();
- int l = aWorld.getBlockMetadata(i, j, k);
-
- if (material == Material.water && l == 0) {
- aWorld.setBlockToAir(i, j, k);
- return this.func_150910_a(aStack, aPlayer, Items.water_bucket);
- }
-
- if (material == Material.lava && l == 0) {
- aWorld.setBlockToAir(i, j, k);
- return this.func_150910_a(aStack, aPlayer, Items.lava_bucket);
- }
- } else {
- if (isFull == Blocks.air) {
- return new ItemStack(Items.bucket);
- }
-
- if (movingobjectposition.sideHit == 0) {
- --j;
- }
-
- if (movingobjectposition.sideHit == 1) {
- ++j;
- }
-
- if (movingobjectposition.sideHit == 2) {
- --k;
- }
-
- if (movingobjectposition.sideHit == 3) {
- ++k;
- }
-
- if (movingobjectposition.sideHit == 4) {
- --i;
- }
-
- if (movingobjectposition.sideHit == 5) {
- ++i;
- }
-
- if (!aPlayer.canPlayerEdit(i, j, k, movingobjectposition.sideHit, aStack)) {
- return aStack;
- }
-
- if (this.tryPlaceContainedLiquid(isFull, aWorld, i, j, k) && !aPlayer.capabilities.isCreativeMode) {
- return new ItemStack(Items.bucket);
- }
- }
- }
-
- return aStack;
- }
- }
-
- private ItemStack func_150910_a(ItemStack p_150910_1_, EntityPlayer p_150910_2_, Item p_150910_3_) {
- if (p_150910_2_.capabilities.isCreativeMode) {
- return p_150910_1_;
- } else if (--p_150910_1_.stackSize <= 0) {
- return new ItemStack(p_150910_3_);
- } else {
- if (!p_150910_2_.inventory.addItemStackToInventory(new ItemStack(p_150910_3_))) {
- p_150910_2_.dropPlayerItemWithRandomChoice(new ItemStack(p_150910_3_, 1, 0), false);
- }
-
- return p_150910_1_;
- }
- }
-
- /**
- * Attempts to place the liquid contained inside the bucket.
- */
- public boolean tryPlaceContainedLiquid(Block isFull, World aWorld, int aX, int aY, int aZ) {
- if (isFull == Blocks.air) {
- return false;
- } else {
- Material material = aWorld.getBlock(aX, aY, aZ).getMaterial();
- boolean flag = !material.isSolid();
-
- if (!aWorld.isAirBlock(aX, aY, aZ) && !flag) {
- return false;
- } else {
-
- if (!aWorld.isRemote && flag && !material.isLiquid()) {
- aWorld.func_147480_a(aX, aY, aZ, true);
- }
-
- aWorld.setBlock(aX, aY, aZ, isFull, 0, 3);
-
- return true;
- }
- }
- }
-
- @Override
- public IIcon getIconFromDamage(int aMeta) {
- IIcon aTemp = mIconCache.get(aMeta);
- return aTemp != null ? aTemp : super.getIconFromDamage(aMeta);
- }
-
- @Override
- public boolean getHasSubtypes() {
- return mInternalFluidCache.size() > 0;
- }
-
- @Override
- public void getSubItems(Item item, CreativeTabs tab, List list) {
- list.add(new ItemStack(item, 1, 0));
- for (Block f : mInternalFluidCache) {
- Integer aMeta;
- if (f != null) {
- aMeta = FluidFactory.mBlockToMetaMap.get(f);
- if (aMeta != null) {
- list.add(new ItemStack(item, 1, aMeta));
- }
- }
- }
- }
-
- @Override
- public int getMaxDamage() {
- return 512;
- }
-
- @Override
- public boolean isDamageable() {
- return false;
- }
-
- @Override
- public void addInformation(ItemStack p_77624_1_, EntityPlayer p_77624_2_, List p_77624_3_, boolean p_77624_4_) {
- // TODO Auto-generated method stub
- super.addInformation(p_77624_1_, p_77624_2_, p_77624_3_, p_77624_4_);
- }
-
- @Override
- public int getItemEnchantability() {
- return 0;
- }
-
- @Override
- public boolean isRepairable() {
- return false;
- }
-
- @Override
- public IIcon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining) {
- if (stack != null && renderPass == 1) {
- return mOverlayBucketTexture;
- }
- else {
- return mBaseBucketTexture;
- }
- /*IIcon aTemp = mIconCache.get(stack.getItemDamage());
- return aTemp != null ? aTemp : super.getIcon(stack, renderPass, player, usingItem, useRemaining);*/
- }
-
- @Override
- public boolean isBookEnchantable(ItemStack stack, ItemStack book) {
- return false;
- }
-
- @Override
- public int getMaxDamage(ItemStack stack) {
- return 512;
- }
-
- @Override
- public boolean isDamaged(ItemStack stack) {
- return false;
- }
-
- @Override
- public int getItemEnchantability(ItemStack stack) {
- return 0;
- }
-
- @Override
- public IIcon getIconFromDamageForRenderPass(final int damage, final int pass) {
- if (pass == 1) {
- return mOverlayBucketTexture;
- }
- else {
- return mBaseBucketTexture;
- }
- }
-
- @Override
- public void registerIcons(final IIconRegister i) {
- mBaseBucketTexture = i.registerIcon("bucket_empty");
- mOverlayBucketTexture = i.registerIcon(CORE.MODID+":bucket.generic.overlay");
- }
-
- @Override
- public boolean tryPlaceContainedLiquid(World p_77875_1_, int p_77875_2_, int p_77875_3_, int p_77875_4_) {
- return tryPlaceContainedLiquid(Blocks.air, p_77875_1_, p_77875_2_, p_77875_3_, p_77875_4_);
- }
-
- @Override
- public int getColorFromItemStack(ItemStack aStack, int aPass) {
- if (aPass == 0) {
- return super.getColorFromItemStack(aStack, aPass);
- }
- else {
- return FluidFactory.mMetaToColourMap.get(aStack.getItemDamage());
- }
- }
-
- @Override
- public boolean requiresMultipleRenderPasses() {
- return true;
- }
-
-
+ private static IIcon mBaseBucketTexture;
+ private static IIcon mOverlayBucketTexture;
+ private static AutoMap<Block> mInternalFluidCache = new AutoMap<Block>();
+
+ public ItemGenericFluidBucket(Block aFluid) {
+ super(aFluid);
+ this.setContainerItem(Items.bucket);
+ this.maxStackSize = 1;
+ mInternalFluidCache.put(aFluid);
+ }
+
+ public static ItemStack registerFluidForBucket(int aID) {
+
+ if (FluidFactory.mMetaToBucketMap.containsKey(aID)) {
+ try {
+ throw new GregtechException("" + aID + " is already registered! Unable to register fluid: "
+ + FluidFactory.mMetaToFluidMap.get(aID).getLocalizedName());
+ } catch (GregtechException e) {
+ e.printStackTrace();
+ CORE.crash("" + aID + " is already registered! Unable to register fluid: "
+ + FluidFactory.mMetaToFluidMap.get(aID).getLocalizedName());
+ }
+ }
+ mInternalFluidCache.put(FluidFactory.mMetaToBlockMap.get(aID));
+ return ItemUtils.simpleMetaStack(FluidFactory.mGenericBucket, aID, 1);
+ }
+
+ Map<Integer, IIcon> mIconCache = new LinkedHashMap<Integer, IIcon>();
+
+ /**
+ * Called whenever this item is equipped and the right mouse button is pressed.
+ * Args: itemStack, world, entityPlayer
+ */
+ public ItemStack onItemRightClick(ItemStack aStack, World aWorld, EntityPlayer aPlayer) {
+
+ Block isFull = FluidFactory.mMetaToBlockMap.get(aStack.getItemDamage());
+
+ boolean flag = isFull == Blocks.air;
+ MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(aWorld, aPlayer, flag);
+
+ if (movingobjectposition == null || isFull == null) {
+ return aStack;
+ } else {
+ FillBucketEvent event = new FillBucketEvent(aPlayer, aStack, aWorld, movingobjectposition);
+ if (MinecraftForge.EVENT_BUS.post(event)) {
+ return aStack;
+ }
+
+ if (event.getResult() == Event.Result.ALLOW) {
+ if (aPlayer.capabilities.isCreativeMode) {
+ return aStack;
+ }
+
+ if (--aStack.stackSize <= 0) {
+ return event.result;
+ }
+
+ if (!aPlayer.inventory.addItemStackToInventory(event.result)) {
+ aPlayer.dropPlayerItemWithRandomChoice(event.result, false);
+ }
+
+ return aStack;
+ }
+ if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
+ int i = movingobjectposition.blockX;
+ int j = movingobjectposition.blockY;
+ int k = movingobjectposition.blockZ;
+
+ if (!aWorld.canMineBlock(aPlayer, i, j, k)) {
+ return aStack;
+ }
+
+ if (flag) {
+ if (!aPlayer.canPlayerEdit(i, j, k, movingobjectposition.sideHit, aStack)) {
+ return aStack;
+ }
+
+ Material material = aWorld.getBlock(i, j, k).getMaterial();
+ int l = aWorld.getBlockMetadata(i, j, k);
+
+ if (material == Material.water && l == 0) {
+ aWorld.setBlockToAir(i, j, k);
+ return this.func_150910_a(aStack, aPlayer, Items.water_bucket);
+ }
+
+ if (material == Material.lava && l == 0) {
+ aWorld.setBlockToAir(i, j, k);
+ return this.func_150910_a(aStack, aPlayer, Items.lava_bucket);
+ }
+ } else {
+ if (isFull == Blocks.air) {
+ return new ItemStack(Items.bucket);
+ }
+
+ if (movingobjectposition.sideHit == 0) {
+ --j;
+ }
+
+ if (movingobjectposition.sideHit == 1) {
+ ++j;
+ }
+
+ if (movingobjectposition.sideHit == 2) {
+ --k;
+ }
+
+ if (movingobjectposition.sideHit == 3) {
+ ++k;
+ }
+
+ if (movingobjectposition.sideHit == 4) {
+ --i;
+ }
+
+ if (movingobjectposition.sideHit == 5) {
+ ++i;
+ }
+
+ if (!aPlayer.canPlayerEdit(i, j, k, movingobjectposition.sideHit, aStack)) {
+ return aStack;
+ }
+
+ if (this.tryPlaceContainedLiquid(isFull, aWorld, i, j, k) && !aPlayer.capabilities.isCreativeMode) {
+ return new ItemStack(Items.bucket);
+ }
+ }
+ }
+
+ return aStack;
+ }
+ }
+
+ private ItemStack func_150910_a(ItemStack p_150910_1_, EntityPlayer p_150910_2_, Item p_150910_3_) {
+ if (p_150910_2_.capabilities.isCreativeMode) {
+ return p_150910_1_;
+ } else if (--p_150910_1_.stackSize <= 0) {
+ return new ItemStack(p_150910_3_);
+ } else {
+ if (!p_150910_2_.inventory.addItemStackToInventory(new ItemStack(p_150910_3_))) {
+ p_150910_2_.dropPlayerItemWithRandomChoice(new ItemStack(p_150910_3_, 1, 0), false);
+ }
+
+ return p_150910_1_;
+ }
+ }
+
+ /**
+ * Attempts to place the liquid contained inside the bucket.
+ */
+ public boolean tryPlaceContainedLiquid(Block isFull, World aWorld, int aX, int aY, int aZ) {
+ if (isFull == Blocks.air) {
+ return false;
+ } else {
+ Material material = aWorld.getBlock(aX, aY, aZ).getMaterial();
+ boolean flag = !material.isSolid();
+
+ if (!aWorld.isAirBlock(aX, aY, aZ) && !flag) {
+ return false;
+ } else {
+
+ if (!aWorld.isRemote && flag && !material.isLiquid()) {
+ aWorld.func_147480_a(aX, aY, aZ, true);
+ }
+
+ aWorld.setBlock(aX, aY, aZ, isFull, 0, 3);
+
+ return true;
+ }
+ }
+ }
+
+ @Override
+ public IIcon getIconFromDamage(int aMeta) {
+ IIcon aTemp = mIconCache.get(aMeta);
+ return aTemp != null ? aTemp : super.getIconFromDamage(aMeta);
+ }
+
+ @Override
+ public boolean getHasSubtypes() {
+ return mInternalFluidCache.size() > 0;
+ }
+
+ @Override
+ public void getSubItems(Item item, CreativeTabs tab, List list) {
+ list.add(new ItemStack(item, 1, 0));
+ for (Block f : mInternalFluidCache) {
+ Integer aMeta;
+ if (f != null) {
+ aMeta = FluidFactory.mBlockToMetaMap.get(f);
+ if (aMeta != null) {
+ list.add(new ItemStack(item, 1, aMeta));
+ }
+ }
+ }
+ }
+
+ @Override
+ public int getMaxDamage() {
+ return 512;
+ }
+
+ @Override
+ public boolean isDamageable() {
+ return false;
+ }
+
+ @Override
+ public void addInformation(ItemStack p_77624_1_, EntityPlayer p_77624_2_, List p_77624_3_, boolean p_77624_4_) {
+ // TODO Auto-generated method stub
+ super.addInformation(p_77624_1_, p_77624_2_, p_77624_3_, p_77624_4_);
+ }
+
+ @Override
+ public int getItemEnchantability() {
+ return 0;
+ }
+
+ @Override
+ public boolean isRepairable() {
+ return false;
+ }
+
+ @Override
+ public IIcon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining) {
+ if (stack != null && renderPass == 1) {
+ return mOverlayBucketTexture;
+ } else {
+ return mBaseBucketTexture;
+ }
+ /*IIcon aTemp = mIconCache.get(stack.getItemDamage());
+ return aTemp != null ? aTemp : super.getIcon(stack, renderPass, player, usingItem, useRemaining);*/
+ }
+
+ @Override
+ public boolean isBookEnchantable(ItemStack stack, ItemStack book) {
+ return false;
+ }
+
+ @Override
+ public int getMaxDamage(ItemStack stack) {
+ return 512;
+ }
+
+ @Override
+ public boolean isDamaged(ItemStack stack) {
+ return false;
+ }
+
+ @Override
+ public int getItemEnchantability(ItemStack stack) {
+ return 0;
+ }
+
+ @Override
+ public IIcon getIconFromDamageForRenderPass(final int damage, final int pass) {
+ if (pass == 1) {
+ return mOverlayBucketTexture;
+ } else {
+ return mBaseBucketTexture;
+ }
+ }
+
+ @Override
+ public void registerIcons(final IIconRegister i) {
+ mBaseBucketTexture = i.registerIcon("bucket_empty");
+ mOverlayBucketTexture = i.registerIcon(CORE.MODID + ":bucket.generic.overlay");
+ }
+
+ @Override
+ public boolean tryPlaceContainedLiquid(World p_77875_1_, int p_77875_2_, int p_77875_3_, int p_77875_4_) {
+ return tryPlaceContainedLiquid(Blocks.air, p_77875_1_, p_77875_2_, p_77875_3_, p_77875_4_);
+ }
+
+ @Override
+ public int getColorFromItemStack(ItemStack aStack, int aPass) {
+ if (aPass == 0) {
+ return super.getColorFromItemStack(aStack, aPass);
+ } else {
+ return FluidFactory.mMetaToColourMap.get(aStack.getItemDamage());
+ }
+ }
+
+ @Override
+ public boolean requiresMultipleRenderPasses() {
+ return true;
+ }
}