fixed diode lag, proper limit, functional crucible recipes, scraps

This commit is contained in:
Boblet 2022-09-29 16:52:05 +02:00
parent 1f2937c666
commit 46f11acb9b
17 changed files with 197 additions and 10 deletions

View File

@ -110,7 +110,7 @@ public class CableDiode extends BlockContainer implements ILookOverlay, IToolabl
TileEntityDiode diode = (TileEntityDiode) te;
List<String> text = new ArrayList();
text.add("Max.: " + BobMathUtil.getShortNumber(diode.getMaxPower()) + "HE/pulse");
text.add("Max.: " + BobMathUtil.getShortNumber(diode.getMaxPower()) + "HE/t");
ILookOverlay.printGeneric(event, I18nUtil.resolveKey(getUnlocalizedName() + ".name"), 0xffff00, 0x404000, text);
}
@ -168,6 +168,8 @@ public class CableDiode extends BlockContainer implements ILookOverlay, IToolabl
private boolean recursionBrake = false;
private long subBuffer;
private long contingent = 0;
private long lastTransfer = 0;
@Override
public long transferPower(long power) {
@ -175,9 +177,17 @@ public class CableDiode extends BlockContainer implements ILookOverlay, IToolabl
if(recursionBrake)
return power;
if(lastTransfer != worldObj.getTotalWorldTime()) {
lastTransfer = worldObj.getTotalWorldTime();
contingent = getMaxPower();
}
if(contingent <= 0)
return power;
//this part turns "maxPower" from a glorified transfer weight into an actual transfer cap
long overShoot = Math.max(0, power - getMaxPower());
power = Math.min(power, getMaxPower());
long overShoot = Math.max(0, power - contingent);
power = Math.min(power, contingent);
recursionBrake = true;
this.subBuffer = power;
@ -186,6 +196,9 @@ public class CableDiode extends BlockContainer implements ILookOverlay, IToolabl
this.sendPower(worldObj, xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, dir);
long ret = this.subBuffer;
long sent = power - ret;
contingent -= sent;
this.subBuffer = 0;
recursionBrake = false;

View File

@ -8,6 +8,7 @@ import java.util.List;
import com.hbm.inventory.OreDictManager;
import com.hbm.inventory.RecipesCommon.ComparableStack;
import com.hbm.items.ModItems;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
@ -18,11 +19,40 @@ import net.minecraft.item.ItemStack;
public class MatDistribution {
public static void register() {
//vanilla crap
registerOre("stone", MAT_STONE, BLOCK.q(1));
registerOre("cobblestone", MAT_STONE, BLOCK.q(1));
registerEntry(Blocks.obsidian, MAT_OBSIDIAN, BLOCK.q(1));
registerEntry(Blocks.rail, MAT_IRON, INGOT.q(6, 16));
registerEntry(Blocks.golden_rail, MAT_GOLD, INGOT.q(6), MAT_REDSTONE, DUST.q(1));
registerEntry(Blocks.detector_rail, MAT_IRON, INGOT.q(6), MAT_REDSTONE, DUST.q(1));
registerEntry(Items.minecart, MAT_IRON, INGOT.q(5));
//castables
registerEntry(ModItems.blade_titanium, MAT_TITANIUM, INGOT.q(2));
registerEntry(ModItems.blade_tungsten, MAT_TUNGSTEN, INGOT.q(2));
registerEntry(ModItems.blades_gold, MAT_GOLD, INGOT.q(4));
registerEntry(ModItems.blades_aluminium, MAT_ALUMINIUM, INGOT.q(4));
registerEntry(ModItems.blades_iron, MAT_IRON, INGOT.q(4));
registerEntry(ModItems.blades_steel, MAT_STEEL, INGOT.q(4));
registerEntry(ModItems.blades_titanium, MAT_TITANIUM, INGOT.q(4));
registerEntry(ModItems.blades_advanced_alloy, MAT_ALLOY, INGOT.q(4));
registerEntry(ModItems.blades_combine_steel, MAT_CMB, INGOT.q(4));
registerEntry(ModItems.blades_schrabidium, MAT_SCHRABIDIUM, INGOT.q(4));
registerEntry(ModItems.stamp_stone_flat, MAT_STONE, INGOT.q(3));
registerEntry(ModItems.stamp_iron_flat, MAT_IRON, INGOT.q(3));
registerEntry(ModItems.stamp_steel_flat, MAT_STEEL, INGOT.q(3));
registerEntry(ModItems.stamp_titanium_flat, MAT_TITANIUM, INGOT.q(3));
registerEntry(ModItems.stamp_obsidian_flat, MAT_OBSIDIAN, INGOT.q(3));
registerEntry(ModItems.stamp_schrabidium_flat, MAT_SCHRABIDIUM, INGOT.q(3));
registerEntry(ModItems.hull_small_steel, MAT_STEEL, INGOT.q(2));
registerEntry(ModItems.hull_small_aluminium, MAT_ALUMINIUM, INGOT.q(2));
registerEntry(ModItems.hull_big_steel, MAT_STEEL, INGOT.q(6));
registerEntry(ModItems.hull_big_aluminium, MAT_ALUMINIUM, INGOT.q(6));
registerEntry(ModItems.hull_big_titanium, MAT_TITANIUM, INGOT.q(6));
registerEntry(ModItems.pipes_steel, MAT_STEEL, BLOCK.q(3));
//actual ores
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));

View File

@ -24,6 +24,7 @@ import net.minecraft.item.ItemStack;
*/
public class Mats {
public static List<NTMMaterial> orderedList = new ArrayList();
public static HashMap<String, MaterialShapes> prefixByName = new HashMap();
public static HashMap<Integer, NTMMaterial> matById = new HashMap();
public static HashMap<String, NTMMaterial> matByName = new HashMap();

View File

@ -14,6 +14,7 @@ public class NTMMaterial {
public MaterialShapes[] shapes = new MaterialShapes[0];
public boolean omitItemGen = false;
public SmeltingBehavior smeltable = SmeltingBehavior.NOT_SMELTABLE;
public int solidColor = 0xFF4A00; //TODO
public int moltenColor = 0xFF4A00;
public NTMMaterial(int id, DictFrame dict) {
@ -25,6 +26,7 @@ public class NTMMaterial {
Mats.matByName.put(name, this);
}
Mats.orderedList.add(this);
Mats.matById.put(id, this);
}

View File

@ -15,8 +15,12 @@ public class CrucibleRecipes extends SerializableRecipe {
public static HashMap<Integer, CrucibleRecipe> indexMapping = new HashMap();
public static List<CrucibleRecipe> recipes = new ArrayList();
/*
* IMPORTANT: crucibles do not have stack size checks for the recipe's result, meaning that they can overflow if the resulting stacks are
* bigger than the input stacks, so make sure that material doesn't "expand". very few things do that IRL when alloying anyway.
*/
@Override
public void registerDefaults() {
@ -38,7 +42,7 @@ public class CrucibleRecipes extends SerializableRecipe {
public MaterialStack[] output;
private int id;
private String name;
public int frequency;
public int frequency = 1;
public CrucibleRecipe(int id, String name, int frequency) {
this.id = id;

View File

@ -744,6 +744,7 @@ public class ModItems {
public static Item mold_base;
public static Item mold;
public static Item scraps;
public static Item part_lithium;
public static Item part_beryllium;
@ -3355,6 +3356,7 @@ public class ModItems {
mold_base = new Item().setUnlocalizedName("mold_base").setCreativeTab(MainRegistry.controlTab).setTextureName(RefStrings.MODID + ":mold_base");
mold = new ItemMold().setUnlocalizedName("mold").setCreativeTab(MainRegistry.controlTab);
scraps = new ItemScraps().setUnlocalizedName("scraps").setCreativeTab(MainRegistry.controlTab).setTextureName(RefStrings.MODID + ":scraps");
part_lithium = new Item().setUnlocalizedName("part_lithium").setCreativeTab(MainRegistry.controlTab).setTextureName(RefStrings.MODID + ":part_lithium");
part_beryllium = new Item().setUnlocalizedName("part_beryllium").setCreativeTab(MainRegistry.controlTab).setTextureName(RefStrings.MODID + ":part_beryllium");
@ -6654,6 +6656,7 @@ public class ModItems {
//Molds
GameRegistry.registerItem(mold_base, mold_base.getUnlocalizedName());
GameRegistry.registerItem(mold, mold.getUnlocalizedName());
GameRegistry.registerItem(scraps, scraps.getUnlocalizedName());
//Machine Upgrades
GameRegistry.registerItem(upgrade_template, upgrade_template.getUnlocalizedName());

View File

@ -17,6 +17,7 @@ import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
@ -28,10 +29,15 @@ public class ItemMold extends Item {
public List<Mold> molds = new ArrayList(); //molds in "pretty" order, variable between versions
public HashMap<Integer, Mold> moldById = new HashMap(); //molds by their static ID -> stack item damage
public HashMap<NTMMaterial, ItemStack> blockOverrides = new HashMap();
public ItemMold() {
this.setHasSubtypes(true);
this.setMaxDamage(0);
blockOverrides.put(Mats.MAT_STONE, new ItemStack(Blocks.stone));
blockOverrides.put(Mats.MAT_OBSIDIAN, new ItemStack(Blocks.obsidian));
int S = 0;
int L = 1;
@ -41,7 +47,7 @@ public class ItemMold extends Item {
registerMold(new MoldShape( 3, S, "plate", MaterialShapes.PLATE));
registerMold(new MoldWire( 4, S, "wire"));
registerMold(new MoldMulti( 5, S, "blade", MaterialShapes.INGOT.q(3),
registerMold(new MoldMulti( 5, S, "blade", MaterialShapes.INGOT.q(2),
Mats.MAT_TITANIUM, new ItemStack(ModItems.blade_titanium),
Mats.MAT_TUNGSTEN, new ItemStack(ModItems.blade_tungsten)));
@ -74,7 +80,7 @@ public class ItemMold extends Item {
registerMold(new MoldShape( 10, L, "ingots", MaterialShapes.INGOT, 9));
registerMold(new MoldShape( 11, L, "plates", MaterialShapes.PLATE, 9));
registerMold(new MoldShape( 12, L, "block", MaterialShapes.BLOCK));
registerMold(new MoldBlock( 12, L, "block", MaterialShapes.BLOCK));
registerMold(new MoldSingle( 13, L, "pipes", new ItemStack(ModItems.pipes_steel), Mats.MAT_STEEL, MaterialShapes.BLOCK.q(3)));
}
@ -188,6 +194,24 @@ public class ItemMold extends Item {
}
}
public class MoldBlock extends MoldShape {
public MoldBlock(int id, int size, String name, MaterialShapes shape) {
super(id, size, name, shape);
}
@Override
public ItemStack getOutput(NTMMaterial mat) {
ItemStack override = blockOverrides.get(mat);
if(override != null)
return override.copy();
return super.getOutput(mat);
}
}
public class MoldWire extends Mold {
public MoldWire(int id, int size, String name) {

View File

@ -0,0 +1,76 @@
package com.hbm.items.machine;
import java.util.List;
import com.hbm.inventory.material.MaterialShapes;
import com.hbm.inventory.material.Mats;
import com.hbm.inventory.material.Mats.MaterialStack;
import com.hbm.items.ModItems;
import com.hbm.inventory.material.NTMMaterial;
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;
import net.minecraft.nbt.NBTTagCompound;
public class ItemScraps extends Item {
public ItemScraps() {
this.setHasSubtypes(true);
}
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs tab, List list) {
for(NTMMaterial mat : Mats.orderedList) {
list.add(new ItemStack(item, 1, mat.id));
}
}
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool) {
MaterialStack contents = getMats(stack);
if(contents != null) {
list.add(contents.material.names[0] + " " + Mats.formatAmount(contents.amount));
}
}
@SideOnly(Side.CLIENT)
public int getColorFromItemStack(ItemStack stack, int layer) {
NTMMaterial mat = Mats.matById.get(stack.getItemDamage());
if(mat != null) {
return mat.moltenColor;
}
return 0xffffff;
}
public static MaterialStack getMats(ItemStack stack) {
if(stack.getItem() != ModItems.scraps) return null;
NTMMaterial mat = Mats.matById.get(stack.getItemDamage());
if(mat == null) return null;
int amount = MaterialShapes.INGOT.q(1);
if(stack.hasTagCompound()) {
amount = stack.getTagCompound().getInteger("amount");
}
return new MaterialStack(mat, amount);
}
public static ItemStack create(MaterialStack stack) {
ItemStack scrap = new ItemStack(ModItems.scrap, 1, stack.material.id);
scrap.stackTagCompound = new NBTTagCompound();
scrap.stackTagCompound.setInteger("amount", stack.amount);
return scrap;
}
}

View File

@ -199,7 +199,7 @@ public class CraftingManager {
addRecipeAuto(new ItemStack(ModItems.sphere_steel, 1), new Object[] { "PIP", "I I", "PIP", 'P', STEEL.plate(), 'I', STEEL.ingot() });
addRecipeAuto(new ItemStack(ModItems.pedestal_steel, 1), new Object[] { "P P", "P P", "III", 'P', STEEL.plate(), 'I', STEEL.ingot() });
addRecipeAuto(new ItemStack(ModItems.lemon, 1), new Object[] { " D ", "DSD", " D ", 'D', KEY_YELLOW, 'S', "stone" });
addRecipeAuto(new ItemStack(ModItems.blade_titanium, 4), new Object[] { "TP", "TP", "TT", 'P', TI.plate(), 'T', TI.ingot() });
addRecipeAuto(new ItemStack(ModItems.blade_titanium, 2), new Object[] { "TP", "TP", "TT", 'P', TI.plate(), 'T', TI.ingot() });
addRecipeAuto(new ItemStack(ModItems.turbine_titanium, 1), new Object[] { "BBB", "BSB", "BBB", 'B', ModItems.blade_titanium, 'S', STEEL.ingot() });
addRecipeAuto(new ItemStack(ModItems.rotor_steel, 3), new Object[] { "CCC", "SSS", "CCC", 'C', ModItems.coil_gold, 'S', STEEL.ingot() });
addRecipeAuto(new ItemStack(ModItems.generator_steel, 1), new Object[] { "RRR", "CCC", "SSS", 'C', ModItems.coil_gold_torus, 'S', STEEL.ingot(), 'R', ModItems.rotor_steel });
@ -209,7 +209,6 @@ public class CraftingManager {
addRecipeAuto(new ItemStack(ModItems.shimmer_sledge, 1), new Object[] { "H", "G", "G", 'G', ModItems.shimmer_handle, 'H', ModItems.shimmer_head });
addRecipeAuto(new ItemStack(ModItems.shimmer_axe, 1), new Object[] { "H", "G", "G", 'G', ModItems.shimmer_handle, 'H', ModItems.shimmer_axe_head });
addRecipeAuto(new ItemStack(ModItems.definitelyfood, 1), new Object[] { "DDD", "SDS", "DDD", 'D', Blocks.dirt, 'S', STEEL.plate() });
addRecipeAuto(new ItemStack(ModItems.blade_tungsten, 2), new Object[] { "IP", "TP", "TI", 'P', TI.plate(), 'T', TI.ingot(), 'I', W.ingot() });
addRecipeAuto(new ItemStack(ModItems.turbine_tungsten, 1), new Object[] { "BBB", "BSB", "BBB", 'B', ModItems.blade_tungsten, 'S', DURA.ingot() });
addRecipeAuto(new ItemStack(ModItems.ring_starmetal, 1), new Object[] { " S ", "S S", " S ", 'S', STAR.ingot() });
addRecipeAuto(new ItemStack(ModItems.flywheel_beryllium, 1), new Object[] { "BBB", "BTB", "BBB", 'B', BE.block(), 'T', ModItems.bolt_compound });

View File

@ -65,6 +65,7 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
if(!worldObj.isRemote) {
tryPullHeat();
/* collect items */
if(worldObj.getTotalWorldTime() % 5 == 0) {
List<EntityItem> list = worldObj.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(xCoord - 0.5, yCoord + 0.5, zCoord - 0.5, xCoord + 1.5, yCoord + 1, zCoord + 1.5));
@ -90,10 +91,14 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
}
}
/* smelt items from buffer */
if(!trySmelt()) {
this.progress = 0;
}
tryRecipe();
/* pour wasste stack */
if(!this.wasteStack.isEmpty()) {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset).getOpposite();
@ -101,6 +106,7 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
CrucibleUtil.pourFullStack(worldObj, xCoord + 0.5D + dir.offsetX * 1.875D, yCoord + 0.25D, zCoord + 0.5D + dir.offsetZ * 1.875D, 6, true, this.wasteStack, MaterialShapes.NUGGET.q(1), impact);
}
/* pour recipe stack */
if(!this.recipeStack.isEmpty()) {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset);
@ -126,9 +132,11 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
CrucibleUtil.pourFullStack(worldObj, xCoord + 0.5D + dir.offsetX * 1.875D, yCoord + 0.25D, zCoord + 0.5D + dir.offsetZ * 1.875D, 6, true, toCast, MaterialShapes.NUGGET.q(1), impact);
}
/* clean up stacks */
this.recipeStack.removeIf(o -> o.amount <= 0);
this.wasteStack.removeIf(x -> x.amount <= 0);
/* sync */
NBTTagCompound data = new NBTTagCompound();
int[] rec = new int[recipeStack.size() * 2];
int[] was = new int[wasteStack.size() * 2];
@ -221,6 +229,33 @@ public class TileEntityCrucible extends TileEntityMachineBase implements IGUIPro
return true;
}
protected void tryRecipe() {
CrucibleRecipe recipe = this.getLoadedRecipe();
if(recipe == null) return;
if(worldObj.getTotalWorldTime() % recipe.frequency > 0) return;
for(MaterialStack stack : recipe.input) {
if(getQuantaFromType(this.recipeStack, stack.material) < stack.amount) return;
}
for(MaterialStack stack : this.recipeStack) {
stack.amount -= getQuantaFromType(recipe.input, stack.material);
}
for(MaterialStack out : recipe.output) {
for(MaterialStack stack : this.recipeStack) {
if(stack.material == out.material) {
stack.amount += out.amount;
break;
}
}
this.recipeStack.add(out.copy());
}
}
protected int getFirstSmeltableSlot() {
for(int i = 1; i < 10; i++) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 352 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 368 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 353 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 351 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 478 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 B