crucible fun

This commit is contained in:
Bob 2022-09-18 21:04:28 +02:00
parent ba21416f69
commit 8910c6c662
11 changed files with 350 additions and 16 deletions

View File

@ -3368,7 +3368,7 @@ public class ModBlocks {
GameRegistry.registerBlock(corium_block, corium_block.getUnlocalizedName());
GameRegistry.registerBlock(volcanic_lava_block, volcanic_lava_block.getUnlocalizedName());
GameRegistry.registerBlock(sulfuric_acid_block, sulfuric_acid_block.getUnlocalizedName());
GameRegistry.registerBlock(concrete_liquid, concrete_liquid.getUnlocalizedName());
//GameRegistry.registerBlock(concrete_liquid, concrete_liquid.getUnlocalizedName());
//Multiblock Dummy Blocks
GameRegistry.registerBlock(dummy_block_flare, dummy_block_flare.getUnlocalizedName());

View File

@ -104,10 +104,6 @@ public class FalloutConfigJSON {
entries.add(new FalloutEntry()
.mB(Blocks.mossy_cobblestone)
.prim(new Triplet(Blocks.coal_ore, 0, 1)));
entries.add(new FalloutEntry()
.mB(Blocks.coal_ore)
.prim(new Triplet(Blocks.diamond_ore, 0, 3), new Triplet(Blocks.emerald_ore, 0, 2))
.c(0.2));
entries.add(new FalloutEntry()
.mB(Blocks.coal_ore)
.prim(new Triplet(Blocks.diamond_ore, 0, 3), new Triplet(Blocks.emerald_ore, 0, 2))

View File

@ -26,6 +26,7 @@ public class GeneralConfig {
public static boolean enableRenderDistCheck = true;
public static boolean enableCustomDashKeybind = false;
public static boolean enableReEval = true;
public static boolean enableSilentCompStackErrors = true;
public static int hintPos = 0;
public static boolean enable528 = false;
@ -75,8 +76,9 @@ public class GeneralConfig {
enableRenderDistCheck = config.get(CATEGORY_GENERAL, "1.25_enableRenderDistCheck", true, "Check invalid render distances (over 16, without OptiFine) and fix it").getBoolean(true);
enableCustomDashKeybind = config.get(CATEGORY_GENERAL, "1.26_enableCustomDashKeybind", false, "Enable custom dash keybind instead of shift").getBoolean(false);
enableReEval = config.get(CATEGORY_GENERAL, "1.27_enableReEval", true, "Allows re-evaluating power networks on link remove instead of destroying and recreating").getBoolean(true);
enableSilentCompStackErrors = config.get(CATEGORY_GENERAL, "1.28_enableSilentCompStackErrors", false, "Enabling this will disable log spam created by unregistered items in ComparableStack instances.").getBoolean(false);
hintPos = CommonConfig.createConfigInt(config, CATEGORY_GENERAL, "1.27_hudOverlayPosition", "0: Top left\n1: Top right\n2: Center right\n3: Center Left", 0);
hintPos = CommonConfig.createConfigInt(config, CATEGORY_GENERAL, "1.29_hudOverlayPosition", "0: Top left\n1: Top right\n2: Center right\n3: Center Left", 0);
final String CATEGORY_528 = CommonConfig.CATEGORY_528;

View File

@ -4,10 +4,11 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.hbm.config.GeneralConfig;
import com.hbm.items.ModItems;
import com.hbm.main.MainRegistry;
import net.minecraft.block.Block;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -179,17 +180,21 @@ public class RecipesCommon {
public int hashCode() {
if(item == null) {
MainRegistry.logger.error("ComparableStack has a null item! This is a serious issue!");
Thread.currentThread().dumpStack();
item = Items.stick;
if(!GeneralConfig.enableSilentCompStackErrors) {
MainRegistry.logger.error("ComparableStack has a null item! This is a serious issue!");
Thread.currentThread().dumpStack();
}
item = ModItems.nothing;
}
String name = Item.itemRegistry.getNameForObject(item);
if(name == null) {
MainRegistry.logger.error("ComparableStack holds an item that does not seem to be registered. How does that even happen?");
Thread.currentThread().dumpStack();
item = Items.stick; //we know sticks have a name, so sure, why not
if(!GeneralConfig.enableSilentCompStackErrors) {
MainRegistry.logger.error("ComparableStack holds an item that does not seem to be registered. How does that even happen? This error can be turned off with the config <enableSilentCompStackErrors>. Item name: " + item.getUnlocalizedName());
Thread.currentThread().dumpStack();
}
item = ModItems.nothing;
}
final int prime = 31;

View File

@ -76,6 +76,7 @@ public class Mats {
return new DictFrame(string);
}
/** will not respect stacksizes - all stacks will be treated as a singular */
public static List<MaterialStack> getMaterialsFromItem(ItemStack stack) {
List<MaterialStack> list = new ArrayList();
List<String> names = ItemStackUtil.getOreDictNames(stack);
@ -107,7 +108,7 @@ public class Mats {
}
}
List<MaterialStack> entries = materialEntries.get(new ComparableStack(stack));
List<MaterialStack> entries = materialEntries.get(new ComparableStack(stack).makeSingular());
if(entries != null) {
list.addAll(entries);
@ -119,12 +120,16 @@ public class Mats {
public static class MaterialStack {
//final fields to prevent accidental changing
public final NTMMaterial material;
public final int amount;
public int amount;
public MaterialStack(NTMMaterial material, int amount) {
this.material = material;
this.amount = amount;
}
public MaterialStack copy() {
return new MaterialStack(material, amount);
}
}
public static String formatAmount(int amount) {

View File

@ -0,0 +1,110 @@
package com.hbm.inventory.recipes;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import com.google.gson.JsonElement;
import com.google.gson.stream.JsonWriter;
import com.hbm.inventory.material.Mats;
import com.hbm.inventory.material.Mats.MaterialStack;
import com.hbm.inventory.recipes.loader.SerializableRecipe;
public class CrucibleRecipes extends SerializableRecipe {
public static HashMap<Integer, CrucibleRecipe> indexMapping = new HashMap();
public static List<CrucibleRecipe> recipes = new ArrayList();
@Override
public void registerDefaults() {
recipes.add(new CrucibleRecipe(0, "crucible.steel", 1)
.inputs(new MaterialStack(Mats.MAT_IRON, 10), new MaterialStack(Mats.MAT_COAL, 15))
.outputs(new MaterialStack(Mats.MAT_STEEL, 10)));
recipes.add(new CrucibleRecipe(1, "crucible.redcopper", 1)
.inputs(new MaterialStack(Mats.MAT_STEEL, 10), new MaterialStack(Mats.MAT_REDSTONE, 10))
.outputs(new MaterialStack(Mats.MAT_MINGRADE, 20)));
recipes.add(new CrucibleRecipe(2, "crucible.aa", 1)
.inputs(new MaterialStack(Mats.MAT_STEEL, 10), new MaterialStack(Mats.MAT_MINGRADE, 10))
.outputs(new MaterialStack(Mats.MAT_ALLOY, 20)));
}
public static class CrucibleRecipe {
public MaterialStack[] input;
public MaterialStack[] output;
private int id;
private String name;
public int frequency;
public CrucibleRecipe(int id, String name, int frequency) {
this.id = id;
this.name = name;
this.frequency = frequency;
if(!indexMapping.containsKey(id)) {
indexMapping.put(id, this);
} else {
throw new IllegalStateException("Crucible recipe " + name + " has been registered with duplicate id " + id + " used by " + indexMapping.get(id).name + "!");
}
}
public CrucibleRecipe inputs(MaterialStack... input) {
this.input = input;
return this;
}
public CrucibleRecipe outputs(MaterialStack... output) {
this.output = output;
return this;
}
public int getId() {
return this.id;
}
public String getName() {
return this.name;
}
public int getInputAmount() {
int content = 0;
for(MaterialStack stack : input) {
content += stack.amount;
}
return content;
}
}
@Override
public String getFileName() {
return "hbmCrucible.json";
}
@Override
public Object getRecipeObject() {
return this.recipes;
}
@Override
public void readRecipe(JsonElement recipe) {
}
@Override
public void writeRecipe(Object recipe, JsonWriter writer) throws IOException {
}
@Override
public void deleteRecipes() {
this.indexMapping.clear();
this.recipes.clear();
}
}

View File

@ -40,6 +40,7 @@ public abstract class SerializableRecipe {
public static void registerAllHandlers() {
recipeHandlers.add(new ShredderRecipes());
recipeHandlers.add(new ChemplantRecipes());
recipeHandlers.add(new CrucibleRecipes());
recipeHandlers.add(new CentrifugeRecipes());
recipeHandlers.add(new CyclotronRecipes());
recipeHandlers.add(new HadronRecipes());

View File

@ -1247,6 +1247,7 @@ public class ModItems {
public static Item assembly_template;
public static Item chemistry_template;
public static Item chemistry_icon;
public static Item crucible_template;
public static Item fluid_identifier;
public static Item fluid_identifier_multi;
public static Item fluid_icon;
@ -4869,6 +4870,7 @@ public class ModItems {
assembly_template = new ItemAssemblyTemplate().setUnlocalizedName("assembly_template").setMaxStackSize(1).setCreativeTab(MainRegistry.templateTab).setTextureName(RefStrings.MODID + ":assembly_template");
chemistry_template = new ItemChemistryTemplate().setUnlocalizedName("chemistry_template").setMaxStackSize(1).setCreativeTab(MainRegistry.templateTab).setTextureName(RefStrings.MODID + ":chemistry_template");
chemistry_icon = new ItemChemistryIcon().setUnlocalizedName("chemistry_icon").setMaxStackSize(1).setCreativeTab(null);
crucible_template = new ItemCrucibleTemplate().setUnlocalizedName("crucible_template").setMaxStackSize(1).setCreativeTab(MainRegistry.templateTab).setTextureName(RefStrings.MODID + ":crucible_template");
fluid_identifier = new ItemFluidIdentifier().setUnlocalizedName("fluid_identifier").setMaxStackSize(1).setCreativeTab(MainRegistry.templateTab).setTextureName(RefStrings.MODID + ":fluid_identifier");
fluid_identifier_multi = new ItemFluidIDMulti().setUnlocalizedName("fluid_identifier_multi").setMaxStackSize(1).setCreativeTab(MainRegistry.templateTab).setTextureName(RefStrings.MODID + ":fluid_identifier_multi");
fluid_icon = new ItemFluidIcon().setUnlocalizedName("fluid_icon").setCreativeTab(null).setTextureName(RefStrings.MODID + ":fluid_icon");
@ -6679,6 +6681,7 @@ public class ModItems {
GameRegistry.registerItem(assembly_template, assembly_template.getUnlocalizedName());
GameRegistry.registerItem(chemistry_template, chemistry_template.getUnlocalizedName());
GameRegistry.registerItem(chemistry_icon, chemistry_icon.getUnlocalizedName());
GameRegistry.registerItem(crucible_template, crucible_template.getUnlocalizedName());
//Machine Items
GameRegistry.registerItem(fuse, fuse.getUnlocalizedName());

View File

@ -0,0 +1,53 @@
package com.hbm.items.machine;
import java.util.List;
import com.hbm.inventory.material.Mats;
import com.hbm.inventory.material.Mats.MaterialStack;
import com.hbm.inventory.recipes.CrucibleRecipes;
import com.hbm.inventory.recipes.CrucibleRecipes.CrucibleRecipe;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
public class ItemCrucibleTemplate extends Item {
public ItemCrucibleTemplate() {
this.setHasSubtypes(true);
this.setMaxDamage(0);
}
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs tabs, List list) {
for(int i = 0; i < CrucibleRecipes.recipes.size(); i++) {
list.add(new ItemStack(item, 1, CrucibleRecipes.recipes.get(i).getId()));
}
}
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool) {
CrucibleRecipe recipe = CrucibleRecipes.indexMapping.get(stack.getItemDamage());
if(recipe == null) {
return;
}
list.add("Input:");
for(MaterialStack in : recipe.input) {
list.add("- " + in.material.names[0] + ": " + Mats.formatAmount(in.amount));
}
list.add("Output:");
for(MaterialStack out : recipe.output) {
list.add("- " + out.material.names[0] + ": " + Mats.formatAmount(out.amount));
}
}
}

View File

@ -1,7 +1,17 @@
package com.hbm.tileentity.machine;
import java.util.ArrayList;
import java.util.List;
import com.hbm.inventory.container.ContainerCrucible;
import com.hbm.inventory.gui.GUICrucible;
import com.hbm.inventory.material.MaterialShapes;
import com.hbm.inventory.material.Mats;
import com.hbm.inventory.material.Mats.MaterialStack;
import com.hbm.inventory.material.NTMMaterial;
import com.hbm.inventory.recipes.CrucibleRecipes;
import com.hbm.inventory.recipes.CrucibleRecipes.CrucibleRecipe;
import com.hbm.items.ModItems;
import com.hbm.tileentity.IGUIProvider;
import com.hbm.tileentity.TileEntityMachineBase;
@ -11,16 +21,24 @@ 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.item.ItemStack;
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 int progress;
public static final int processTime = 20_000;
public static final double diffusion = 0.25D;
public final int recipeCapacity = MaterialShapes.BLOCK.q(16);
public final int wasteCapacity = MaterialShapes.BLOCK.q(16);
public List<MaterialStack> recipeStack = new ArrayList();
public List<MaterialStack> wasteStack = new ArrayList();
public TileEntityCrucible() {
super(10);
}
@ -30,11 +48,20 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
return "container.machineCrucible";
}
@Override
public int getInventoryStackLimit() {
return 1; //prevents clogging
}
@Override
public void updateEntity() {
if(!worldObj.isRemote) {
tryPullHeat();
if(!trySmelt()) {
this.progress = 0;
}
}
}
@ -61,6 +88,138 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
this.heat = Math.max(this.heat - Math.max(this.heat / 1000, 1), 0);
}
protected boolean trySmelt() {
if(this.heat < maxHeat / 2) return false;
int slot = this.getFirstSmeltableSlot();
if(slot == -1) return false;
int delta = this.heat - (maxHeat / 2);
delta *= 0.05;
this.progress += delta;
this.heat -= delta;
if(this.progress >= processTime) {
this.progress = 0;
List<MaterialStack> materials = Mats.getMaterialsFromItem(slots[slot]);
CrucibleRecipe recipe = getLoadedRecipe();
for(MaterialStack material : materials) {
boolean mainStack = recipe != null && getQuantaFromType(recipe.input, material.material) > 0;
if(mainStack) {
this.addToStack(this.recipeStack, material);
} else {
this.addToStack(this.wasteStack, material);
}
}
this.decrStackSize(slot, 1);
}
return true;
}
protected int getFirstSmeltableSlot() {
for(int i = 1; i < 10; i++) {
ItemStack stack = slots[i];
if(stack != null && isItemSmeltable(stack)) {
return i;
}
}
return -1;
}
public boolean isItemSmeltable(ItemStack stack) {
List<MaterialStack> materials = Mats.getMaterialsFromItem(stack);
//if there's no materials in there at all, don't smelt
if(materials.isEmpty())
return false;
CrucibleRecipe recipe = getLoadedRecipe();
//needs to be true, will always be true if there's no recipe loaded
boolean matchesRecipe = recipe == null;
//the amount of material in the entire recipe input
int recipeContent = recipe != null ? recipe.getInputAmount() : 0;
//the total amount of the current waste stack, used for simulation
int wasteAmount = getQuantaFromType(this.wasteStack, null);
for(MaterialStack mat : materials) {
//if no recipe is loaded, everything will land in the waste stack
int recipeInputRequired = recipe != null ? getQuantaFromType(recipe.input, mat.material) : 0;
if(recipeInputRequired == 0) {
//if this type isn't required by the recipe, add it to the waste stack
wasteAmount += mat.amount;
} else {
//the maximum is the recipe's ratio scaled up to the recipe stack's capacity
int matMaximum = recipeInputRequired * this.recipeCapacity / recipeContent;
int amountStored = getQuantaFromType(recipeStack, mat.material);
matchesRecipe = true;
//if the amount of that input would exceed the amount dictated by the recipe, return false
if(recipe != null && amountStored + mat.amount > matMaximum)
return false;
}
}
//if the waste amount doesn't exceed the capacity and the recipe matches (or isn't null), return true
return wasteAmount <= this.wasteCapacity && matchesRecipe;
}
public void addToStack(List<MaterialStack> stack, MaterialStack matStack) {
for(MaterialStack mat : stack) {
if(mat.material == matStack.material) {
mat.amount += matStack.amount;
return;
}
}
stack.add(matStack.copy());
}
public CrucibleRecipe getLoadedRecipe() {
if(slots[0] != null && slots[0].getItem() == ModItems.crucible_template) {
return CrucibleRecipes.indexMapping.get(slots[0].getItemDamage());
}
return null;
}
/* "Arrays and Lists don't have a common ancestor" my fucking ass */
public int getQuantaFromType(MaterialStack[] stacks, NTMMaterial mat) {
for(MaterialStack stack : stacks) {
if(mat == null || stack.material == mat) {
return stack.amount;
}
}
return 0;
}
public int getQuantaFromType(List<MaterialStack> stacks, NTMMaterial mat) {
for(MaterialStack stack : stacks) {
if(mat == null || stack.material == mat) {
return stack.amount;
}
}
return 0;
}
@Override
public Container provideContainer(int ID, EntityPlayer player, World world, int x, int y, int z) {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.7 KiB

After

Width:  |  Height:  |  Size: 9.1 KiB