More custom machine options

Add more custom machine options. Now custom machines can receive neutron flux and heat through the "Neutron Flux Receiver" and "Heat receiver" blocks within the structure. The recipe has also added corresponding configurable neutron flux and heat requirements, and can also be configured to generate/absorb contamination
This commit is contained in:
FOlkvangrField 2023-12-30 16:14:10 +08:00
parent c70d5bf517
commit 7473278dab
15 changed files with 432 additions and 217 deletions

View File

@ -896,6 +896,8 @@ public class ModBlocks {
public static Block cm_tank; public static Block cm_tank;
public static Block cm_circuit; public static Block cm_circuit;
public static Block cm_port; public static Block cm_port;
public static Block cm_flux;
public static Block cm_heat;
public static Block custom_machine; public static Block custom_machine;
public static Block cm_anchor; public static Block cm_anchor;
@ -2074,6 +2076,8 @@ public class ModBlocks {
cm_tank = new BlockCMGlass(Material.iron, EnumCMMaterials.class, true, true).setBlockName("cm_tank").setCreativeTab(MainRegistry.machineTab).setHardness(5.0F).setResistance(10.0F).setBlockTextureName(RefStrings.MODID + ":cm_tank"); cm_tank = new BlockCMGlass(Material.iron, EnumCMMaterials.class, true, true).setBlockName("cm_tank").setCreativeTab(MainRegistry.machineTab).setHardness(5.0F).setResistance(10.0F).setBlockTextureName(RefStrings.MODID + ":cm_tank");
cm_circuit = new BlockCM(Material.iron, EnumCMCircuit.class, true, true).setBlockName("cm_circuit").setCreativeTab(MainRegistry.machineTab).setHardness(5.0F).setResistance(10.0F).setBlockTextureName(RefStrings.MODID + ":cm_circuit"); cm_circuit = new BlockCM(Material.iron, EnumCMCircuit.class, true, true).setBlockName("cm_circuit").setCreativeTab(MainRegistry.machineTab).setHardness(5.0F).setResistance(10.0F).setBlockTextureName(RefStrings.MODID + ":cm_circuit");
cm_port = new BlockCMPort(Material.iron, EnumCMMaterials.class, true, true).setBlockName("cm_port").setCreativeTab(MainRegistry.machineTab).setHardness(5.0F).setResistance(10.0F).setBlockTextureName(RefStrings.MODID + ":cm_port"); cm_port = new BlockCMPort(Material.iron, EnumCMMaterials.class, true, true).setBlockName("cm_port").setCreativeTab(MainRegistry.machineTab).setHardness(5.0F).setResistance(10.0F).setBlockTextureName(RefStrings.MODID + ":cm_port");
cm_flux = new BlockCMFlux(Material.iron, RefStrings.MODID + ":cm_flux_top").setBlockName("cm_flux").setCreativeTab(MainRegistry.machineTab).setHardness(5.0F).setResistance(10.0F).setBlockTextureName(RefStrings.MODID + ":cm_flux_side");
cm_heat = new BlockCMHeat(Material.iron, RefStrings.MODID +":cm_heat_top").setBlockName("cm_heat").setCreativeTab(MainRegistry.machineTab).setHardness(5.0F).setResistance(10.0F).setBlockTextureName(RefStrings.MODID + ":cm_heat_side");
custom_machine = new BlockCustomMachine().setBlockName("custom_machine").setCreativeTab(MainRegistry.machineTab).setLightLevel(1F).setHardness(5.0F).setResistance(10.0F); custom_machine = new BlockCustomMachine().setBlockName("custom_machine").setCreativeTab(MainRegistry.machineTab).setLightLevel(1F).setHardness(5.0F).setResistance(10.0F);
cm_anchor = new BlockCMAnchor().setBlockName("custom_machine_anchor").setCreativeTab(MainRegistry.machineTab).setHardness(5.0F).setResistance(10.0F); cm_anchor = new BlockCMAnchor().setBlockName("custom_machine_anchor").setCreativeTab(MainRegistry.machineTab).setHardness(5.0F).setResistance(10.0F);
@ -3450,6 +3454,8 @@ public class ModBlocks {
register(cm_tank); register(cm_tank);
register(cm_circuit); register(cm_circuit);
register(cm_port); register(cm_port);
register(cm_flux);
register(cm_heat);
register(cm_anchor); register(cm_anchor);
//PWR //PWR

View File

@ -0,0 +1,9 @@
package com.hbm.blocks.machine;
import net.minecraft.block.material.Material;
public class BlockCMFlux extends BlockPillar{
public BlockCMFlux(Material mat, String top) {
super(mat, top);
}
}

View File

@ -0,0 +1,9 @@
package com.hbm.blocks.machine;
import net.minecraft.block.material.Material;
public class BlockCMHeat extends BlockPillar{
public BlockCMHeat(Material mat, String top) {
super(mat, top);
}
}

View File

@ -34,19 +34,19 @@ public class CustomMachineConfigJSON {
public static final Gson gson = new Gson(); public static final Gson gson = new Gson();
public static HashMap<String, MachineConfiguration> customMachines = new HashMap(); public static HashMap<String, MachineConfiguration> customMachines = new HashMap();
public static List<MachineConfiguration> niceList = new ArrayList(); public static List<MachineConfiguration> niceList = new ArrayList();
public static void initialize() { public static void initialize() {
File folder = MainRegistry.configHbmDir; File folder = MainRegistry.configHbmDir;
File config = new File(folder.getAbsolutePath() + File.separatorChar + "hbmCustomMachines.json"); File config = new File(folder.getAbsolutePath() + File.separatorChar + "hbmCustomMachines.json");
if(!config.exists()) { if(!config.exists()) {
writeDefault(config); writeDefault(config);
} }
readConfig(config); readConfig(config);
} }
public static void writeDefault(File config) { public static void writeDefault(File config) {
try { try {
@ -54,7 +54,7 @@ public class CustomMachineConfigJSON {
writer.setIndent(" "); writer.setIndent(" ");
writer.beginObject(); writer.beginObject();
writer.name("machines").beginArray(); writer.name("machines").beginArray();
writer.beginObject(); writer.beginObject();
writer.name("recipeKey").value("paperPress"); writer.name("recipeKey").value("paperPress");
writer.name("unlocalizedName").value("paperPress"); writer.name("unlocalizedName").value("paperPress");
@ -66,14 +66,17 @@ public class CustomMachineConfigJSON {
writer.name("fluidOutCap").value(0); writer.name("fluidOutCap").value(0);
writer.name("itemOutCount").value(1); writer.name("itemOutCount").value(1);
writer.name("generatorMode").value(false); writer.name("generatorMode").value(false);
writer.name("maxPollutionCap").value(100);
writer.name("fluxMode").value(false);
writer.name("recipeSpeedMult").value(1.0D); writer.name("recipeSpeedMult").value(1.0D);
writer.name("recipeConsumptionMult").value(1.0D); writer.name("recipeConsumptionMult").value(1.0D);
writer.name("maxPower").value(10_000L); writer.name("maxPower").value(10_000L);
writer.name("maxHeat").value(0);
writer.name("recipeShape").beginArray(); writer.name("recipeShape").beginArray();
writer.value("IPI").value("PCP").value("IPI"); writer.value("IPI").value("PCP").value("IPI");
writer.endArray(); writer.endArray();
writer.name("recipeParts").beginArray().setIndent(""); writer.name("recipeParts").beginArray().setIndent("");
writer.value("I"); writer.value("I");
SerializableRecipe.writeAStack(new OreDictStack(OreDictManager.STEEL.ingot()), writer); SerializableRecipe.writeAStack(new OreDictStack(OreDictManager.STEEL.ingot()), writer);
@ -84,9 +87,9 @@ public class CustomMachineConfigJSON {
writer.value("C"); writer.value("C");
SerializableRecipe.writeAStack(new ComparableStack(ModItems.circuit_aluminium), writer); SerializableRecipe.writeAStack(new ComparableStack(ModItems.circuit_aluminium), writer);
writer.endArray().setIndent(" "); writer.endArray().setIndent(" ");
writer.name("components").beginArray(); writer.name("components").beginArray();
for(int x = -1; x <= 1; x++) { for(int x = -1; x <= 1; x++) {
for(int y = -1; y <= 1; y++) { for(int y = -1; y <= 1; y++) {
for(int z = 0; z <= 2; z++) { for(int z = 0; z <= 2; z++) {
@ -104,7 +107,7 @@ public class CustomMachineConfigJSON {
} }
} }
} }
writer.beginObject().setIndent(""); writer.beginObject().setIndent("");
writer.name("block").value("hbm:tile.cm_port"); writer.name("block").value("hbm:tile.cm_port");
writer.name("x").value(0); writer.name("x").value(0);
@ -114,7 +117,7 @@ public class CustomMachineConfigJSON {
writer.value(0); writer.value(0);
writer.endArray(); writer.endArray();
writer.endObject().setIndent(" "); writer.endObject().setIndent(" ");
writer.beginObject().setIndent(""); writer.beginObject().setIndent("");
writer.name("block").value("hbm:tile.cm_port"); writer.name("block").value("hbm:tile.cm_port");
writer.name("x").value(0); writer.name("x").value(0);
@ -124,10 +127,10 @@ public class CustomMachineConfigJSON {
writer.value(0); writer.value(0);
writer.endArray(); writer.endArray();
writer.endObject().setIndent(" "); writer.endObject().setIndent(" ");
writer.endArray(); writer.endArray();
writer.endObject(); writer.endObject();
writer.endArray(); writer.endArray();
writer.endObject(); writer.endObject();
writer.close(); writer.close();
@ -135,16 +138,16 @@ public class CustomMachineConfigJSON {
e.printStackTrace(); e.printStackTrace();
} }
} }
public static void readConfig(File config) { public static void readConfig(File config) {
try { try {
JsonObject json = gson.fromJson(new FileReader(config), JsonObject.class); JsonObject json = gson.fromJson(new FileReader(config), JsonObject.class);
JsonArray machines = json.get("machines").getAsJsonArray(); JsonArray machines = json.get("machines").getAsJsonArray();
for(int i = 0; i < machines.size(); i++) { for(int i = 0; i < machines.size(); i++) {
JsonObject machineObject = machines.get(i).getAsJsonObject(); JsonObject machineObject = machines.get(i).getAsJsonObject();
MachineConfiguration configuration = new MachineConfiguration(); MachineConfiguration configuration = new MachineConfiguration();
configuration.recipeKey = machineObject.get("recipeKey").getAsString(); configuration.recipeKey = machineObject.get("recipeKey").getAsString();
configuration.unlocalizedName = machineObject.get("unlocalizedName").getAsString(); configuration.unlocalizedName = machineObject.get("unlocalizedName").getAsString();
@ -156,45 +159,48 @@ public class CustomMachineConfigJSON {
configuration.fluidOutCap = machineObject.get("fluidOutCap").getAsInt(); configuration.fluidOutCap = machineObject.get("fluidOutCap").getAsInt();
configuration.itemOutCount = machineObject.get("itemOutCount").getAsInt(); configuration.itemOutCount = machineObject.get("itemOutCount").getAsInt();
configuration.generatorMode = machineObject.get("generatorMode").getAsBoolean(); configuration.generatorMode = machineObject.get("generatorMode").getAsBoolean();
configuration.maxPollutionCap = machineObject.get("maxPollutionCap").getAsInt();
configuration.fluxMode = machineObject.get("fluxMode").getAsBoolean();
configuration.recipeSpeedMult = machineObject.get("recipeSpeedMult").getAsDouble(); configuration.recipeSpeedMult = machineObject.get("recipeSpeedMult").getAsDouble();
configuration.recipeConsumptionMult = machineObject.get("recipeConsumptionMult").getAsDouble(); configuration.recipeConsumptionMult = machineObject.get("recipeConsumptionMult").getAsDouble();
configuration.maxPower = machineObject.get("maxPower").getAsLong(); configuration.maxPower = machineObject.get("maxPower").getAsLong();
configuration.maxHeat = machineObject.get("maxHeat").getAsInt();
if(machineObject.has("recipeShape") && machineObject.has("recipeParts")) { if(machineObject.has("recipeShape") && machineObject.has("recipeParts")) {
JsonArray recipeShape = machineObject.get("recipeShape").getAsJsonArray(); JsonArray recipeShape = machineObject.get("recipeShape").getAsJsonArray();
JsonArray recipeParts = machineObject.get("recipeParts").getAsJsonArray(); JsonArray recipeParts = machineObject.get("recipeParts").getAsJsonArray();
Object[] parts = new Object[recipeShape.size() + recipeParts.size()]; Object[] parts = new Object[recipeShape.size() + recipeParts.size()];
for(int j = 0; j < recipeShape.size(); j++) { for(int j = 0; j < recipeShape.size(); j++) {
parts[j] = recipeShape.get(j).getAsString(); parts[j] = recipeShape.get(j).getAsString();
} }
for(int j = 0; j < recipeParts.size(); j++) { for(int j = 0; j < recipeParts.size(); j++) {
Object o = null; Object o = null;
if(j % 2 == 0) { if(j % 2 == 0) {
o = recipeParts.get(j).getAsString().charAt(0); //god is dead and we killed him o = recipeParts.get(j).getAsString().charAt(0); //god is dead and we killed him
} else { } else {
AStack a = SerializableRecipe.readAStack(recipeParts.get(j).getAsJsonArray()); AStack a = SerializableRecipe.readAStack(recipeParts.get(j).getAsJsonArray());
if(a instanceof ComparableStack) o = ((ComparableStack) a).toStack(); if(a instanceof ComparableStack) o = ((ComparableStack) a).toStack();
if(a instanceof OreDictStack) o = ((OreDictStack) a).name; if(a instanceof OreDictStack) o = ((OreDictStack) a).name;
} }
parts[j + recipeShape.size()] = o; parts[j + recipeShape.size()] = o;
} }
ItemStack stack = new ItemStack(ModBlocks.custom_machine, 1, i + 100); ItemStack stack = new ItemStack(ModBlocks.custom_machine, 1, i + 100);
stack.stackTagCompound = new NBTTagCompound(); stack.stackTagCompound = new NBTTagCompound();
stack.stackTagCompound.setString("machineType", configuration.unlocalizedName); stack.stackTagCompound.setString("machineType", configuration.unlocalizedName);
CraftingManager.addRecipeAuto(stack, parts); CraftingManager.addRecipeAuto(stack, parts);
} }
JsonArray components = machineObject.get("components").getAsJsonArray(); JsonArray components = machineObject.get("components").getAsJsonArray();
configuration.components = new ArrayList(); configuration.components = new ArrayList();
for(int j = 0; j < components.size(); j++) { for(int j = 0; j < components.size(); j++) {
JsonObject compObject = components.get(j).getAsJsonObject(); JsonObject compObject = components.get(j).getAsJsonObject();
ComponentDefinition compDef = new ComponentDefinition(); ComponentDefinition compDef = new ComponentDefinition();
@ -207,21 +213,21 @@ public class CustomMachineConfigJSON {
for(int k = 0; k < compDef.metas.size(); k++) { for(int k = 0; k < compDef.metas.size(); k++) {
compDef.allowedMetas.add(compDef.metas.get(k).getAsInt()); compDef.allowedMetas.add(compDef.metas.get(k).getAsInt());
} }
configuration.components.add(compDef); configuration.components.add(compDef);
} }
customMachines.put(configuration.unlocalizedName, configuration); customMachines.put(configuration.unlocalizedName, configuration);
niceList.add(configuration); niceList.add(configuration);
} }
} catch(Exception ex) { } catch(Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
public static class MachineConfiguration { public static class MachineConfiguration {
/** The name of the recipe set that this machine can handle */ /** The name of the recipe set that this machine can handle */
public String recipeKey; public String recipeKey;
/** The internal name of this machine */ /** The internal name of this machine */
@ -237,14 +243,17 @@ public class CustomMachineConfigJSON {
public int itemOutCount; public int itemOutCount;
/** Whether inputs should be used up when the process begins */ /** Whether inputs should be used up when the process begins */
public boolean generatorMode; public boolean generatorMode;
public int maxPollutionCap;
public boolean fluxMode;
public double recipeSpeedMult = 1D; public double recipeSpeedMult = 1D;
public double recipeConsumptionMult = 1D; public double recipeConsumptionMult = 1D;
public long maxPower; public long maxPower;
public int maxHeat;
/** Definitions of blocks that this machine is composed of */ /** Definitions of blocks that this machine is composed of */
public List<ComponentDefinition> components; public List<ComponentDefinition> components;
public static class ComponentDefinition { public static class ComponentDefinition {
public Block block; public Block block;
public Set<Integer> allowedMetas; public Set<Integer> allowedMetas;

View File

@ -5,6 +5,7 @@ import java.util.ArrayList;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import codechicken.lib.gui.GuiDraw;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
import com.hbm.config.CustomMachineConfigJSON; import com.hbm.config.CustomMachineConfigJSON;
import com.hbm.config.CustomMachineConfigJSON.MachineConfiguration; import com.hbm.config.CustomMachineConfigJSON.MachineConfiguration;
@ -25,10 +26,10 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.EnumChatFormatting;
public class CustomMachineHandler extends TemplateRecipeHandler { public class CustomMachineHandler extends TemplateRecipeHandler {
public LinkedList<RecipeTransferRect> transferRectsRec = new LinkedList<RecipeTransferRect>(); public LinkedList<RecipeTransferRect> transferRectsRec = new LinkedList<RecipeTransferRect>();
public LinkedList<Class<? extends GuiContainer>> guiRec = new LinkedList<Class<? extends GuiContainer>>(); public LinkedList<Class<? extends GuiContainer>> guiRec = new LinkedList<Class<? extends GuiContainer>>();
public MachineConfiguration conf; public MachineConfiguration conf;
@Override @Override
@ -39,20 +40,25 @@ public class CustomMachineHandler extends TemplateRecipeHandler {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
public CustomMachineHandler(MachineConfiguration conf) { public CustomMachineHandler(MachineConfiguration conf) {
super(); super();
this.conf = conf; this.conf = conf;
loadTransferRects(); loadTransferRects();
RecipeTransferRectHandler.registerRectsToGuis(getRecipeTransferRectGuis(), transferRects); RecipeTransferRectHandler.registerRectsToGuis(getRecipeTransferRectGuis(), transferRects);
} }
public class RecipeSet extends TemplateRecipeHandler.CachedRecipe { public class RecipeSet extends TemplateRecipeHandler.CachedRecipe {
List<PositionedStack> inputs = new ArrayList(); List<PositionedStack> inputs = new ArrayList();
PositionedStack machine; PositionedStack machine;
List<PositionedStack> outputs = new ArrayList(); List<PositionedStack> outputs = new ArrayList();
public int flux = 0;
public int heat = 0;
public float radiationAmount = 0;
public String pollutionType;
public float pollutionAmount = 0;
public RecipeSet(CustomMachineRecipe recipe) { public RecipeSet(CustomMachineRecipe recipe) {
for(int i = 0; i < 3; i++) if(recipe.inputFluids.length > i) inputs.add(new PositionedStack(ItemFluidIcon.make(recipe.inputFluids[i]), 12 + i * 18, 6)); for(int i = 0; i < 3; i++) if(recipe.inputFluids.length > i) inputs.add(new PositionedStack(ItemFluidIcon.make(recipe.inputFluids[i]), 12 + i * 18, 6));
@ -60,7 +66,7 @@ public class CustomMachineHandler extends TemplateRecipeHandler {
for(int i = 3; i < 6; i++) if(recipe.inputItems.length > i) inputs.add(new PositionedStack(recipe.inputItems[i].extractForNEI(), 12 + (i - 3) * 18, 42)); for(int i = 3; i < 6; i++) if(recipe.inputItems.length > i) inputs.add(new PositionedStack(recipe.inputItems[i].extractForNEI(), 12 + (i - 3) * 18, 42));
for(int i = 0; i < 3; i++) if(recipe.outputFluids.length > i) outputs.add(new PositionedStack(ItemFluidIcon.make(recipe.outputFluids[i]), 102 + i * 18, 6)); for(int i = 0; i < 3; i++) if(recipe.outputFluids.length > i) outputs.add(new PositionedStack(ItemFluidIcon.make(recipe.outputFluids[i]), 102 + i * 18, 6));
for(int i = 0; i < 3; i++) if(recipe.outputItems.length > i) { for(int i = 0; i < 3; i++) if(recipe.outputItems.length > i) {
Pair<ItemStack, Float> pair = recipe.outputItems[i]; Pair<ItemStack, Float> pair = recipe.outputItems[i];
ItemStack out = pair.getKey().copy(); ItemStack out = pair.getKey().copy();
@ -69,7 +75,7 @@ public class CustomMachineHandler extends TemplateRecipeHandler {
} }
outputs.add(new PositionedStack(out, 102 + i * 18, 24)); outputs.add(new PositionedStack(out, 102 + i * 18, 24));
} }
for(int i = 3; i < 6; i++) if(recipe.outputItems.length > i) { for(int i = 3; i < 6; i++) if(recipe.outputItems.length > i) {
Pair<ItemStack, Float> pair = recipe.outputItems[i]; Pair<ItemStack, Float> pair = recipe.outputItems[i];
ItemStack out = pair.getKey().copy(); ItemStack out = pair.getKey().copy();
@ -78,7 +84,13 @@ public class CustomMachineHandler extends TemplateRecipeHandler {
} }
outputs.add(new PositionedStack(out, 102 + (i - 3) * 18, 42)); outputs.add(new PositionedStack(out, 102 + (i - 3) * 18, 42));
} }
if(recipe.pollutionMode) {
this.pollutionType = recipe.pollutionType;
this.pollutionAmount = recipe.pollutionAmount;
}
if(recipe.radiationMode) this.radiationAmount = recipe.radiationAmount;
if(conf.fluxMode) this.flux = recipe.flux;
if(conf.maxHeat>0 && recipe.heat>0) this.heat = recipe.heat;
this.machine = new PositionedStack(new ItemStack(ModBlocks.custom_machine, 1, 100 + CustomMachineConfigJSON.niceList.indexOf(conf)), 75, 42); this.machine = new PositionedStack(new ItemStack(ModBlocks.custom_machine, 1, 100 + CustomMachineConfigJSON.niceList.indexOf(conf)), 75, 42);
} }
@ -111,14 +123,14 @@ public class CustomMachineHandler extends TemplateRecipeHandler {
public String getGuiTexture() { public String getGuiTexture() {
return RefStrings.MODID + ":textures/gui/nei/gui_nei_custom.png"; return RefStrings.MODID + ":textures/gui/nei/gui_nei_custom.png";
} }
@Override @Override
public void loadCraftingRecipes(String outputId, Object... results) { public void loadCraftingRecipes(String outputId, Object... results) {
if(outputId.equals("ntm_" + conf.unlocalizedName)) { if(outputId.equals("ntm_" + conf.unlocalizedName)) {
List<CustomMachineRecipe> recipes = CustomMachineRecipes.recipes.get(conf.recipeKey); List<CustomMachineRecipe> recipes = CustomMachineRecipes.recipes.get(conf.recipeKey);
if(recipes != null) for(CustomMachineRecipe recipe : recipes) { if(recipes != null) for(CustomMachineRecipe recipe : recipes) {
this.arecipes.add(new RecipeSet(recipe)); this.arecipes.add(new RecipeSet(recipe));
} }
@ -126,25 +138,25 @@ public class CustomMachineHandler extends TemplateRecipeHandler {
super.loadCraftingRecipes(outputId, results); super.loadCraftingRecipes(outputId, results);
} }
} }
@Override @Override
public void loadCraftingRecipes(ItemStack result) { public void loadCraftingRecipes(ItemStack result) {
List<CustomMachineRecipe> recipes = CustomMachineRecipes.recipes.get(conf.recipeKey); List<CustomMachineRecipe> recipes = CustomMachineRecipes.recipes.get(conf.recipeKey);
if(recipes != null) outer:for(CustomMachineRecipe recipe : recipes) { if(recipes != null) outer:for(CustomMachineRecipe recipe : recipes) {
for(Pair<ItemStack, Float> stack : recipe.outputItems) { for(Pair<ItemStack, Float> stack : recipe.outputItems) {
if(NEIServerUtils.areStacksSameTypeCrafting(stack.getKey(), result)) { if(NEIServerUtils.areStacksSameTypeCrafting(stack.getKey(), result)) {
this.arecipes.add(new RecipeSet(recipe)); this.arecipes.add(new RecipeSet(recipe));
continue outer; continue outer;
} }
} }
for(FluidStack fluid : recipe.outputFluids) { for(FluidStack fluid : recipe.outputFluids) {
ItemStack drop = ItemFluidIcon.make(fluid); ItemStack drop = ItemFluidIcon.make(fluid);
if(compareFluidStacks(result, drop)) { if(compareFluidStacks(result, drop)) {
this.arecipes.add(new RecipeSet(recipe)); this.arecipes.add(new RecipeSet(recipe));
continue outer; continue outer;
@ -152,28 +164,28 @@ public class CustomMachineHandler extends TemplateRecipeHandler {
} }
} }
} }
@Override @Override
public void loadUsageRecipes(String inputId, Object... ingredients) { public void loadUsageRecipes(String inputId, Object... ingredients) {
if(inputId.equals("ntm_" + conf.unlocalizedName)) { if(inputId.equals("ntm_" + conf.unlocalizedName)) {
loadCraftingRecipes("ntm_" + conf.unlocalizedName, new Object[0]); loadCraftingRecipes("ntm_" + conf.unlocalizedName, new Object[0]);
} else { } else {
super.loadUsageRecipes(inputId, ingredients); super.loadUsageRecipes(inputId, ingredients);
} }
} }
@Override @Override
public void loadUsageRecipes(ItemStack ingredient) { public void loadUsageRecipes(ItemStack ingredient) {
List<CustomMachineRecipe> recipes = CustomMachineRecipes.recipes.get(conf.recipeKey); List<CustomMachineRecipe> recipes = CustomMachineRecipes.recipes.get(conf.recipeKey);
if(recipes != null) outer:for(CustomMachineRecipe recipe : recipes) { if(recipes != null) outer:for(CustomMachineRecipe recipe : recipes) {
for(AStack stack : recipe.inputItems) { for(AStack stack : recipe.inputItems) {
List<ItemStack> stacks = stack.extractForNEI(); List<ItemStack> stacks = stack.extractForNEI();
for(ItemStack sta : stacks) { for(ItemStack sta : stacks) {
if(NEIServerUtils.areStacksSameTypeCrafting(ingredient, sta)) { if(NEIServerUtils.areStacksSameTypeCrafting(ingredient, sta)) {
this.arecipes.add(new RecipeSet(recipe)); this.arecipes.add(new RecipeSet(recipe));
@ -181,10 +193,10 @@ public class CustomMachineHandler extends TemplateRecipeHandler {
} }
} }
} }
for(FluidStack fluid : recipe.inputFluids) { for(FluidStack fluid : recipe.inputFluids) {
ItemStack drop = ItemFluidIcon.make(fluid); ItemStack drop = ItemFluidIcon.make(fluid);
if(compareFluidStacks(ingredient, drop)) { if(compareFluidStacks(ingredient, drop)) {
this.arecipes.add(new RecipeSet(recipe)); this.arecipes.add(new RecipeSet(recipe));
continue outer; continue outer;
@ -196,11 +208,32 @@ public class CustomMachineHandler extends TemplateRecipeHandler {
public static boolean compareFluidStacks(ItemStack sta1, ItemStack sta2) { public static boolean compareFluidStacks(ItemStack sta1, ItemStack sta2) {
return sta1.getItem() == sta2.getItem() && sta1.getItemDamage() == sta2.getItemDamage(); return sta1.getItem() == sta2.getItem() && sta1.getItemDamage() == sta2.getItemDamage();
} }
@Override @Override
public void loadTransferRects() { public void loadTransferRects() {
if(this.conf == null) return; if(this.conf == null) return;
transferRects.add(new RecipeTransferRect(new Rectangle(65, 23, 36, 18), "ntm_" + conf.unlocalizedName)); transferRects.add(new RecipeTransferRect(new Rectangle(65, 23, 36, 18), "ntm_" + conf.unlocalizedName));
RecipeTransferRectHandler.registerRectsToGuis(getRecipeTransferRectGuis(), transferRects); RecipeTransferRectHandler.registerRectsToGuis(getRecipeTransferRectGuis(), transferRects);
} }
@Override
public void drawExtras(int recipe) {
RecipeSet Recipe = (RecipeSet) this.arecipes.get(recipe);
int side = 83;
if(Recipe.radiationAmount != 0){
String radiation = "Radiation:" + Recipe.radiationAmount + "";
GuiDraw.drawString(radiation, 160 - GuiDraw.fontRenderer.getStringWidth(radiation), 63, 0x08FF00);
}
if (Recipe.pollutionAmount != 0){
String pollution = Recipe.pollutionType + ":" + Recipe.pollutionAmount + "";
GuiDraw.drawString(pollution, 160 - GuiDraw.fontRenderer.getStringWidth(pollution), 75, 0x404040);
}
if(conf.fluxMode) {
String flux = "Flux:" + Recipe.flux + "";
GuiDraw.drawString(flux, side - GuiDraw.fontRenderer.getStringWidth(flux) / 2, 16, 0x08FF00);
}
if(conf.maxHeat>0 && Recipe.heat>0){
String heat = "Heat:" + Recipe.heat + "";
GuiDraw.drawString(heat, side - GuiDraw.fontRenderer.getStringWidth(heat) / 2, 8, 0xFF0000);
}
}
} }

View File

@ -1,7 +1,9 @@
package com.hbm.inventory.gui; package com.hbm.inventory.gui;
import java.util.Arrays; import java.util.Arrays;
import java.util.Locale;
import com.hbm.render.util.GaugeUtil;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import com.hbm.inventory.SlotPattern; import com.hbm.inventory.SlotPattern;
@ -17,58 +19,59 @@ import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
public class GUIMachineCustom extends GuiInfoContainer { public class GUIMachineCustom extends GuiInfoContainer {
private static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/processing/gui_custom.png"); private static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/processing/gui_custom.png");
private TileEntityCustomMachine custom; private TileEntityCustomMachine custom;
public GUIMachineCustom(InventoryPlayer invPlayer, TileEntityCustomMachine tedf) { public GUIMachineCustom(InventoryPlayer invPlayer, TileEntityCustomMachine tedf) {
super(new ContainerMachineCustom(invPlayer, tedf)); super(new ContainerMachineCustom(invPlayer, tedf));
custom = tedf; custom = tedf;
this.xSize = 176; this.xSize = 176;
this.ySize = 256; this.ySize = 256;
} }
@Override @Override
public void drawScreen(int x, int y, float interp) { public void drawScreen(int x, int y, float interp) {
super.drawScreen(x, y, interp); super.drawScreen(x, y, interp);
this.drawElectricityInfo(this, x, y, guiLeft + 150, guiTop + 18, 16, 52, custom.power, custom.config.maxPower);
this.drawElectricityInfo(this, x, y, guiLeft + 150, guiTop + 18, 16, 52, custom.power, custom.config.maxPower);
if(custom.config.maxHeat>0) this.drawCustomInfoStat(x, y, guiLeft + 61, guiTop + 53, 18, 18, x, y, new String[] { "Heat:" + String.format(Locale.US, "%,d", custom.heat) + " / " + String.format(Locale.US, "%,d", custom.config.maxHeat)});
if(this.mc.thePlayer.inventory.getItemStack() == null) { if(this.mc.thePlayer.inventory.getItemStack() == null) {
for(int i = 0; i < this.inventorySlots.inventorySlots.size(); ++i) { for(int i = 0; i < this.inventorySlots.inventorySlots.size(); ++i) {
Slot slot = (Slot) this.inventorySlots.inventorySlots.get(i); Slot slot = (Slot) this.inventorySlots.inventorySlots.get(i);
int tileIndex = slot.getSlotIndex(); int tileIndex = slot.getSlotIndex();
if(this.isMouseOverSlot(slot, x, y) && slot instanceof SlotPattern && custom.matcher.modes[tileIndex - 10] != null) { if(this.isMouseOverSlot(slot, x, y) && slot instanceof SlotPattern && custom.matcher.modes[tileIndex - 10] != null) {
String label = EnumChatFormatting.YELLOW + ""; String label = EnumChatFormatting.YELLOW + "";
switch(custom.matcher.modes[tileIndex - 10]) { switch(custom.matcher.modes[tileIndex - 10]) {
case "exact": label += "Item and meta match"; break; case "exact": label += "Item and meta match"; break;
case "wildcard": label += "Item matches"; break; case "wildcard": label += "Item matches"; break;
default: label += "Ore dict key matches: " + custom.matcher.modes[tileIndex - 10]; break; default: label += "Ore dict key matches: " + custom.matcher.modes[tileIndex - 10]; break;
} }
this.func_146283_a(Arrays.asList(new String[] { EnumChatFormatting.RED + "Right click to change", label }), x, y - 30); this.func_146283_a(Arrays.asList(new String[] { EnumChatFormatting.RED + "Right click to change", label }), x, y - 30);
} }
} }
} }
for(int i = 0; i < custom.inputTanks.length; i++) { for(int i = 0; i < custom.inputTanks.length; i++) {
custom.inputTanks[i].renderTankInfo(this, x, y, guiLeft + 8 + 18 * i, guiTop + 18, 16, 34); custom.inputTanks[i].renderTankInfo(this, x, y, guiLeft + 8 + 18 * i, guiTop + 18, 16, 34);
} }
for(int i = 0; i < custom.outputTanks.length; i++) { for(int i = 0; i < custom.outputTanks.length; i++) {
custom.outputTanks[i].renderTankInfo(this, x, y, guiLeft + 78 + 18 * i, guiTop + 18, 16, 34); custom.outputTanks[i].renderTankInfo(this, x, y, guiLeft + 78 + 18 * i, guiTop + 18, 16, 34);
} }
} }
@Override @Override
protected void drawGuiContainerForegroundLayer(int i, int j) { protected void drawGuiContainerForegroundLayer(int i, int j) {
String name = this.custom.getInventoryName(); String name = this.custom.getInventoryName();
this.fontRendererObj.drawString(name, 68 - this.fontRendererObj.getStringWidth(name) / 2, 6, 4210752); this.fontRendererObj.drawString(name, 68 - this.fontRendererObj.getStringWidth(name) / 2, 6, 4210752);
this.fontRendererObj.drawString(I18n.format("container.inventory"), 8, this.ySize - 96 + 2, 4210752); this.fontRendererObj.drawString(I18n.format("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
if(custom.config.fluxMode) this.fontRendererObj.drawString("Flux:" + custom.flux,83, 57,0x08FF00);
} }
@Override @Override
@ -76,17 +79,23 @@ public class GUIMachineCustom extends GuiInfoContainer {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
Minecraft.getMinecraft().getTextureManager().bindTexture(texture); Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
if(custom.config.fluxMode){
drawTexturedModalRect(guiLeft + 78, guiTop + 54, 192, 122,51 , 15);
}
if(custom.maxHeat>0) {
drawTexturedModalRect(guiLeft + 61, guiTop + 53, 236,0 , 18, 18);
GaugeUtil.drawSmoothGauge(guiLeft + 70, guiTop + 62, this.zLevel, (double) custom.heat / (double) custom.config.maxHeat, 5, 2, 1, 0x7F0000);
}
int p = custom.progress * 90 / custom.maxProgress; int p = custom.progress * 90 / custom.maxProgress;
drawTexturedModalRect(guiLeft + 78, guiTop + 119, 192, 0, Math.min(p, 44), 16); drawTexturedModalRect(guiLeft + 78, guiTop + 119, 192, 0, Math.min(p, 44), 16);
if(p > 44) { if(p > 44) {
p-= 44; p-= 44;
drawTexturedModalRect(guiLeft + 78 + 44, guiTop + 119, 192, 16, p, 16); drawTexturedModalRect(guiLeft + 78 + 44, guiTop + 119, 192, 16, p, 16);
} }
int e = (int) (custom.power * 52 / custom.config.maxPower); int e = (int) (custom.power * 52 / custom.config.maxPower);
drawTexturedModalRect(guiLeft + 150, guiTop + 70 - e, 176, 52 - e, 16, e); drawTexturedModalRect(guiLeft + 150, guiTop + 70 - e, 176, 52 - e, 16, e);
for(int i = 0; i < 2; i++) { for(int i = 0; i < 2; i++) {
for(int j = 0; j < 3; j++) { for(int j = 0; j < 3; j++) {
int index = i * 3 + j; int index = i * 3 + j;
@ -99,7 +108,7 @@ public class GUIMachineCustom extends GuiInfoContainer {
} }
} }
} }
for(int i = 0; i < 3; i++) { for(int i = 0; i < 3; i++) {
if(custom.config.fluidInCount <= i) { if(custom.config.fluidInCount <= i) {
drawTexturedModalRect(guiLeft + 7 + i * 18, guiTop + 17, 192 + i * 18, 32, 18, 54); drawTexturedModalRect(guiLeft + 7 + i * 18, guiTop + 17, 192 + i * 18, 32, 18, 54);
@ -108,11 +117,11 @@ public class GUIMachineCustom extends GuiInfoContainer {
drawTexturedModalRect(guiLeft + 77 + i * 18, guiTop + 17, 192 + i * 18, 32, 18, 36); drawTexturedModalRect(guiLeft + 77 + i * 18, guiTop + 17, 192 + i * 18, 32, 18, 36);
} }
} }
for(int i = 0; i < custom.inputTanks.length; i++) { for(int i = 0; i < custom.inputTanks.length; i++) {
custom.inputTanks[i].renderTank(guiLeft + 8 + 18 * i, guiTop + 52, this.zLevel, 16, 34); custom.inputTanks[i].renderTank(guiLeft + 8 + 18 * i, guiTop + 52, this.zLevel, 16, 34);
} }
for(int i = 0; i < custom.outputTanks.length; i++) { for(int i = 0; i < custom.outputTanks.length; i++) {
custom.outputTanks[i].renderTank(guiLeft + 78 + 18 * i, guiTop + 52, this.zLevel, 16, 34); custom.outputTanks[i].renderTank(guiLeft + 78 + 18 * i, guiTop + 52, this.zLevel, 16, 34);
} }

View File

@ -22,12 +22,12 @@ import net.minecraft.init.Items;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
public class CustomMachineRecipes extends SerializableRecipe { public class CustomMachineRecipes extends SerializableRecipe {
public static HashMap<String, List<CustomMachineRecipe>> recipes = new HashMap(); public static HashMap<String, List<CustomMachineRecipe>> recipes = new HashMap();
@Override @Override
public void registerDefaults() { public void registerDefaults() {
recipes.put("paperPress", new ArrayList() {{ recipes.put("paperPress", new ArrayList() {{
CustomMachineRecipe recipe = new CustomMachineRecipe(); CustomMachineRecipe recipe = new CustomMachineRecipe();
recipe.inputFluids = new FluidStack[] {new FluidStack(Fluids.WATER, 250)}; recipe.inputFluids = new FluidStack[] {new FluidStack(Fluids.WATER, 250)};
@ -36,6 +36,13 @@ public class CustomMachineRecipes extends SerializableRecipe {
recipe.outputItems = new Pair[] {new Pair(new ItemStack(Items.paper, 3), 1F)}; recipe.outputItems = new Pair[] {new Pair(new ItemStack(Items.paper, 3), 1F)};
recipe.duration = 60; recipe.duration = 60;
recipe.consumptionPerTick = 10; recipe.consumptionPerTick = 10;
recipe.pollutionMode = true;
recipe.pollutionType = "SOOT";
recipe.pollutionAmount = 0.03f;
recipe.radiationMode = false;
recipe.radiationAmount = 0;
recipe.flux = 0;
recipe.heat = 0;
add(recipe); add(recipe);
}}); }});
} }
@ -58,11 +65,11 @@ public class CustomMachineRecipes extends SerializableRecipe {
@Override @Override
public void readRecipe(JsonElement recipe) { public void readRecipe(JsonElement recipe) {
JsonObject obj = recipe.getAsJsonObject(); JsonObject obj = recipe.getAsJsonObject();
String name = obj.get("recipeKey").getAsString(); String name = obj.get("recipeKey").getAsString();
List<CustomMachineRecipe> list = new ArrayList(); List<CustomMachineRecipe> list = new ArrayList();
JsonArray array = obj.get("recipes").getAsJsonArray(); JsonArray array = obj.get("recipes").getAsJsonArray();
for(int i = 0; i < array.size(); i++) { for(int i = 0; i < array.size(); i++) {
JsonObject rec = array.get(i).getAsJsonObject(); JsonObject rec = array.get(i).getAsJsonObject();
CustomMachineRecipe recipeInstance = new CustomMachineRecipe(); CustomMachineRecipe recipeInstance = new CustomMachineRecipe();
@ -72,56 +79,79 @@ public class CustomMachineRecipes extends SerializableRecipe {
recipeInstance.outputItems = this.readItemStackArrayChance(rec.get("outputItems").getAsJsonArray()); recipeInstance.outputItems = this.readItemStackArrayChance(rec.get("outputItems").getAsJsonArray());
recipeInstance.duration = rec.get("duration").getAsInt(); recipeInstance.duration = rec.get("duration").getAsInt();
recipeInstance.consumptionPerTick = rec.get("consumptionPerTick").getAsInt(); recipeInstance.consumptionPerTick = rec.get("consumptionPerTick").getAsInt();
recipeInstance.pollutionMode = rec.get("pollutionMode").getAsBoolean();
recipeInstance.pollutionType = rec.get("pollutionType").getAsString();
recipeInstance.pollutionAmount = rec.get("pollutionAmount").getAsFloat();
recipeInstance.radiationMode = rec.get("radiationMode").getAsBoolean();
recipeInstance.radiationAmount = rec.get("radiationAmount").getAsFloat();
recipeInstance.flux = rec.get("flux").getAsInt();
recipeInstance.heat = rec.get("heat").getAsInt();
list.add(recipeInstance); list.add(recipeInstance);
} }
recipes.put(name, list); recipes.put(name, list);
} }
@Override @Override
public void writeRecipe(Object recipe, JsonWriter writer) throws IOException { public void writeRecipe(Object recipe, JsonWriter writer) throws IOException {
Entry<String, List<CustomMachineRecipe>> entry = (Entry) recipe; Entry<String, List<CustomMachineRecipe>> entry = (Entry) recipe;
writer.name("recipeKey").value(entry.getKey()); writer.name("recipeKey").value(entry.getKey());
writer.name("recipes").beginArray(); writer.name("recipes").beginArray();
for(CustomMachineRecipe recipeInstance : entry.getValue()) { for(CustomMachineRecipe recipeInstance : entry.getValue()) {
writer.beginObject(); writer.beginObject();
writer.name("inputFluids").beginArray(); writer.name("inputFluids").beginArray();
for(FluidStack stack : recipeInstance.inputFluids) this.writeFluidStack(stack, writer); for(FluidStack stack : recipeInstance.inputFluids) this.writeFluidStack(stack, writer);
writer.endArray(); writer.endArray();
writer.name("inputItems").beginArray(); writer.name("inputItems").beginArray();
for(AStack stack : recipeInstance.inputItems) this.writeAStack(stack, writer); for(AStack stack : recipeInstance.inputItems) this.writeAStack(stack, writer);
writer.endArray(); writer.endArray();
writer.name("outputFluids").beginArray(); writer.name("outputFluids").beginArray();
for(FluidStack stack : recipeInstance.outputFluids) this.writeFluidStack(stack, writer); for(FluidStack stack : recipeInstance.outputFluids) this.writeFluidStack(stack, writer);
writer.endArray(); writer.endArray();
writer.name("outputItems").beginArray(); writer.name("outputItems").beginArray();
for(Pair stack : recipeInstance.outputItems) this.writeItemStackChance(stack, writer); for(Pair stack : recipeInstance.outputItems) this.writeItemStackChance(stack, writer);
writer.endArray(); writer.endArray();
writer.name("duration").value(recipeInstance.duration); writer.name("duration").value(recipeInstance.duration);
writer.name("consumptionPerTick").value(recipeInstance.consumptionPerTick); writer.name("consumptionPerTick").value(recipeInstance.consumptionPerTick);
writer.name("pollutionMode").value(recipeInstance.pollutionMode);
writer.name("pollutionType").value(recipeInstance.pollutionType);
writer.name("pollutionAmount").value(recipeInstance.pollutionAmount);
writer.name("radiationMode").value(recipeInstance.radiationMode);
writer.name("radiationnAmount").value(recipeInstance.radiationAmount);
writer.name("flux").value(recipeInstance.flux);
writer.name("heat").value(recipeInstance.heat);
writer.endObject(); writer.endObject();
} }
writer.endArray(); writer.endArray();
} }
public static class CustomMachineRecipe { public static class CustomMachineRecipe {
public FluidStack[] inputFluids; public FluidStack[] inputFluids;
public AStack[] inputItems; public AStack[] inputItems;
public FluidStack[] outputFluids; public FluidStack[] outputFluids;
public Pair<ItemStack, Float>[] outputItems; public Pair<ItemStack, Float>[] outputItems;
public int duration; public int duration;
public int consumptionPerTick; public int consumptionPerTick;
public boolean pollutionMode;
public String pollutionType;
public float pollutionAmount;
public boolean radiationMode;
public float radiationAmount;
public int flux;
public int heat;
} }
} }

View File

@ -1166,6 +1166,8 @@ public class CraftingManager {
addRecipeAuto(new ItemStack(ModBlocks.cm_circuit, 1, 2), " I ", "IMI", " I ", 'I', STEEL.ingot(), 'M', ModItems.circuit_red_copper); addRecipeAuto(new ItemStack(ModBlocks.cm_circuit, 1, 2), " I ", "IMI", " I ", 'I', STEEL.ingot(), 'M', ModItems.circuit_red_copper);
addRecipeAuto(new ItemStack(ModBlocks.cm_circuit, 1, 3), " I ", "IMI", " I ", 'I', STEEL.ingot(), 'M', ModItems.circuit_gold); addRecipeAuto(new ItemStack(ModBlocks.cm_circuit, 1, 3), " I ", "IMI", " I ", 'I', STEEL.ingot(), 'M', ModItems.circuit_gold);
addRecipeAuto(new ItemStack(ModBlocks.cm_circuit, 1, 4), " I ", "IMI", " I ", 'I', STEEL.ingot(), 'M', ModItems.circuit_schrabidium); addRecipeAuto(new ItemStack(ModBlocks.cm_circuit, 1, 4), " I ", "IMI", " I ", 'I', STEEL.ingot(), 'M', ModItems.circuit_schrabidium);
addRecipeAuto(new ItemStack(ModBlocks.cm_flux, 1, 0), "NZN", "ZCZ", "NZN", 'Z', ZR.plateCast(), 'N', ModItems.neutron_reflector, 'C', ModItems.reactor_core);
addRecipeAuto(new ItemStack(ModBlocks.cm_heat, 1, 0), "PCP", "PSP", "PCP", 'P', ANY_PLASTIC.ingot(), 'C', ModItems.board_copper, 'S', ModItems.pipes_steel);
} }
public static void crumple() { public static void crumple() {

View File

@ -3,9 +3,14 @@ package com.hbm.tileentity.machine;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import api.hbm.tile.IHeatSource;
import com.hbm.blocks.ModBlocks;
import com.hbm.blocks.machine.ReactorResearch;
import com.hbm.config.CustomMachineConfigJSON; import com.hbm.config.CustomMachineConfigJSON;
import com.hbm.config.CustomMachineConfigJSON.MachineConfiguration; import com.hbm.config.CustomMachineConfigJSON.MachineConfiguration;
import com.hbm.config.CustomMachineConfigJSON.MachineConfiguration.ComponentDefinition; import com.hbm.config.CustomMachineConfigJSON.MachineConfiguration.ComponentDefinition;
import com.hbm.handler.pollution.PollutionHandler;
import com.hbm.handler.radiation.ChunkRadiationManager;
import com.hbm.inventory.container.ContainerMachineCustom; import com.hbm.inventory.container.ContainerMachineCustom;
import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.fluid.tank.FluidTank; import com.hbm.inventory.fluid.tank.FluidTank;
@ -15,7 +20,7 @@ import com.hbm.inventory.recipes.CustomMachineRecipes.CustomMachineRecipe;
import com.hbm.lib.Library; import com.hbm.lib.Library;
import com.hbm.module.ModulePatternMatcher; import com.hbm.module.ModulePatternMatcher;
import com.hbm.tileentity.IGUIProvider; import com.hbm.tileentity.IGUIProvider;
import com.hbm.tileentity.TileEntityMachineBase; import com.hbm.tileentity.TileEntityMachinePolluting;
import com.hbm.tileentity.TileEntityProxyBase; import com.hbm.tileentity.TileEntityProxyBase;
import com.hbm.util.Compat; import com.hbm.util.Compat;
import com.hbm.util.fauxpointtwelve.BlockPos; import com.hbm.util.fauxpointtwelve.BlockPos;
@ -35,12 +40,15 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityCustomMachine extends TileEntityMachineBase implements IFluidStandardTransceiver, IEnergyUser, IGUIProvider { public class TileEntityCustomMachine extends TileEntityMachinePolluting implements IFluidStandardTransceiver, IEnergyUser, IGUIProvider {
public String machineType; public String machineType;
public MachineConfiguration config; public MachineConfiguration config;
public long power; public long power;
public int flux;
public int heat;
public int maxHeat;
public int progress; public int progress;
public int maxProgress = 1; public int maxProgress = 1;
public FluidTank[] inputTanks; public FluidTank[] inputTanks;
@ -49,8 +57,10 @@ public class TileEntityCustomMachine extends TileEntityMachineBase implements IF
public int structureCheckDelay; public int structureCheckDelay;
public boolean structureOK = false; public boolean structureOK = false;
public CustomMachineRecipe cachedRecipe; public CustomMachineRecipe cachedRecipe;
public List<DirPos> connectionPos = new ArrayList(); public List<DirPos> connectionPos = new ArrayList();
public List<DirPos> fluxPos = new ArrayList();
public List<DirPos> heatPos = new ArrayList();
public TileEntityCustomMachine() { public TileEntityCustomMachine() {
/* /*
@ -60,22 +70,26 @@ public class TileEntityCustomMachine extends TileEntityMachineBase implements IF
* 10-15: Template * 10-15: Template
* 16-21: Output * 16-21: Output
*/ */
super(22); super(22, 100);
} }
public void init() { public void init() {
MachineConfiguration config = CustomMachineConfigJSON.customMachines.get(this.machineType); MachineConfiguration config = CustomMachineConfigJSON.customMachines.get(this.machineType);
if(config != null) { if (config != null) {
this.config = config; this.config = config;
inputTanks = new FluidTank[config.fluidInCount]; inputTanks = new FluidTank[config.fluidInCount];
for(int i = 0; i < inputTanks.length; i++) inputTanks[i] = new FluidTank(Fluids.NONE, config.fluidInCap); for (int i = 0; i < inputTanks.length; i++) inputTanks[i] = new FluidTank(Fluids.NONE, config.fluidInCap);
outputTanks = new FluidTank[config.fluidOutCount]; outputTanks = new FluidTank[config.fluidOutCount];
for(int i = 0; i < outputTanks.length; i++) outputTanks[i] = new FluidTank(Fluids.NONE, config.fluidOutCap); for (int i = 0; i < outputTanks.length; i++)
outputTanks[i] = new FluidTank(Fluids.NONE, config.fluidOutCap);
maxHeat = config.maxHeat;
matcher = new ModulePatternMatcher(config.itemInCount); matcher = new ModulePatternMatcher(config.itemInCount);
smoke.changeTankSize(config.maxPollutionCap);
smoke_leaded.changeTankSize(config.maxPollutionCap);
smoke_poison.changeTankSize(config.maxPollutionCap);
} else { } else {
worldObj.func_147480_a(xCoord, yCoord, zCoord, false); worldObj.func_147480_a(xCoord, yCoord, zCoord, false);
} }
@ -88,75 +102,112 @@ public class TileEntityCustomMachine extends TileEntityMachineBase implements IF
@Override @Override
public void updateEntity() { public void updateEntity() {
if(!worldObj.isRemote) { if (!worldObj.isRemote) {
if(config == null) { if (config == null) {
worldObj.func_147480_a(xCoord, yCoord, zCoord, false); worldObj.func_147480_a(xCoord, yCoord, zCoord, false);
return; return;
} }
this.power = Library.chargeTEFromItems(slots, 0, power, this.config.maxPower); this.power = Library.chargeTEFromItems(slots, 0, power, this.config.maxPower);
if(this.inputTanks.length > 0) this.inputTanks[0].setType(1, slots); if (this.inputTanks.length > 0) this.inputTanks[0].setType(1, slots);
if(this.inputTanks.length > 1) this.inputTanks[1].setType(2, slots); if (this.inputTanks.length > 1) this.inputTanks[1].setType(2, slots);
if(this.inputTanks.length > 2) this.inputTanks[2].setType(3, slots); if (this.inputTanks.length > 2) this.inputTanks[2].setType(3, slots);
this.structureCheckDelay--; this.structureCheckDelay--;
if(this.structureCheckDelay <= 0) this.checkStructure(); if (this.structureCheckDelay <= 0) this.checkStructure();
if(this.worldObj.getTotalWorldTime() % 20 == 0) { if (this.worldObj.getTotalWorldTime() % 20 == 0) {
for(DirPos pos : this.connectionPos) { for (DirPos pos : this.connectionPos) {
for(FluidTank tank : this.inputTanks) { for (FluidTank tank : this.inputTanks) {
this.trySubscribe(tank.getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.trySubscribe(tank.getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
} }
if(!config.generatorMode) this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); if (!config.generatorMode)
this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
}
for (byte d = 2; d < 6; d++) {
ForgeDirection dir = ForgeDirection.getOrientation(d);
for (DirPos pos : this.fluxPos) {
Block b = worldObj.getBlock(pos.getX() + dir.offsetX, pos.getY(), pos.getZ() + dir.offsetZ);
if (b == ModBlocks.reactor_research) {
int[] source = ((ReactorResearch) ModBlocks.reactor_research).findCore(worldObj, pos.getX() + dir.offsetX, pos.getY(), pos.getZ() + dir.offsetZ);
if (source != null) {
TileEntity tile = worldObj.getTileEntity(source[0], source[1], source[2]);
if (tile instanceof TileEntityReactorResearch) {
TileEntityReactorResearch reactor = (TileEntityReactorResearch) tile;
this.flux = reactor.totalFlux;
}
}
}
}
if(config.maxHeat>0){
for (DirPos pos : this.heatPos){
this.tryPullHeat(pos.getX() + dir.offsetX, pos.getY()-1, pos.getZ() + dir.offsetZ);
}
}
} }
} }
for(DirPos pos : this.connectionPos) { for (DirPos pos : this.connectionPos) {
if(config.generatorMode && power > 0) this.sendPower(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); if (config.generatorMode && power > 0)
for(FluidTank tank : this.outputTanks) if(tank.getFill() > 0) this.sendFluid(tank, worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.sendPower(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
for (FluidTank tank : this.outputTanks)
if (tank.getFill() > 0)
this.sendFluid(tank, worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
this.sendSmoke(pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
} }
if(this.structureOK) { if (this.structureOK) {
if(config.generatorMode) { if (config.generatorMode) {
if(this.cachedRecipe == null) { if (this.cachedRecipe == null) {
CustomMachineRecipe recipe = this.getMatchingRecipe(); CustomMachineRecipe recipe = this.getMatchingRecipe();
if(recipe != null && this.hasRequiredQuantities(recipe) && this.hasSpace(recipe)) { if (recipe != null && this.hasRequiredQuantities(recipe) && this.hasSpace(recipe)) {
this.cachedRecipe = recipe; this.cachedRecipe = recipe;
this.useUpInput(recipe); this.useUpInput(recipe);
} }
} }
if(this.cachedRecipe != null) { if (this.cachedRecipe != null) {
this.maxProgress = (int) Math.max(cachedRecipe.duration / this.config.recipeSpeedMult, 1); this.maxProgress = (int) Math.max(cachedRecipe.duration / this.config.recipeSpeedMult, 1);
int powerReq = (int) Math.max(cachedRecipe.consumptionPerTick * this.config.recipeConsumptionMult, 1); int powerReq = (int) Math.max(cachedRecipe.consumptionPerTick * this.config.recipeConsumptionMult, 1);
this.progress++; this.progress++;
this.power += powerReq; this.power += powerReq;
if(power > config.maxPower) power = config.maxPower; this.heat -= cachedRecipe.heat;
if (power > config.maxPower) power = config.maxPower;
if(progress >= this.maxProgress) { if (worldObj.getTotalWorldTime() % 20 == 0) {
pollution(cachedRecipe);
radiation(cachedRecipe);
}
if (progress >= this.maxProgress) {
this.progress = 0; this.progress = 0;
this.processRecipe(cachedRecipe); this.processRecipe(cachedRecipe);
this.cachedRecipe = null; this.cachedRecipe = null;
} }
} }
} else { } else {
CustomMachineRecipe recipe = this.getMatchingRecipe(); CustomMachineRecipe recipe = this.getMatchingRecipe();
if(recipe != null) { if (recipe != null) {
this.maxProgress = (int) Math.max(recipe.duration / this.config.recipeSpeedMult, 1); this.maxProgress = (int) Math.max(recipe.duration / this.config.recipeSpeedMult, 1);
int powerReq = (int) Math.max(recipe.consumptionPerTick * this.config.recipeConsumptionMult, 1); int powerReq = (int) Math.max(recipe.consumptionPerTick * this.config.recipeConsumptionMult, 1);
if(this.power >= powerReq && this.hasRequiredQuantities(recipe) && this.hasSpace(recipe)) { if (this.power >= powerReq && this.hasRequiredQuantities(recipe) && this.hasSpace(recipe)) {
this.progress++; this.progress++;
this.power -= powerReq; this.power -= powerReq;
this.heat -= recipe.heat;
if(progress >= this.maxProgress) { if (worldObj.getTotalWorldTime() % 20 == 0) {
pollution(recipe);
radiation(recipe);
}
if (progress >= this.maxProgress) {
this.progress = 0; this.progress = 0;
this.useUpInput(recipe); this.useUpInput(recipe);
this.processRecipe(recipe); this.processRecipe(recipe);
@ -169,89 +220,129 @@ public class TileEntityCustomMachine extends TileEntityMachineBase implements IF
} else { } else {
this.progress = 0; this.progress = 0;
} }
NBTTagCompound data = new NBTTagCompound(); NBTTagCompound data = new NBTTagCompound();
data.setString("type", this.machineType); data.setString("type", this.machineType);
data.setLong("power", power); data.setLong("power", power);
data.setBoolean("structureOK", structureOK); data.setBoolean("structureOK", structureOK);
data.setInteger("flux", flux);
data.setInteger("heat", heat);
data.setInteger("progress", progress); data.setInteger("progress", progress);
data.setInteger("maxProgress", maxProgress); data.setInteger("maxProgress", maxProgress);
for(int i = 0; i < inputTanks.length; i++) inputTanks[i].writeToNBT(data, "i" + i); for (int i = 0; i < inputTanks.length; i++) inputTanks[i].writeToNBT(data, "i" + i);
for(int i = 0; i < outputTanks.length; i++) outputTanks[i].writeToNBT(data, "o" + i); for (int i = 0; i < outputTanks.length; i++) outputTanks[i].writeToNBT(data, "o" + i);
this.matcher.writeToNBT(data); this.matcher.writeToNBT(data);
this.networkPack(data, 50); this.networkPack(data, 50);
} }
} }
/** Only accepts inputs in a fixed order, saves a ton of performance because there's no permutations to check for */ /** Only accepts inputs in a fixed order, saves a ton of performance because there's no permutations to check for */
public CustomMachineRecipe getMatchingRecipe() { public CustomMachineRecipe getMatchingRecipe() {
List<CustomMachineRecipe> recipes = CustomMachineRecipes.recipes.get(this.config.recipeKey); List<CustomMachineRecipe> recipes = CustomMachineRecipes.recipes.get(this.config.recipeKey);
if(recipes == null || recipes.isEmpty()) return null; if(recipes == null || recipes.isEmpty()) return null;
outer: outer:
for(CustomMachineRecipe recipe : recipes) { for(CustomMachineRecipe recipe : recipes) {
for(int i = 0; i < recipe.inputFluids.length; i++) { for(int i = 0; i < recipe.inputFluids.length; i++) {
if(this.inputTanks[i].getTankType() != recipe.inputFluids[i].type || this.inputTanks[i].getPressure() != recipe.inputFluids[i].pressure) continue outer; if(this.inputTanks[i].getTankType() != recipe.inputFluids[i].type || this.inputTanks[i].getPressure() != recipe.inputFluids[i].pressure) continue outer;
} }
for(int i = 0; i < recipe.inputItems.length; i++) { for(int i = 0; i < recipe.inputItems.length; i++) {
if(recipe.inputItems[i] != null && slots[i + 4] == null) continue outer; if(recipe.inputItems[i] != null && slots[i + 4] == null) continue outer;
if(!recipe.inputItems[i].matchesRecipe(slots[i + 4], true)) continue outer; if(!recipe.inputItems[i].matchesRecipe(slots[i + 4], true)) continue outer;
} }
return recipe; return recipe;
} }
return null; return null;
} }
public void pollution(CustomMachineRecipe recipe) {
if (recipe.pollutionMode) {
if (recipe.pollutionAmount > 0) {
this.pollute(PollutionHandler.PollutionType.valueOf(recipe.pollutionType), recipe.pollutionAmount);
} else if (recipe.pollutionAmount < 0 && PollutionHandler.getPollution(worldObj, xCoord, yCoord, zCoord, PollutionHandler.PollutionType.valueOf(recipe.pollutionType)) >= -recipe.pollutionAmount) {
PollutionHandler.decrementPollution(worldObj, xCoord, yCoord, zCoord, PollutionHandler.PollutionType.valueOf(recipe.pollutionType), -recipe.pollutionAmount);
}
}
}
public void radiation(CustomMachineRecipe recipe){
if (recipe.radiationMode) {
if (recipe.radiationAmount > 0) {
ChunkRadiationManager.proxy.incrementRad(worldObj, xCoord, yCoord, zCoord, recipe.radiationAmount);
} else if (recipe.radiationAmount < 0) {
ChunkRadiationManager.proxy.decrementRad(worldObj, xCoord, yCoord, zCoord, -recipe.radiationAmount);
}
}
}
protected void tryPullHeat(int x, int y, int z) {
TileEntity con = worldObj.getTileEntity(x, y, z);
if(con instanceof IHeatSource) {
IHeatSource source = (IHeatSource) con;
int diff = source.getHeatStored() - this.heat;
if(diff == 0) {
return;
}
if(diff > 0) {
source.useUpHeat(diff);
this.heat += diff;
if(this.heat > this.maxHeat)
this.heat = this.maxHeat;
}
}
}
public boolean hasRequiredQuantities(CustomMachineRecipe recipe) { public boolean hasRequiredQuantities(CustomMachineRecipe recipe) {
for(int i = 0; i < recipe.inputFluids.length; i++) { for(int i = 0; i < recipe.inputFluids.length; i++) {
if(this.inputTanks[i].getFill() < recipe.inputFluids[i].fill) return false; if(this.inputTanks[i].getFill() < recipe.inputFluids[i].fill) return false;
} }
for(int i = 0; i < recipe.inputItems.length; i++) { for(int i = 0; i < recipe.inputItems.length; i++) {
if(slots[i + 4] != null && slots[i + 4].stackSize < recipe.inputItems[i].stacksize) return false; if(slots[i + 4] != null && slots[i + 4].stackSize < recipe.inputItems[i].stacksize) return false;
} }
if(config.fluxMode ? this.flux < recipe.flux : false) return false;
if(config.maxHeat>0 && recipe.heat>0 ? this.heat < recipe.heat : false) return false;
return true; return true;
} }
public boolean hasSpace(CustomMachineRecipe recipe) { public boolean hasSpace(CustomMachineRecipe recipe) {
for(int i = 0; i < recipe.outputFluids.length; i++) { for(int i = 0; i < recipe.outputFluids.length; i++) {
if(this.outputTanks[i].getTankType() == recipe.outputFluids[i].type && this.outputTanks[i].getFill() + recipe.outputFluids[i].fill > this.outputTanks[i].getMaxFill()) return false; if(this.outputTanks[i].getTankType() == recipe.outputFluids[i].type && this.outputTanks[i].getFill() + recipe.outputFluids[i].fill > this.outputTanks[i].getMaxFill()) return false;
} }
for(int i = 0; i < recipe.outputItems.length; i++) { for(int i = 0; i < recipe.outputItems.length; i++) {
if(slots[i + 16] != null && (slots[i + 16].getItem() != recipe.outputItems[i].key.getItem() || slots[i + 16].getItemDamage() != recipe.outputItems[i].key.getItemDamage())) return false; if(slots[i + 16] != null && (slots[i + 16].getItem() != recipe.outputItems[i].key.getItem() || slots[i + 16].getItemDamage() != recipe.outputItems[i].key.getItemDamage())) return false;
if(slots[i + 16] != null && slots[16 + i].stackSize + recipe.outputItems[i].key.stackSize > slots[i + 16].getMaxStackSize()) return false; if(slots[i + 16] != null && slots[16 + i].stackSize + recipe.outputItems[i].key.stackSize > slots[i + 16].getMaxStackSize()) return false;
} }
return true; return true;
} }
public void useUpInput(CustomMachineRecipe recipe) { public void useUpInput(CustomMachineRecipe recipe) {
for(int i = 0; i < recipe.inputFluids.length; i++) { for(int i = 0; i < recipe.inputFluids.length; i++) {
this.inputTanks[i].setFill(this.inputTanks[i].getFill() - recipe.inputFluids[i].fill); this.inputTanks[i].setFill(this.inputTanks[i].getFill() - recipe.inputFluids[i].fill);
} }
for(int i = 0; i < recipe.inputItems.length; i++) { for(int i = 0; i < recipe.inputItems.length; i++) {
this.decrStackSize(i + 4, recipe.inputItems[i].stacksize); this.decrStackSize(i + 4, recipe.inputItems[i].stacksize);
} }
} }
public void processRecipe(CustomMachineRecipe recipe) { public void processRecipe(CustomMachineRecipe recipe) {
for(int i = 0; i < recipe.outputFluids.length; i++) { for(int i = 0; i < recipe.outputFluids.length; i++) {
if(this.outputTanks[i].getTankType() != recipe.outputFluids[i].type) this.outputTanks[i].setTankType(recipe.outputFluids[i].type); if(this.outputTanks[i].getTankType() != recipe.outputFluids[i].type) this.outputTanks[i].setTankType(recipe.outputFluids[i].type);
this.outputTanks[i].setFill(this.outputTanks[i].getFill() + recipe.outputFluids[i].fill); this.outputTanks[i].setFill(this.outputTanks[i].getFill() + recipe.outputFluids[i].fill);
} }
for(int i = 0; i < recipe.outputItems.length; i++) { for(int i = 0; i < recipe.outputItems.length; i++) {
if(worldObj.rand.nextFloat() < recipe.outputItems[i].value) { if(worldObj.rand.nextFloat() < recipe.outputItems[i].value) {
if(slots[i + 16] == null) { if(slots[i + 16] == null) {
slots[i + 16] = recipe.outputItems[i].key.copy(); slots[i + 16] = recipe.outputItems[i].key.copy();
@ -261,19 +352,18 @@ public class TileEntityCustomMachine extends TileEntityMachineBase implements IF
} }
} }
} }
public boolean checkStructure() { public boolean checkStructure() {
this.connectionPos.clear(); this.connectionPos.clear();
this.structureCheckDelay = 300; this.structureCheckDelay = 300;
this.structureOK = false; this.structureOK = false;
if(this.config == null) return false; if(this.config == null) return false;
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata()); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata());
ForgeDirection rot = dir.getRotation(ForgeDirection.UP); ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
for(ComponentDefinition comp : config.components) { for(ComponentDefinition comp : config.components) {
/* vvv precisely the same method used for defining ports vvv */ /* vvv precisely the same method used for defining ports vvv */
int x = xCoord - dir.offsetX * comp.x + rot.offsetX * comp.x; int x = xCoord - dir.offsetX * comp.x + rot.offsetX * comp.x;
int y = yCoord + comp.y; int y = yCoord + comp.y;
@ -285,42 +375,52 @@ public class TileEntityCustomMachine extends TileEntityMachineBase implements IF
z = zCoord + dir.offsetX * comp.x - rot.offsetX * comp.x; z = zCoord + dir.offsetX * comp.x - rot.offsetX * comp.x;
} }
/* i wholeheartedly believe it is the computer who is wrong here */ /* i wholeheartedly believe it is the computer who is wrong here */
Block b = worldObj.getBlock(x, y, z); Block b = worldObj.getBlock(x, y, z);
if(b != comp.block) return false; if(b != comp.block) return false;
int meta = worldObj.getBlockMetadata(x, y, z); int meta = worldObj.getBlockMetadata(x, y, z);
if(!comp.allowedMetas.contains(meta)) return false; if(!comp.allowedMetas.contains(meta)) return false;
TileEntity tile = Compat.getTileStandard(worldObj, x, y, z); TileEntity tile = Compat.getTileStandard(worldObj, x, y, z);
if(tile instanceof TileEntityProxyBase) { if(tile instanceof TileEntityProxyBase) {
TileEntityProxyBase proxy = (TileEntityProxyBase) tile; TileEntityProxyBase proxy = (TileEntityProxyBase) tile;
proxy.cachedPosition = new BlockPos(xCoord, yCoord, zCoord); proxy.cachedPosition = new BlockPos(xCoord, yCoord, zCoord);
proxy.markDirty(); proxy.markDirty();
for(ForgeDirection facing : ForgeDirection.VALID_DIRECTIONS) { for(ForgeDirection facing : ForgeDirection.VALID_DIRECTIONS) {
this.connectionPos.add(new DirPos(x + facing.offsetX, y + facing.offsetY, z + facing.offsetZ, facing)); this.connectionPos.add(new DirPos(x + facing.offsetX, y + facing.offsetY, z + facing.offsetZ, facing));
} }
} }
if(worldObj.getBlock(x,y,z) == ModBlocks.cm_flux){
for(ForgeDirection facing : ForgeDirection.VALID_DIRECTIONS) {
this.fluxPos.add(new DirPos(x + facing.offsetX, y + facing.offsetY, z + facing.offsetZ, facing));
}
}
else if(worldObj.getBlock(x,y,z) == ModBlocks.cm_heat){
for(ForgeDirection facing : ForgeDirection.VALID_DIRECTIONS) {
this.heatPos.add(new DirPos(x + facing.offsetX, y + facing.offsetY, z + facing.offsetZ, facing));
}
}
} }
for(ForgeDirection facing : ForgeDirection.VALID_DIRECTIONS) { for(ForgeDirection facing : ForgeDirection.VALID_DIRECTIONS) {
this.connectionPos.add(new DirPos(xCoord + facing.offsetX, yCoord + facing.offsetY, zCoord + facing.offsetZ, facing)); this.connectionPos.add(new DirPos(xCoord + facing.offsetX, yCoord + facing.offsetY, zCoord + facing.offsetZ, facing));
} }
this.structureOK = true; this.structureOK = true;
return true; return true;
} }
public void buildStructure() { public void buildStructure() {
if(this.config == null) return; if(this.config == null) return;
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata()); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata());
ForgeDirection rot = dir.getRotation(ForgeDirection.UP); ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
for(ComponentDefinition comp : config.components) { for(ComponentDefinition comp : config.components) {
int x = xCoord - dir.offsetX * comp.x + rot.offsetX * comp.x; int x = xCoord - dir.offsetX * comp.x + rot.offsetX * comp.x;
int y = yCoord + comp.y; int y = yCoord + comp.y;
int z = zCoord - dir.offsetZ * comp.z + rot.offsetZ * comp.z; int z = zCoord - dir.offsetZ * comp.z + rot.offsetZ * comp.z;
@ -328,7 +428,7 @@ public class TileEntityCustomMachine extends TileEntityMachineBase implements IF
x = xCoord + dir.offsetZ * comp.z - rot.offsetZ * comp.z; x = xCoord + dir.offsetZ * comp.z - rot.offsetZ * comp.z;
z = zCoord + dir.offsetX * comp.x - rot.offsetX * comp.x; z = zCoord + dir.offsetX * comp.x - rot.offsetX * comp.x;
} }
worldObj.setBlock(x, y, z, comp.block, (int) comp.allowedMetas.toArray()[0], 3); worldObj.setBlock(x, y, z, comp.block, (int) comp.allowedMetas.toArray()[0], 3);
} }
} }
@ -353,12 +453,12 @@ public class TileEntityCustomMachine extends TileEntityMachineBase implements IF
@Override @Override
public boolean isItemValidForSlot(int slot, ItemStack stack) { public boolean isItemValidForSlot(int slot, ItemStack stack) {
if(slot < 4 || slot > 9) return false; if(slot < 4 || slot > 9) return false;
int index = slot - 4; int index = slot - 4;
int filterSlot = slot + 6; int filterSlot = slot + 6;
if(slots[filterSlot] == null) return true; if(slots[filterSlot] == null) return true;
return matcher.isValidForFilter(slots[filterSlot], index, stack); return matcher.isValidForFilter(slots[filterSlot], index, stack);
} }
@ -366,56 +466,58 @@ public class TileEntityCustomMachine extends TileEntityMachineBase implements IF
public void networkUnpack(NBTTagCompound nbt) { public void networkUnpack(NBTTagCompound nbt) {
this.machineType = nbt.getString("type"); this.machineType = nbt.getString("type");
if(this.config == null) this.init(); if(this.config == null) this.init();
this.power = nbt.getLong("power"); this.power = nbt.getLong("power");
this.progress = nbt.getInteger("progress"); this.progress = nbt.getInteger("progress");
this.flux = nbt.getInteger("flux");
this.heat = nbt.getInteger("heat");
this.structureOK = nbt.getBoolean("structureOK"); this.structureOK = nbt.getBoolean("structureOK");
this.maxProgress = nbt.getInteger("maxProgress"); this.maxProgress = nbt.getInteger("maxProgress");
for(int i = 0; i < inputTanks.length; i++) inputTanks[i].readFromNBT(nbt, "i" + i); for(int i = 0; i < inputTanks.length; i++) inputTanks[i].readFromNBT(nbt, "i" + i);
for(int i = 0; i < outputTanks.length; i++) outputTanks[i].readFromNBT(nbt, "o" + i); for(int i = 0; i < outputTanks.length; i++) outputTanks[i].readFromNBT(nbt, "o" + i);
this.matcher.readFromNBT(nbt); this.matcher.readFromNBT(nbt);
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
this.machineType = nbt.getString("machineType"); this.machineType = nbt.getString("machineType");
this.init(); this.init();
super.readFromNBT(nbt); super.readFromNBT(nbt);
if(this.config != null) { if(this.config != null) {
for(int i = 0; i < inputTanks.length; i++) inputTanks[i].readFromNBT(nbt, "i" + i); for(int i = 0; i < inputTanks.length; i++) inputTanks[i].readFromNBT(nbt, "i" + i);
for(int i = 0; i < outputTanks.length; i++) outputTanks[i].readFromNBT(nbt, "o" + i); for(int i = 0; i < outputTanks.length; i++) outputTanks[i].readFromNBT(nbt, "o" + i);
this.matcher.readFromNBT(nbt); this.matcher.readFromNBT(nbt);
int index = nbt.getInteger("cachedIndex"); int index = nbt.getInteger("cachedIndex");
if(index != -1) { if(index != -1) {
this.cachedRecipe = CustomMachineRecipes.recipes.get(this.config.recipeKey).get(index); this.cachedRecipe = CustomMachineRecipes.recipes.get(this.config.recipeKey).get(index);
} }
} }
} }
@Override @Override
public void writeToNBT(NBTTagCompound nbt) { public void writeToNBT(NBTTagCompound nbt) {
if(machineType == null || this.config == null) { if(machineType == null || this.config == null) {
super.writeToNBT(nbt); super.writeToNBT(nbt);
return; return;
} }
nbt.setString("machineType", machineType); nbt.setString("machineType", machineType);
super.writeToNBT(nbt); super.writeToNBT(nbt);
for(int i = 0; i < inputTanks.length; i++) inputTanks[i].writeToNBT(nbt, "i" + i); for(int i = 0; i < inputTanks.length; i++) inputTanks[i].writeToNBT(nbt, "i" + i);
for(int i = 0; i < outputTanks.length; i++) outputTanks[i].writeToNBT(nbt, "o" + i); for(int i = 0; i < outputTanks.length; i++) outputTanks[i].writeToNBT(nbt, "o" + i);
this.matcher.writeToNBT(nbt); this.matcher.writeToNBT(nbt);
if(this.cachedRecipe != null) { if(this.cachedRecipe != null) {
int index = CustomMachineRecipes.recipes.get(this.config.recipeKey).indexOf(this.cachedRecipe); int index = CustomMachineRecipes.recipes.get(this.config.recipeKey).indexOf(this.cachedRecipe);
nbt.setInteger("cachedIndex", index); nbt.setInteger("cachedIndex", index);
@ -426,18 +528,22 @@ public class TileEntityCustomMachine extends TileEntityMachineBase implements IF
@Override @Override
public FluidTank[] getAllTanks() { public FluidTank[] getAllTanks() {
FluidTank[] all = new FluidTank[inputTanks.length + outputTanks.length]; FluidTank[] all = new FluidTank[inputTanks.length + outputTanks.length];
for(int i = 0; i < inputTanks.length; i++) all[i] = inputTanks[i]; for(int i = 0; i < inputTanks.length; i++) all[i] = inputTanks[i];
for(int i = 0; i < outputTanks.length; i++) all[inputTanks.length + i] = outputTanks[i]; for(int i = 0; i < outputTanks.length; i++) all[inputTanks.length + i] = outputTanks[i];
return all; return all;
} }
@Override @Override
public FluidTank[] getSendingTanks() { public FluidTank[] getSendingTanks() {
return outputTanks != null ? outputTanks : new FluidTank[0]; FluidTank[] all = new FluidTank[outputTanks.length + this.getSmokeTanks().length];
for(int i = 0; i < outputTanks.length; i++) all[i] = outputTanks[i];
for(int i = 0; i < this.getSmokeTanks().length; i++) all[outputTanks.length + i] = this.getSmokeTanks()[i];
//return outputTanks != null ? outputTanks : new FluidTank[0];
return all;
} }
@Override @Override
@ -472,20 +578,20 @@ public class TileEntityCustomMachine extends TileEntityMachineBase implements IF
public void setPower(long power) { public void setPower(long power) {
this.power = power; this.power = power;
} }
@Override @Override
public long transferPower(long power) { public long transferPower(long power) {
if(this.config != null && this.config.generatorMode) return power; if(this.config != null && this.config.generatorMode) return power;
this.setPower(this.getPower() + power); this.setPower(this.getPower() + power);
if(this.getPower() > this.getMaxPower()) { if(this.getPower() > this.getMaxPower()) {
long overshoot = this.getPower() - this.getMaxPower(); long overshoot = this.getPower() - this.getMaxPower();
this.setPower(this.getMaxPower()); this.setPower(this.getMaxPower());
return overshoot; return overshoot;
} }
return 0; return 0;
} }

View File

@ -4724,6 +4724,8 @@ tile.cm_circuit.schrabidium.name=Tier 5 Circuit Block
tile.cm_engine.bismuth.name=Bismuth Motor Block tile.cm_engine.bismuth.name=Bismuth Motor Block
tile.cm_engine.desh.name=Desh Motor Block tile.cm_engine.desh.name=Desh Motor Block
tile.cm_engine.standard.name=Motor Block tile.cm_engine.standard.name=Motor Block
tile.cm_flux.name=Neutron Flux Receiver
tile.cm_heat.name=Heat receiver
tile.cm_port.alloy.name=Advanced Alloy Port tile.cm_port.alloy.name=Advanced Alloy Port
tile.cm_port.desh.name=Desh Port tile.cm_port.desh.name=Desh Port
tile.cm_port.steel.name=Steel Port tile.cm_port.steel.name=Steel Port

Binary file not shown.

After

Width:  |  Height:  |  Size: 410 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 541 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 742 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB