From fbec8d04583389bae257940088948958f17b62bc Mon Sep 17 00:00:00 2001 From: DrZed Date: Thu, 6 Oct 2016 22:42:02 -0400 Subject: [PATCH] Gray liquids, to be RGD'd later in custom renderer --- src/main/java/HxCKDMS/HxCTiC/HxCTiC.java | 5 ++ src/main/java/HxCKDMS/HxCTiC/LeFluid.java | 57 +++++++++++++++++++ .../HxCTiC/{ => lib}/Configurations.java | 7 ++- .../java/HxCKDMS/HxCTiC/lib/HxCMaterial.java | 45 ++++++++++++++- .../java/HxCKDMS/HxCTiC/lib/Registry.java | 31 ++++++++++ .../resources/assets/hxctic/lang/en_US.lang | 4 +- 6 files changed, 144 insertions(+), 5 deletions(-) create mode 100644 src/main/java/HxCKDMS/HxCTiC/LeFluid.java rename src/main/java/HxCKDMS/HxCTiC/{ => lib}/Configurations.java (53%) create mode 100644 src/main/java/HxCKDMS/HxCTiC/lib/Registry.java diff --git a/src/main/java/HxCKDMS/HxCTiC/HxCTiC.java b/src/main/java/HxCKDMS/HxCTiC/HxCTiC.java index f2bc153..2dfc2a6 100644 --- a/src/main/java/HxCKDMS/HxCTiC/HxCTiC.java +++ b/src/main/java/HxCKDMS/HxCTiC/HxCTiC.java @@ -3,7 +3,9 @@ import HxCKDMS.HxCCore.HxCCore; import HxCKDMS.HxCCore.api.Configuration.Handlers.SpecialHandlers; import HxCKDMS.HxCCore.api.Configuration.HxCConfig; +import HxCKDMS.HxCTiC.lib.Configurations; import HxCKDMS.HxCTiC.lib.HxCMaterial; +import HxCKDMS.HxCTiC.lib.Registry; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; @@ -16,6 +18,7 @@ @Mod(modid = MOD_ID, name = MOD_NAME, version = VERSION, dependencies = DEPENDENCIES) public class HxCTiC { + @Instance(MOD_ID) public static HxCTiC instance; public static SimpleNetworkWrapper networkWrapper = new SimpleNetworkWrapper(CHANNEL_NAME); @@ -26,10 +29,12 @@ public void preinit(FMLPreInitializationEvent event) { SpecialHandlers.registerSpecialClass(HxCMaterial.class); hxCConfig = new HxCConfig(Configurations.class, "HxCTiC", HxCCore.HxCConfigDir, "cfg", MOD_ID); hxCConfig.initConfiguration(); + Registry.preinit(); } @EventHandler public void init(FMLInitializationEvent event) { + Registry.init(); Configurations.materials.values().forEach(HxCMaterial::init); } @EventHandler diff --git a/src/main/java/HxCKDMS/HxCTiC/LeFluid.java b/src/main/java/HxCKDMS/HxCTiC/LeFluid.java new file mode 100644 index 0000000..4b7475b --- /dev/null +++ b/src/main/java/HxCKDMS/HxCTiC/LeFluid.java @@ -0,0 +1,57 @@ +package HxCKDMS.HxCTiC; + +import HxCKDMS.HxCTiC.lib.Reference; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.fluids.BlockFluidClassic; +import net.minecraftforge.fluids.Fluid; + +public class LeFluid extends BlockFluidClassic { + + @SideOnly(Side.CLIENT) + protected IIcon stillIcon; + @SideOnly(Side.CLIENT) + protected IIcon flowingIcon; + private int color; + public LeFluid(Fluid fluid, int Color) { + super(fluid, Material.lava); + setCreativeTab(CreativeTabs.tabMisc); + color = Color; + } + + @Override + public IIcon getIcon(int side, int meta) { + return (side == 0 || side == 1)? stillIcon : flowingIcon; + } + + @Override + public int getBlockColor() { + return color; + } + + @SideOnly(Side.CLIENT) + @Override + public void registerBlockIcons(IIconRegister register) { + stillIcon = register.registerIcon(Reference.MOD_ID + ":fluidStill"); + flowingIcon = register.registerIcon(Reference.MOD_ID + ":fluidFlowing"); + } + + @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/HxCKDMS/HxCTiC/Configurations.java b/src/main/java/HxCKDMS/HxCTiC/lib/Configurations.java similarity index 53% rename from src/main/java/HxCKDMS/HxCTiC/Configurations.java rename to src/main/java/HxCKDMS/HxCTiC/lib/Configurations.java index f161194..38abae1 100644 --- a/src/main/java/HxCKDMS/HxCTiC/Configurations.java +++ b/src/main/java/HxCKDMS/HxCTiC/lib/Configurations.java @@ -1,7 +1,6 @@ -package HxCKDMS.HxCTiC; +package HxCKDMS.HxCTiC.lib; import HxCKDMS.HxCCore.api.Configuration.Config; -import HxCKDMS.HxCTiC.lib.HxCMaterial; import net.minecraft.util.EnumChatFormatting; import java.util.HashMap; @@ -11,6 +10,8 @@ public class Configurations { public static HashMap materials = new HashMap(){{ //Proof of concept before I sleep, OP as fuck not gonna really exist... - putIfAbsent("Potato", new HxCMaterial(500, "potato", 5000, 30, 5, 15, 5.0f, 4, 1, 10, 1, 1, 0.1f, EnumChatFormatting.YELLOW.toString(), 0xffffff00)); + putIfAbsent("Potato", new HxCMaterial(500, "potato", 5000, 30, 5, 15, 5.0f, 4, 1, 10, 1, 1, 0.1f, EnumChatFormatting.YELLOW.toString(), 0xffffff00, "cropPotato", 1, false)); + putIfAbsent("Carrot", new HxCMaterial(501, "carrot", 50, 10, 7, 5, 10.0f, 2, 1, 10, 1, 1, 0.1f, EnumChatFormatting.GOLD.toString(), 0xffffCC00, "cropCarrot", 1, false)); + putIfAbsent("Quartz", new HxCMaterial(502, "quartz", 50, 10, 4, 25, 1.5f, 2, 1, 10, 1, 1, 0.1f, EnumChatFormatting.GRAY.toString(), 0xffCCCCCC, "gemQuartz", 1, false)); }}; } diff --git a/src/main/java/HxCKDMS/HxCTiC/lib/HxCMaterial.java b/src/main/java/HxCKDMS/HxCTiC/lib/HxCMaterial.java index 91508c2..4b5a50b 100644 --- a/src/main/java/HxCKDMS/HxCTiC/lib/HxCMaterial.java +++ b/src/main/java/HxCKDMS/HxCTiC/lib/HxCMaterial.java @@ -3,8 +3,12 @@ import HxCKDMS.HxCCore.Configs.Configurations; import HxCKDMS.HxCCore.api.Utils.LogHelper; import cpw.mods.fml.common.event.FMLInterModComms; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.oredict.OreDictionary; @SuppressWarnings("WeakerAccess") public class HxCMaterial { @@ -24,9 +28,13 @@ public class HxCMaterial { public float ProjectileFragility; public String Style = EnumChatFormatting.WHITE.toString(); public int Colour = 0xFFFFFFFF; + public String OreDictionaryItem; + public int RequiredAmountOfMaterial; + public boolean StampedMaterial = false; + public HxCMaterial () {} - public HxCMaterial (int id, String name, int durability, int miningSpeed, int miningLevel, int attack, float durabilityMod, int reinforcement, int stonebound, float projSpeed, int drawSpeed, float mass, float fragility, String style, int color) { + public HxCMaterial (int id, String name, int durability, int miningSpeed, int miningLevel, int attack, float durabilityMod, int reinforcement, int stonebound, float projSpeed, int drawSpeed, float mass, float fragility, String style, int color, String oreDict, int amount, boolean Stamped) { MaterialID = id; MaterialName = name; LocalizationString = "material.hxctic." + name.toLowerCase(); @@ -43,6 +51,9 @@ public HxCMaterial (int id, String name, int durability, int miningSpeed, int mi ProjectileFragility = fragility; Style = style; Colour = color; + OreDictionaryItem = oreDict; + RequiredAmountOfMaterial = amount; + StampedMaterial = Stamped; if (Configurations.DebugMode) LogHelper.info(String.format("Registered material : %1$s with traits : ID = %2$s , Name = %3$s , Durability = %4$s , MiningSpeed = %5$s , MiningLevel = %6$s , AttackDamage = %7$s , DurabilityToolModifier = %8$s , ReinforcementLevel = %9$s , StoneboundLevel = %10$s , ProjectileSpeed = %11$s , DrawSpeed = %12$s , Mass = %13$s , Fragility = %14$s", name, id, name, durability, miningSpeed, miningLevel, attack, durabilityMod, reinforcement, stonebound, projSpeed, drawSpeed, mass, fragility), Reference.MOD_ID); } @@ -70,5 +81,37 @@ public void init() { tag.setString("Style", Style); tag.setInteger("Color", Colour); FMLInterModComms.sendMessage("TConstruct", "addMaterial", tag); + + if (OreDictionary.doesOreNameExist(OreDictionaryItem)) { + tag = new NBTTagCompound(); + tag.setInteger("MaterialId", MaterialID); + tag.setInteger("Value", 1); // 1 material ever 2 value. See PartMapping IMC + NBTTagCompound item = new NBTTagCompound(); + (new ItemStack(OreDictionary.getOres(OreDictionaryItem).get(0).getItem())).writeToNBT(item); + tag.setTag("Item", item); + + FMLInterModComms.sendMessage("TConstruct", "addMaterialItem", tag); + + tag = new NBTTagCompound(); + item = new NBTTagCompound(); + (new ItemStack(OreDictionary.getOres(OreDictionaryItem).get(0).getItem())).writeToNBT(item); + tag.setTag("Item", item); + item = new NBTTagCompound(); + (new ItemStack(Blocks.bedrock)).writeToNBT(item); + tag.setTag("Block", item); + + (new FluidStack(Registry.fluids.get("fluid_" + MaterialName.toLowerCase()), 144)).writeToNBT(tag); + + tag.setInteger("Temperature", 500); + FMLInterModComms.sendMessage("TConstruct", "addSmelteryMelting", tag); + + tag = new NBTTagCompound(); + // liquid to use + tag.setString("FluidName", "fluid_" + MaterialName.toLowerCase()); + // or this way, it's equal + (new FluidStack(Registry.fluids.get("fluid_" + MaterialName.toLowerCase()), 1)).writeToNBT(tag); + tag.setInteger("MaterialId", MaterialID); + FMLInterModComms.sendMessage("TConstruct", "addPartCastingMaterial", tag); + } } } diff --git a/src/main/java/HxCKDMS/HxCTiC/lib/Registry.java b/src/main/java/HxCKDMS/HxCTiC/lib/Registry.java new file mode 100644 index 0000000..278aedf --- /dev/null +++ b/src/main/java/HxCKDMS/HxCTiC/lib/Registry.java @@ -0,0 +1,31 @@ +package HxCKDMS.HxCTiC.lib; + +import HxCKDMS.HxCTiC.LeFluid; +import cpw.mods.fml.common.registry.GameRegistry; +import net.minecraft.block.Block; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; +import org.apache.commons.lang3.StringUtils; + +import java.util.HashMap; + +public class Registry { + public static HashMap fluids = new HashMap<>(); + public static HashMap leFluids = new HashMap<>(); + + public static void preinit() { + Configurations.materials.keySet().forEach(mat -> + fluids.putIfAbsent("fluid_" + mat.toLowerCase(), new Fluid("fluid_" + mat.toLowerCase()))); + } + + public static void init () { + fluids.forEach((name, fluid) -> { + FluidRegistry.registerFluid(fluid); + System.out.println(StringUtils.capitalize(name.substring(6))); + Block lef = new LeFluid(fluid, Configurations.materials.get(StringUtils.capitalize(name.substring(6))).Colour).setBlockName(name); + leFluids.putIfAbsent(name, lef); + GameRegistry.registerBlock(lef, Reference.MOD_ID + "_fluid_" + name); + fluid.setUnlocalizedName(lef.getUnlocalizedName()); + }); + } +} diff --git a/src/main/resources/assets/hxctic/lang/en_US.lang b/src/main/resources/assets/hxctic/lang/en_US.lang index fa6d4e2..136f958 100644 --- a/src/main/resources/assets/hxctic/lang/en_US.lang +++ b/src/main/resources/assets/hxctic/lang/en_US.lang @@ -1 +1,3 @@ -material.hxctic.potato=Potato Material \ No newline at end of file +material.hxctic.potato=Potato Material +material.hxctic.carrot=Carrot Material +material.hxctic.quartz=Quartz Material \ No newline at end of file