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

View File

@ -5,6 +5,7 @@ import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import codechicken.lib.gui.GuiDraw;
import com.hbm.blocks.ModBlocks;
import com.hbm.config.CustomMachineConfigJSON;
import com.hbm.config.CustomMachineConfigJSON.MachineConfiguration;
@ -25,10 +26,10 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
public class CustomMachineHandler extends TemplateRecipeHandler {
public LinkedList<RecipeTransferRect> transferRectsRec = new LinkedList<RecipeTransferRect>();
public LinkedList<Class<? extends GuiContainer>> guiRec = new LinkedList<Class<? extends GuiContainer>>();
public MachineConfiguration conf;
@Override
@ -39,20 +40,25 @@ public class CustomMachineHandler extends TemplateRecipeHandler {
throw new RuntimeException(e);
}
}
public CustomMachineHandler(MachineConfiguration conf) {
super();
this.conf = conf;
loadTransferRects();
RecipeTransferRectHandler.registerRectsToGuis(getRecipeTransferRectGuis(), transferRects);
}
public class RecipeSet extends TemplateRecipeHandler.CachedRecipe {
List<PositionedStack> inputs = new ArrayList();
PositionedStack machine;
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) {
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 = 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) {
Pair<ItemStack, Float> pair = recipe.outputItems[i];
ItemStack out = pair.getKey().copy();
@ -69,7 +75,7 @@ public class CustomMachineHandler extends TemplateRecipeHandler {
}
outputs.add(new PositionedStack(out, 102 + i * 18, 24));
}
for(int i = 3; i < 6; i++) if(recipe.outputItems.length > i) {
Pair<ItemStack, Float> pair = recipe.outputItems[i];
ItemStack out = pair.getKey().copy();
@ -78,7 +84,13 @@ public class CustomMachineHandler extends TemplateRecipeHandler {
}
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);
}
@ -111,14 +123,14 @@ public class CustomMachineHandler extends TemplateRecipeHandler {
public String getGuiTexture() {
return RefStrings.MODID + ":textures/gui/nei/gui_nei_custom.png";
}
@Override
public void loadCraftingRecipes(String outputId, Object... results) {
if(outputId.equals("ntm_" + conf.unlocalizedName)) {
List<CustomMachineRecipe> recipes = CustomMachineRecipes.recipes.get(conf.recipeKey);
if(recipes != null) for(CustomMachineRecipe recipe : recipes) {
this.arecipes.add(new RecipeSet(recipe));
}
@ -126,25 +138,25 @@ public class CustomMachineHandler extends TemplateRecipeHandler {
super.loadCraftingRecipes(outputId, results);
}
}
@Override
public void loadCraftingRecipes(ItemStack result) {
List<CustomMachineRecipe> recipes = CustomMachineRecipes.recipes.get(conf.recipeKey);
if(recipes != null) outer:for(CustomMachineRecipe recipe : recipes) {
for(Pair<ItemStack, Float> stack : recipe.outputItems) {
if(NEIServerUtils.areStacksSameTypeCrafting(stack.getKey(), result)) {
this.arecipes.add(new RecipeSet(recipe));
continue outer;
}
}
for(FluidStack fluid : recipe.outputFluids) {
ItemStack drop = ItemFluidIcon.make(fluid);
if(compareFluidStacks(result, drop)) {
this.arecipes.add(new RecipeSet(recipe));
continue outer;
@ -152,28 +164,28 @@ public class CustomMachineHandler extends TemplateRecipeHandler {
}
}
}
@Override
public void loadUsageRecipes(String inputId, Object... ingredients) {
if(inputId.equals("ntm_" + conf.unlocalizedName)) {
loadCraftingRecipes("ntm_" + conf.unlocalizedName, new Object[0]);
} else {
super.loadUsageRecipes(inputId, ingredients);
}
}
@Override
public void loadUsageRecipes(ItemStack ingredient) {
List<CustomMachineRecipe> recipes = CustomMachineRecipes.recipes.get(conf.recipeKey);
if(recipes != null) outer:for(CustomMachineRecipe recipe : recipes) {
for(AStack stack : recipe.inputItems) {
List<ItemStack> stacks = stack.extractForNEI();
for(ItemStack sta : stacks) {
if(NEIServerUtils.areStacksSameTypeCrafting(ingredient, sta)) {
this.arecipes.add(new RecipeSet(recipe));
@ -181,10 +193,10 @@ public class CustomMachineHandler extends TemplateRecipeHandler {
}
}
}
for(FluidStack fluid : recipe.inputFluids) {
ItemStack drop = ItemFluidIcon.make(fluid);
if(compareFluidStacks(ingredient, drop)) {
this.arecipes.add(new RecipeSet(recipe));
continue outer;
@ -196,11 +208,32 @@ public class CustomMachineHandler extends TemplateRecipeHandler {
public static boolean compareFluidStacks(ItemStack sta1, ItemStack sta2) {
return sta1.getItem() == sta2.getItem() && sta1.getItemDamage() == sta2.getItemDamage();
}
@Override
public void loadTransferRects() {
if(this.conf == null) return;
transferRects.add(new RecipeTransferRect(new Rectangle(65, 23, 36, 18), "ntm_" + conf.unlocalizedName));
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;
import java.util.Arrays;
import java.util.Locale;
import com.hbm.render.util.GaugeUtil;
import org.lwjgl.opengl.GL11;
import com.hbm.inventory.SlotPattern;
@ -17,58 +19,59 @@ import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.ResourceLocation;
public class GUIMachineCustom extends GuiInfoContainer {
private static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/processing/gui_custom.png");
private TileEntityCustomMachine custom;
public GUIMachineCustom(InventoryPlayer invPlayer, TileEntityCustomMachine tedf) {
super(new ContainerMachineCustom(invPlayer, tedf));
custom = tedf;
this.xSize = 176;
this.ySize = 256;
}
@Override
public void drawScreen(int x, int y, float 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) {
for(int i = 0; i < this.inventorySlots.inventorySlots.size(); ++i) {
Slot slot = (Slot) this.inventorySlots.inventorySlots.get(i);
int tileIndex = slot.getSlotIndex();
if(this.isMouseOverSlot(slot, x, y) && slot instanceof SlotPattern && custom.matcher.modes[tileIndex - 10] != null) {
String label = EnumChatFormatting.YELLOW + "";
switch(custom.matcher.modes[tileIndex - 10]) {
case "exact": label += "Item and meta match"; break;
case "wildcard": label += "Item matches"; break;
default: label += "Ore dict key matches: " + custom.matcher.modes[tileIndex - 10]; break;
case "exact": label += "Item and meta match"; break;
case "wildcard": label += "Item matches"; 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);
}
}
}
for(int i = 0; i < custom.inputTanks.length; i++) {
custom.inputTanks[i].renderTankInfo(this, x, y, guiLeft + 8 + 18 * i, guiTop + 18, 16, 34);
}
for(int i = 0; i < custom.outputTanks.length; i++) {
custom.outputTanks[i].renderTankInfo(this, x, y, guiLeft + 78 + 18 * i, guiTop + 18, 16, 34);
}
}
@Override
protected void drawGuiContainerForegroundLayer(int i, int j) {
String name = this.custom.getInventoryName();
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);
if(custom.config.fluxMode) this.fontRendererObj.drawString("Flux:" + custom.flux,83, 57,0x08FF00);
}
@Override
@ -76,17 +79,23 @@ public class GUIMachineCustom extends GuiInfoContainer {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
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;
drawTexturedModalRect(guiLeft + 78, guiTop + 119, 192, 0, Math.min(p, 44), 16);
if(p > 44) {
p-= 44;
drawTexturedModalRect(guiLeft + 78 + 44, guiTop + 119, 192, 16, p, 16);
}
int e = (int) (custom.power * 52 / custom.config.maxPower);
drawTexturedModalRect(guiLeft + 150, guiTop + 70 - e, 176, 52 - e, 16, e);
for(int i = 0; i < 2; i++) {
for(int j = 0; j < 3; j++) {
int index = i * 3 + j;
@ -99,7 +108,7 @@ public class GUIMachineCustom extends GuiInfoContainer {
}
}
}
for(int i = 0; i < 3; i++) {
if(custom.config.fluidInCount <= i) {
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);
}
}
for(int i = 0; i < custom.inputTanks.length; i++) {
custom.inputTanks[i].renderTank(guiLeft + 8 + 18 * i, guiTop + 52, this.zLevel, 16, 34);
}
for(int i = 0; i < custom.outputTanks.length; i++) {
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;
public class CustomMachineRecipes extends SerializableRecipe {
public static HashMap<String, List<CustomMachineRecipe>> recipes = new HashMap();
@Override
public void registerDefaults() {
recipes.put("paperPress", new ArrayList() {{
CustomMachineRecipe recipe = new CustomMachineRecipe();
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.duration = 60;
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);
}});
}
@ -58,11 +65,11 @@ public class CustomMachineRecipes extends SerializableRecipe {
@Override
public void readRecipe(JsonElement recipe) {
JsonObject obj = recipe.getAsJsonObject();
String name = obj.get("recipeKey").getAsString();
List<CustomMachineRecipe> list = new ArrayList();
JsonArray array = obj.get("recipes").getAsJsonArray();
for(int i = 0; i < array.size(); i++) {
JsonObject rec = array.get(i).getAsJsonObject();
CustomMachineRecipe recipeInstance = new CustomMachineRecipe();
@ -72,56 +79,79 @@ public class CustomMachineRecipes extends SerializableRecipe {
recipeInstance.outputItems = this.readItemStackArrayChance(rec.get("outputItems").getAsJsonArray());
recipeInstance.duration = rec.get("duration").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);
}
recipes.put(name, list);
}
@Override
public void writeRecipe(Object recipe, JsonWriter writer) throws IOException {
Entry<String, List<CustomMachineRecipe>> entry = (Entry) recipe;
writer.name("recipeKey").value(entry.getKey());
writer.name("recipes").beginArray();
for(CustomMachineRecipe recipeInstance : entry.getValue()) {
writer.beginObject();
writer.name("inputFluids").beginArray();
for(FluidStack stack : recipeInstance.inputFluids) this.writeFluidStack(stack, writer);
writer.endArray();
writer.name("inputItems").beginArray();
for(AStack stack : recipeInstance.inputItems) this.writeAStack(stack, writer);
writer.endArray();
writer.name("outputFluids").beginArray();
for(FluidStack stack : recipeInstance.outputFluids) this.writeFluidStack(stack, writer);
writer.endArray();
writer.name("outputItems").beginArray();
for(Pair stack : recipeInstance.outputItems) this.writeItemStackChance(stack, writer);
writer.endArray();
writer.name("duration").value(recipeInstance.duration);
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.endArray();
}
public static class CustomMachineRecipe {
public FluidStack[] inputFluids;
public AStack[] inputItems;
public FluidStack[] outputFluids;
public Pair<ItemStack, Float>[] outputItems;
public int duration;
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, 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_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() {

View File

@ -3,9 +3,14 @@ package com.hbm.tileentity.machine;
import java.util.ArrayList;
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.MachineConfiguration;
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.fluid.Fluids;
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.module.ModulePatternMatcher;
import com.hbm.tileentity.IGUIProvider;
import com.hbm.tileentity.TileEntityMachineBase;
import com.hbm.tileentity.TileEntityMachinePolluting;
import com.hbm.tileentity.TileEntityProxyBase;
import com.hbm.util.Compat;
import com.hbm.util.fauxpointtwelve.BlockPos;
@ -35,12 +40,15 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
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 MachineConfiguration config;
public long power;
public int flux;
public int heat;
public int maxHeat;
public int progress;
public int maxProgress = 1;
public FluidTank[] inputTanks;
@ -49,8 +57,10 @@ public class TileEntityCustomMachine extends TileEntityMachineBase implements IF
public int structureCheckDelay;
public boolean structureOK = false;
public CustomMachineRecipe cachedRecipe;
public List<DirPos> connectionPos = new ArrayList();
public List<DirPos> fluxPos = new ArrayList();
public List<DirPos> heatPos = new ArrayList();
public TileEntityCustomMachine() {
/*
@ -60,22 +70,26 @@ public class TileEntityCustomMachine extends TileEntityMachineBase implements IF
* 10-15: Template
* 16-21: Output
*/
super(22);
super(22, 100);
}
public void init() {
MachineConfiguration config = CustomMachineConfigJSON.customMachines.get(this.machineType);
if(config != null) {
if (config != null) {
this.config = config;
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];
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);
smoke.changeTankSize(config.maxPollutionCap);
smoke_leaded.changeTankSize(config.maxPollutionCap);
smoke_poison.changeTankSize(config.maxPollutionCap);
} else {
worldObj.func_147480_a(xCoord, yCoord, zCoord, false);
}
@ -88,75 +102,112 @@ public class TileEntityCustomMachine extends TileEntityMachineBase implements IF
@Override
public void updateEntity() {
if(!worldObj.isRemote) {
if(config == null) {
if (!worldObj.isRemote) {
if (config == null) {
worldObj.func_147480_a(xCoord, yCoord, zCoord, false);
return;
}
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 > 1) this.inputTanks[1].setType(2, slots);
if(this.inputTanks.length > 2) this.inputTanks[2].setType(3, 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 > 2) this.inputTanks[2].setType(3, slots);
this.structureCheckDelay--;
if(this.structureCheckDelay <= 0) this.checkStructure();
if(this.worldObj.getTotalWorldTime() % 20 == 0) {
for(DirPos pos : this.connectionPos) {
for(FluidTank tank : this.inputTanks) {
if (this.structureCheckDelay <= 0) this.checkStructure();
if (this.worldObj.getTotalWorldTime() % 20 == 0) {
for (DirPos pos : this.connectionPos) {
for (FluidTank tank : this.inputTanks) {
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) {
if(config.generatorMode && power > 0) 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());
for (DirPos pos : this.connectionPos) {
if (config.generatorMode && power > 0)
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(config.generatorMode) {
if(this.cachedRecipe == null) {
if (this.structureOK) {
if (config.generatorMode) {
if (this.cachedRecipe == null) {
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.useUpInput(recipe);
}
}
if(this.cachedRecipe != null) {
if (this.cachedRecipe != null) {
this.maxProgress = (int) Math.max(cachedRecipe.duration / this.config.recipeSpeedMult, 1);
int powerReq = (int) Math.max(cachedRecipe.consumptionPerTick * this.config.recipeConsumptionMult, 1);
this.progress++;
this.power += powerReq;
if(power > config.maxPower) power = config.maxPower;
if(progress >= this.maxProgress) {
this.heat -= cachedRecipe.heat;
if (power > config.maxPower) power = config.maxPower;
if (worldObj.getTotalWorldTime() % 20 == 0) {
pollution(cachedRecipe);
radiation(cachedRecipe);
}
if (progress >= this.maxProgress) {
this.progress = 0;
this.processRecipe(cachedRecipe);
this.cachedRecipe = null;
}
}
} else {
CustomMachineRecipe recipe = this.getMatchingRecipe();
if(recipe != null) {
if (recipe != null) {
this.maxProgress = (int) Math.max(recipe.duration / this.config.recipeSpeedMult, 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.power -= powerReq;
if(progress >= this.maxProgress) {
this.heat -= recipe.heat;
if (worldObj.getTotalWorldTime() % 20 == 0) {
pollution(recipe);
radiation(recipe);
}
if (progress >= this.maxProgress) {
this.progress = 0;
this.useUpInput(recipe);
this.processRecipe(recipe);
@ -169,89 +220,129 @@ public class TileEntityCustomMachine extends TileEntityMachineBase implements IF
} else {
this.progress = 0;
}
NBTTagCompound data = new NBTTagCompound();
data.setString("type", this.machineType);
data.setLong("power", power);
data.setBoolean("structureOK", structureOK);
data.setInteger("flux", flux);
data.setInteger("heat", heat);
data.setInteger("progress", progress);
data.setInteger("maxProgress", maxProgress);
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 < inputTanks.length; i++) inputTanks[i].writeToNBT(data, "i" + i);
for (int i = 0; i < outputTanks.length; i++) outputTanks[i].writeToNBT(data, "o" + i);
this.matcher.writeToNBT(data);
this.networkPack(data, 50);
}
}
/** Only accepts inputs in a fixed order, saves a ton of performance because there's no permutations to check for */
public CustomMachineRecipe getMatchingRecipe() {
List<CustomMachineRecipe> recipes = CustomMachineRecipes.recipes.get(this.config.recipeKey);
if(recipes == null || recipes.isEmpty()) return null;
outer:
for(CustomMachineRecipe recipe : recipes) {
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;
}
for(int i = 0; i < recipe.inputItems.length; i++) {
if(recipe.inputItems[i] != null && slots[i + 4] == null) continue outer;
if(!recipe.inputItems[i].matchesRecipe(slots[i + 4], true)) continue outer;
}
return recipe;
}
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) {
for(int i = 0; i < recipe.inputFluids.length; i++) {
if(this.inputTanks[i].getFill() < recipe.inputFluids[i].fill) return false;
}
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(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;
}
public boolean hasSpace(CustomMachineRecipe recipe) {
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;
}
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[16 + i].stackSize + recipe.outputItems[i].key.stackSize > slots[i + 16].getMaxStackSize()) return false;
}
return true;
}
public void useUpInput(CustomMachineRecipe recipe) {
for(int i = 0; i < recipe.inputFluids.length; i++) {
this.inputTanks[i].setFill(this.inputTanks[i].getFill() - recipe.inputFluids[i].fill);
}
for(int i = 0; i < recipe.inputItems.length; i++) {
this.decrStackSize(i + 4, recipe.inputItems[i].stacksize);
}
}
public void processRecipe(CustomMachineRecipe recipe) {
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);
this.outputTanks[i].setFill(this.outputTanks[i].getFill() + recipe.outputFluids[i].fill);
}
for(int i = 0; i < recipe.outputItems.length; i++) {
if(worldObj.rand.nextFloat() < recipe.outputItems[i].value) {
if(slots[i + 16] == null) {
slots[i + 16] = recipe.outputItems[i].key.copy();
@ -261,19 +352,18 @@ public class TileEntityCustomMachine extends TileEntityMachineBase implements IF
}
}
}
public boolean checkStructure() {
this.connectionPos.clear();
this.structureCheckDelay = 300;
this.structureOK = false;
if(this.config == null) return false;
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata());
ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
for(ComponentDefinition comp : config.components) {
/* vvv precisely the same method used for defining ports vvv */
int x = xCoord - dir.offsetX * comp.x + rot.offsetX * comp.x;
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;
}
/* i wholeheartedly believe it is the computer who is wrong here */
Block b = worldObj.getBlock(x, y, z);
if(b != comp.block) return false;
int meta = worldObj.getBlockMetadata(x, y, z);
if(!comp.allowedMetas.contains(meta)) return false;
TileEntity tile = Compat.getTileStandard(worldObj, x, y, z);
if(tile instanceof TileEntityProxyBase) {
TileEntityProxyBase proxy = (TileEntityProxyBase) tile;
proxy.cachedPosition = new BlockPos(xCoord, yCoord, zCoord);
proxy.markDirty();
for(ForgeDirection facing : ForgeDirection.VALID_DIRECTIONS) {
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) {
this.connectionPos.add(new DirPos(xCoord + facing.offsetX, yCoord + facing.offsetY, zCoord + facing.offsetZ, facing));
}
this.structureOK = true;
return true;
}
public void buildStructure() {
if(this.config == null) return;
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata());
ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
for(ComponentDefinition comp : config.components) {
int x = xCoord - dir.offsetX * comp.x + rot.offsetX * comp.x;
int y = yCoord + comp.y;
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;
z = zCoord + dir.offsetX * comp.x - rot.offsetX * comp.x;
}
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
public boolean isItemValidForSlot(int slot, ItemStack stack) {
if(slot < 4 || slot > 9) return false;
int index = slot - 4;
int filterSlot = slot + 6;
if(slots[filterSlot] == null) return true;
return matcher.isValidForFilter(slots[filterSlot], index, stack);
}
@ -366,56 +466,58 @@ public class TileEntityCustomMachine extends TileEntityMachineBase implements IF
public void networkUnpack(NBTTagCompound nbt) {
this.machineType = nbt.getString("type");
if(this.config == null) this.init();
this.power = nbt.getLong("power");
this.progress = nbt.getInteger("progress");
this.flux = nbt.getInteger("flux");
this.heat = nbt.getInteger("heat");
this.structureOK = nbt.getBoolean("structureOK");
this.maxProgress = nbt.getInteger("maxProgress");
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);
this.matcher.readFromNBT(nbt);
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
this.machineType = nbt.getString("machineType");
this.init();
super.readFromNBT(nbt);
if(this.config != null) {
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);
this.matcher.readFromNBT(nbt);
int index = nbt.getInteger("cachedIndex");
if(index != -1) {
this.cachedRecipe = CustomMachineRecipes.recipes.get(this.config.recipeKey).get(index);
}
}
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
if(machineType == null || this.config == null) {
super.writeToNBT(nbt);
return;
}
nbt.setString("machineType", machineType);
super.writeToNBT(nbt);
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);
this.matcher.writeToNBT(nbt);
if(this.cachedRecipe != null) {
int index = CustomMachineRecipes.recipes.get(this.config.recipeKey).indexOf(this.cachedRecipe);
nbt.setInteger("cachedIndex", index);
@ -426,18 +528,22 @@ public class TileEntityCustomMachine extends TileEntityMachineBase implements IF
@Override
public FluidTank[] getAllTanks() {
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 < outputTanks.length; i++) all[inputTanks.length + i] = outputTanks[i];
return all;
}
@Override
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
@ -472,20 +578,20 @@ public class TileEntityCustomMachine extends TileEntityMachineBase implements IF
public void setPower(long power) {
this.power = power;
}
@Override
public long transferPower(long power) {
if(this.config != null && this.config.generatorMode) return power;
this.setPower(this.getPower() + power);
if(this.getPower() > this.getMaxPower()) {
long overshoot = this.getPower() - this.getMaxPower();
this.setPower(this.getMaxPower());
return overshoot;
}
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.desh.name=Desh 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.desh.name=Desh 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