mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
more material shenanigans
This commit is contained in:
parent
c0cb5b3ebc
commit
b0647c3950
@ -9,6 +9,7 @@ import java.util.List;
|
||||
import static com.hbm.items.ModItems.*;
|
||||
import static com.hbm.blocks.ModBlocks.*;
|
||||
import static com.hbm.inventory.OreDictManager.DictFrame.*;
|
||||
import static com.hbm.inventory.OreNames.*;
|
||||
|
||||
import com.hbm.blocks.ModBlocks;
|
||||
import com.hbm.blocks.BlockEnums.EnumStoneType;
|
||||
@ -17,6 +18,7 @@ import com.hbm.hazard.HazardData;
|
||||
import com.hbm.hazard.HazardEntry;
|
||||
import com.hbm.hazard.HazardRegistry;
|
||||
import com.hbm.hazard.HazardSystem;
|
||||
import com.hbm.inventory.material.MatDistribution;
|
||||
import com.hbm.items.ItemEnums.EnumCokeType;
|
||||
import com.hbm.items.ItemEnums.EnumTarType;
|
||||
import com.hbm.main.MainRegistry;
|
||||
@ -82,23 +84,6 @@ public class OreDictManager {
|
||||
public static final String KEY_TOOL_CHEMISTRYSET = "ntmchemistryset";
|
||||
|
||||
public static final String KEY_CIRCUIT_BISMUTH = "circuitVersatile";
|
||||
|
||||
/*
|
||||
* PREFIXES
|
||||
*/
|
||||
public static final String ANY = "any";
|
||||
public static final String NUGGET = "nugget";
|
||||
public static final String TINY = "tiny";
|
||||
public static final String INGOT = "ingot";
|
||||
public static final String DUSTTINY = "dustTiny";
|
||||
public static final String DUST = "dust";
|
||||
public static final String GEM = "gem";
|
||||
public static final String CRYSTAL = "crystal";
|
||||
public static final String PLATE = "plate";
|
||||
public static final String BILLET = "billet";
|
||||
public static final String BLOCK = "block";
|
||||
public static final String ORE = "ore";
|
||||
public static final String ORENETHER = "oreNether";
|
||||
|
||||
/*
|
||||
* MATERIALS
|
||||
@ -492,6 +477,8 @@ public class OreDictManager {
|
||||
OreDictionary.registerOre("blockGlassLime", glass_trinitite);
|
||||
OreDictionary.registerOre("blockGlassRed", glass_polonium);
|
||||
OreDictionary.registerOre("blockGlassBlack", glass_ash);
|
||||
|
||||
MatDistribution.register(); //TEMP
|
||||
}
|
||||
|
||||
public static String getReflector() {
|
||||
|
||||
21
src/main/java/com/hbm/inventory/OreNames.java
Normal file
21
src/main/java/com/hbm/inventory/OreNames.java
Normal file
@ -0,0 +1,21 @@
|
||||
package com.hbm.inventory;
|
||||
|
||||
public class OreNames {
|
||||
|
||||
/*
|
||||
* PREFIXES
|
||||
*/
|
||||
public static final String ANY = "any";
|
||||
public static final String NUGGET = "nugget";
|
||||
public static final String TINY = "tiny";
|
||||
public static final String INGOT = "ingot";
|
||||
public static final String DUSTTINY = "dustTiny";
|
||||
public static final String DUST = "dust";
|
||||
public static final String GEM = "gem";
|
||||
public static final String CRYSTAL = "crystal";
|
||||
public static final String PLATE = "plate";
|
||||
public static final String BILLET = "billet";
|
||||
public static final String BLOCK = "block";
|
||||
public static final String ORE = "ore";
|
||||
public static final String ORENETHER = "oreNether";
|
||||
}
|
||||
@ -0,0 +1,65 @@
|
||||
package com.hbm.inventory.material;
|
||||
|
||||
import static com.hbm.inventory.material.Mats.*;
|
||||
import static com.hbm.inventory.material.MaterialShapes.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.hbm.inventory.OreDictManager;
|
||||
import com.hbm.inventory.RecipesCommon.ComparableStack;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class MatDistribution {
|
||||
|
||||
public static void register() {
|
||||
registerEntry(Blocks.rail, MAT_IRON, INGOT.q(6, 16));
|
||||
registerEntry(Blocks.golden_rail, MAT_GOLD, INGOT.q(6));
|
||||
registerEntry(Blocks.detector_rail, MAT_IRON, INGOT.q(6));
|
||||
registerEntry(Items.minecart, MAT_IRON, INGOT.q(5));
|
||||
|
||||
registerOre(OreDictManager.COAL.ore(), MAT_IRON, INGOT.q(4), MAT_STONE, QUART.q(1));
|
||||
registerOre(OreDictManager.IRON.ore(), MAT_IRON, INGOT.q(3), MAT_TITANIUM, INGOT.q(1), MAT_STONE, QUART.q(1));
|
||||
registerOre(OreDictManager.GOLD.ore(), MAT_GOLD, INGOT.q(3), MAT_LEAD, INGOT.q(1), MAT_STONE, QUART.q(1));
|
||||
}
|
||||
|
||||
public static void registerEntry(Object key, Object... matDef) {
|
||||
ComparableStack comp = null;
|
||||
|
||||
if(key instanceof Item) comp = new ComparableStack((Item) key);
|
||||
if(key instanceof Block) comp = new ComparableStack((Block) key);
|
||||
if(key instanceof ItemStack) comp = new ComparableStack((ItemStack) key);
|
||||
|
||||
if(comp == null) return;
|
||||
if(matDef.length % 2 == 1) return;
|
||||
|
||||
List<MaterialStack> stacks = new ArrayList();
|
||||
|
||||
for(int i = 0; i < matDef.length; i += 2) {
|
||||
stacks.add(new MaterialStack((NTMMaterial) matDef[i], (int) matDef[i + 1]));
|
||||
}
|
||||
|
||||
if(stacks.isEmpty()) return;
|
||||
|
||||
materialEntries.put(comp, stacks);
|
||||
}
|
||||
|
||||
public static void registerOre(String key, Object... matDef) {
|
||||
if(matDef.length % 2 == 1) return;
|
||||
|
||||
List<MaterialStack> stacks = new ArrayList();
|
||||
|
||||
for(int i = 0; i < matDef.length; i += 2) {
|
||||
stacks.add(new MaterialStack((NTMMaterial) matDef[i], (int) matDef[i + 1]));
|
||||
}
|
||||
|
||||
if(stacks.isEmpty()) return;
|
||||
|
||||
materialOreEntries.put(key, stacks);
|
||||
}
|
||||
}
|
||||
@ -10,6 +10,7 @@ public enum MaterialShapes {
|
||||
INGOT(NUGGET.quantity * 9, "ingot"),
|
||||
DUST(INGOT.quantity, "dust"),
|
||||
PLATE(INGOT.quantity, "plate"),
|
||||
QUART(162),
|
||||
BLOCK(INGOT.quantity * 9, "block");
|
||||
|
||||
int quantity;
|
||||
@ -23,4 +24,12 @@ public enum MaterialShapes {
|
||||
Mats.prefixByName.put(prefix, this);
|
||||
}
|
||||
}
|
||||
|
||||
public int q(int amount) {
|
||||
return this.quantity * amount;
|
||||
}
|
||||
|
||||
public int q(int unitsUsed, int itemsProduced) { //eg rails: INOGT.q(6, 16) since the recipe uses 6 ton ingots producing 16 individual rail blocks
|
||||
return this.quantity * unitsUsed / itemsProduced;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,12 +1,19 @@
|
||||
package com.hbm.inventory.material;
|
||||
|
||||
import static com.hbm.inventory.OreDictManager.*;
|
||||
import static com.hbm.inventory.material.MaterialShapes.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.hbm.inventory.OreDictManager;
|
||||
import com.hbm.inventory.OreDictManager.DictFrame;
|
||||
import com.hbm.inventory.RecipesCommon.ComparableStack;
|
||||
import com.hbm.inventory.material.NTMMaterial.SmeltingBehavior;
|
||||
import com.hbm.util.ItemStackUtil;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/* with every new rewrite, optimization and improvement, the code becomes more gregian */
|
||||
/**
|
||||
@ -18,16 +25,22 @@ public class Mats {
|
||||
|
||||
public static HashMap<String, MaterialShapes> prefixByName = new HashMap();
|
||||
public static HashMap<String, NTMMaterial> matByName = new HashMap();
|
||||
public static HashMap<ComparableStack, List<MaterialStack>> materialEntries = new HashMap();
|
||||
public static HashMap<String, List<MaterialStack>> materialOreEntries = new HashMap();
|
||||
|
||||
public static NTMMaterial
|
||||
IRON = makeSmeltable(OreDictManager.IRON, 0).omitAutoGen(),
|
||||
GOLD = makeSmeltable(OreDictManager.GOLD, 0).omitAutoGen(),
|
||||
STEEL = makeSmeltable(OreDictManager.STEEL, 0).setShapes(DUSTTINY, INGOT, DUST, PLATE, BLOCK),
|
||||
TUNGSTEN = makeSmeltable(OreDictManager.W, 0).setShapes(WIRE, INGOT, DUST, BLOCK),
|
||||
COPPER = makeSmeltable(OreDictManager.CU, 0).setShapes(WIRE, INGOT, DUST, PLATE, BLOCK),
|
||||
ALUMINIUM = makeSmeltable(OreDictManager.AL, 0).setShapes(WIRE, INGOT, DUST, PLATE, BLOCK),
|
||||
MINGRADE = makeSmeltable(OreDictManager.MINGRADE, 0).setShapes(WIRE, INGOT, DUST, BLOCK),
|
||||
ALLOY = makeSmeltable(OreDictManager.ALLOY, 0).setShapes(WIRE, INGOT, DUST, PLATE, BLOCK);
|
||||
public static final NTMMaterial
|
||||
MAT_STONE = makeSmeltable(new DictFrame("Stone"), 0),
|
||||
MAT_COAL = make(COAL).smeltable(SmeltingBehavior.ADDITIVE),
|
||||
MAT_IRON = makeSmeltable(IRON, 0).omitAutoGen(),
|
||||
MAT_GOLD = makeSmeltable(GOLD, 0).omitAutoGen(),
|
||||
MAT_STEEL = makeSmeltable(STEEL, 0).setShapes(DUSTTINY, INGOT, DUST, PLATE, BLOCK),
|
||||
MAT_TUNGSTEN = makeSmeltable(W, 0).setShapes(WIRE, INGOT, DUST, BLOCK),
|
||||
MAT_COPPER = makeSmeltable(CU, 0).setShapes(WIRE, INGOT, DUST, PLATE, BLOCK),
|
||||
MAT_ALUMINIUM = makeSmeltable(AL, 0).setShapes(WIRE, INGOT, DUST, PLATE, BLOCK),
|
||||
MAT_MINGRADE = makeSmeltable(MINGRADE, 0).setShapes(WIRE, INGOT, DUST, BLOCK),
|
||||
MAT_ALLOY = makeSmeltable(ALLOY, 0).setShapes(WIRE, INGOT, DUST, PLATE, BLOCK),
|
||||
MAT_TITANIUM = makeSmeltable(TI, 0).setShapes(INGOT, DUST, PLATE, BLOCK),
|
||||
MAT_LEAD = makeSmeltable(PB, 0).setShapes(NUGGET, INGOT, DUST, PLATE, BLOCK);
|
||||
|
||||
public static NTMMaterial make(DictFrame dict) {
|
||||
return new NTMMaterial(dict);
|
||||
@ -36,4 +49,74 @@ public class Mats {
|
||||
public static NTMMaterial makeSmeltable(DictFrame dict, int color) {
|
||||
return new NTMMaterial(dict).smeltable(SmeltingBehavior.SMELTABLE).setMoltenColor(color);
|
||||
}
|
||||
|
||||
public static List<MaterialStack> getMaterialsFromItem(ItemStack stack) {
|
||||
List<MaterialStack> list = new ArrayList();
|
||||
List<String> names = ItemStackUtil.getOreDictNames(stack);
|
||||
|
||||
if(!names.isEmpty()) {
|
||||
outer:
|
||||
for(String name : names) {
|
||||
|
||||
List<MaterialStack> oreEntries = materialOreEntries.get(name);
|
||||
|
||||
if(oreEntries != null) {
|
||||
list.addAll(oreEntries);
|
||||
break outer;
|
||||
}
|
||||
|
||||
for(Entry<String, MaterialShapes> prefixEntry : prefixByName.entrySet()) {
|
||||
String prefix = prefixEntry.getKey();
|
||||
|
||||
if(name.startsWith(prefix)) {
|
||||
String materialName = name.substring(prefix.length());
|
||||
NTMMaterial material = matByName.get(materialName);
|
||||
|
||||
if(material != null) {
|
||||
list.add(new MaterialStack(material, prefixEntry.getValue().quantity));
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<MaterialStack> entries = materialEntries.get(new ComparableStack(stack));
|
||||
|
||||
if(entries != null) {
|
||||
list.addAll(entries);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public static class MaterialStack {
|
||||
//final fields to prevent accidental changing
|
||||
public final NTMMaterial material;
|
||||
public final int amount;
|
||||
|
||||
public MaterialStack(NTMMaterial material, int amount) {
|
||||
this.material = material;
|
||||
this.amount = amount;
|
||||
}
|
||||
}
|
||||
|
||||
public static String formatAmount(int amount) {
|
||||
String format = "";
|
||||
|
||||
int blocks = amount / BLOCK.quantity;
|
||||
amount -= BLOCK.q(blocks);
|
||||
int ingots = amount / INGOT.quantity;
|
||||
amount -= INGOT.q(ingots);
|
||||
int nuggets = amount / NUGGET.quantity;
|
||||
amount -= NUGGET.q(nuggets);
|
||||
int quanta = amount;
|
||||
|
||||
if(blocks > 0) format += blocks + " Blocks ";
|
||||
if(ingots > 0) format += ingots + " Ingots ";
|
||||
if(nuggets > 0) format += nuggets + " Nuggets ";
|
||||
if(quanta > 0) format += quanta + " Quanta ";
|
||||
|
||||
return format.trim();
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ import com.hbm.inventory.OreDictManager.DictFrame;
|
||||
*/
|
||||
public class NTMMaterial {
|
||||
|
||||
public String[] names;
|
||||
public MaterialShapes[] shapes = new MaterialShapes[0];
|
||||
public boolean omitItemGen = false;
|
||||
public SmeltingBehavior smeltable = SmeltingBehavior.NOT_SMELTABLE;
|
||||
@ -16,6 +17,8 @@ public class NTMMaterial {
|
||||
|
||||
public NTMMaterial(DictFrame dict) {
|
||||
|
||||
this.names = dict.mats;
|
||||
|
||||
for(String name : dict.mats) {
|
||||
Mats.matByName.put(name, this);
|
||||
}
|
||||
|
||||
@ -25,6 +25,8 @@ import com.hbm.interfaces.IItemHUD;
|
||||
import com.hbm.interfaces.Spaghetti;
|
||||
import com.hbm.inventory.RecipesCommon.ComparableStack;
|
||||
import com.hbm.inventory.gui.GUIArmorTable;
|
||||
import com.hbm.inventory.material.Mats;
|
||||
import com.hbm.inventory.material.Mats.MaterialStack;
|
||||
import com.hbm.items.ModItems;
|
||||
import com.hbm.items.armor.ArmorFSB;
|
||||
import com.hbm.items.armor.ArmorFSBPowered;
|
||||
@ -625,6 +627,14 @@ public class ModEventHandlerClient {
|
||||
if(cannery != null) {
|
||||
list.add(EnumChatFormatting.GREEN + I18nUtil.resolveKey("cannery.f1"));
|
||||
}
|
||||
|
||||
List<MaterialStack> materials = Mats.getMaterialsFromItem(new ComparableStack(stack).makeSingular().toStack());
|
||||
|
||||
if(!materials.isEmpty()) {
|
||||
for(MaterialStack mat : materials) {
|
||||
list.add(EnumChatFormatting.DARK_PURPLE + mat.material.names[0] + ": " + Mats.formatAmount(mat.amount * stack.stackSize));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ResourceLocation ashes = new ResourceLocation(RefStrings.MODID + ":textures/misc/overlay_ash.png");
|
||||
|
||||
@ -5,15 +5,21 @@ import com.hbm.inventory.gui.GUICrucible;
|
||||
import com.hbm.tileentity.IGUIProvider;
|
||||
import com.hbm.tileentity.TileEntityMachineBase;
|
||||
|
||||
import api.hbm.tile.IHeatSource;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class TileEntityCrucible extends TileEntityMachineBase implements IGUIProvider {
|
||||
|
||||
public int heat;
|
||||
public static final int maxHeat = 100_000;
|
||||
public static final double diffusion = 0.25D;
|
||||
|
||||
public TileEntityCrucible() {
|
||||
super(10);
|
||||
@ -27,6 +33,33 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
tryPullHeat();
|
||||
}
|
||||
}
|
||||
|
||||
protected void tryPullHeat() {
|
||||
TileEntity con = worldObj.getTileEntity(xCoord, yCoord - 1, zCoord);
|
||||
|
||||
if(con instanceof IHeatSource) {
|
||||
IHeatSource source = (IHeatSource) con;
|
||||
int diff = source.getHeatStored() - this.heat;
|
||||
|
||||
if(diff == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(diff > 0) {
|
||||
diff = (int) Math.ceil(diff * diffusion);
|
||||
source.useUpHeat(diff);
|
||||
this.heat += diff;
|
||||
if(this.heat > this.maxHeat)
|
||||
this.heat = this.maxHeat;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.heat = Math.max(this.heat - Math.max(this.heat / 1000, 1), 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user