Merge pull request #1288 from FOlkvangrField/more-custom-machine-options

More custom machine options
This commit is contained in:
HbmMods 2024-01-31 09:25:03 +01:00 committed by GitHub
commit 85ba8dd587
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 460 additions and 217 deletions

View File

@ -887,6 +887,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;
@ -2045,6 +2047,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);
@ -3409,6 +3413,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

@ -66,9 +66,12 @@ 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");
@ -156,9 +159,21 @@ 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();
if(machineObject.get("maxPollutionCap")!=null) {
configuration.maxPollutionCap = machineObject.get("maxPollutionCap").getAsInt();
}
else configuration.maxPollutionCap = 0;
if(machineObject.get("fluxMode")!=null) {
configuration.fluxMode = machineObject.get("fluxMode").getAsBoolean();
}
else configuration.fluxMode = false;
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();
if(machineObject.get("maxHeat")!=null) {
configuration.maxHeat = machineObject.get("maxHeat").getAsInt();
}
else configuration.maxHeat = 0;
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();
@ -237,10 +252,13 @@ 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;

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;
@ -52,6 +53,11 @@ public class CustomMachineHandler extends TemplateRecipeHandler {
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) {
@ -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);
} }
@ -203,4 +215,25 @@ public class CustomMachineHandler extends TemplateRecipeHandler {
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;
@ -34,7 +36,7 @@ public class GUIMachineCustom extends GuiInfoContainer {
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);
@ -45,9 +47,9 @@ public class GUIMachineCustom extends GuiInfoContainer {
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);
@ -69,6 +71,7 @@ public class GUIMachineCustom extends GuiInfoContainer {
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,7 +79,13 @@ 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) {

View File

@ -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);
}}); }});
} }
@ -72,6 +79,33 @@ 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();
if(rec.get("pollutionMode")!=null) {
recipeInstance.pollutionMode = rec.get("pollutionMode").getAsBoolean();
recipeInstance.pollutionType = rec.get("pollutionType").getAsString();
recipeInstance.pollutionAmount = rec.get("pollutionAmount").getAsFloat();
}
else {
recipeInstance.pollutionMode = false;
recipeInstance.pollutionType = "";
recipeInstance.pollutionAmount = 0;
}
if(rec.get("radiationMode")!=null) {
recipeInstance.radiationMode = rec.get("radiationMode").getAsBoolean();
recipeInstance.radiationAmount = rec.get("radiationAmount").getAsFloat();
}
else {
recipeInstance.radiationMode = false;
recipeInstance.radiationAmount = 0;
}
if(rec.get("flux")!=null) {
recipeInstance.flux = rec.get("flux").getAsInt();
}
else recipeInstance.flux = 0;
if(rec.get("heat")!=null) {
recipeInstance.heat = rec.get("heat").getAsInt();
}
else recipeInstance.heat = 0;
list.add(recipeInstance); list.add(recipeInstance);
} }
@ -106,6 +140,13 @@ public class CustomMachineRecipes extends SerializableRecipe {
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();
} }
@ -122,6 +163,14 @@ public class CustomMachineRecipes extends SerializableRecipe {
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

@ -1183,6 +1183,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;
@ -51,6 +59,8 @@ public class TileEntityCustomMachine extends TileEntityMachineBase implements IF
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,21 +70,25 @@ 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);
@ -89,56 +103,89 @@ 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;
@ -148,15 +195,19 @@ public class TileEntityCustomMachine extends TileEntityMachineBase implements IF
} 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);
@ -174,13 +225,16 @@ public class TileEntityCustomMachine extends TileEntityMachineBase implements IF
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 */
@ -204,7 +258,43 @@ public class TileEntityCustomMachine extends TileEntityMachineBase implements IF
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++) {
@ -214,7 +304,8 @@ public class TileEntityCustomMachine extends TileEntityMachineBase implements IF
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;
} }
@ -271,7 +362,6 @@ public class TileEntityCustomMachine extends TileEntityMachineBase implements IF
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 */
@ -302,8 +392,18 @@ public class TileEntityCustomMachine extends TileEntityMachineBase implements IF
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));
} }
@ -371,6 +471,8 @@ public class TileEntityCustomMachine extends TileEntityMachineBase implements IF
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);
@ -439,7 +541,11 @@ public class TileEntityCustomMachine extends TileEntityMachineBase implements IF
@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

View File

@ -4726,6 +4726,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