updated some petrochemistry recipe handling

This commit is contained in:
Boblet 2022-02-07 11:01:33 +01:00
parent 1541eedd37
commit 274262436d
15 changed files with 243 additions and 308 deletions

View File

@ -82,6 +82,7 @@ public class SmeltingRecipes {
GameRegistry.addSmelting(ModItems.powder_lithium, new ItemStack(ModItems.lithium), 1.0F);
GameRegistry.addSmelting(ModItems.powder_dura_steel, new ItemStack(ModItems.ingot_dura_steel), 1.0F);
GameRegistry.addSmelting(ModItems.powder_polymer, new ItemStack(ModItems.ingot_polymer), 1.0F);
GameRegistry.addSmelting(ModItems.powder_bakelite, new ItemStack(ModItems.ingot_bakelite), 1.0F);
GameRegistry.addSmelting(ModItems.powder_lanthanium, new ItemStack(ModItems.ingot_lanthanium), 1.0F);
GameRegistry.addSmelting(ModItems.powder_actinium, new ItemStack(ModItems.ingot_actinium), 1.0F);
GameRegistry.addSmelting(ModItems.powder_boron, new ItemStack(ModItems.ingot_boron), 1.0F);

View File

@ -11,4 +11,9 @@ public class FluidStack {
this.fill = fill;
this.type = type;
}
public FluidStack(FluidType type, int fill) {
this.fill = fill;
this.type = type;
}
}

View File

@ -14,7 +14,7 @@ import net.minecraft.util.ResourceLocation;
public class GUIMachineRefinery extends GuiInfoContainer {
private static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/gui_refinery.png");
private static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/processing/gui_refinery.png");
private TileEntityMachineRefinery refinery;
public GUIMachineRefinery(InventoryPlayer invPlayer, TileEntityMachineRefinery tedf) {

View File

@ -9,6 +9,7 @@ import com.hbm.inventory.FluidStack;
import com.hbm.inventory.RecipesCommon.ComparableStack;
import com.hbm.inventory.RecipesCommon.OreDictStack;
import com.hbm.inventory.fluid.Fluids;
import com.hbm.items.ModItems;
import com.hbm.items.machine.ItemFluidIcon;
import net.minecraft.init.Blocks;
@ -36,6 +37,9 @@ public class LiquefactionRecipes {
recipes.put(new ComparableStack(Blocks.snow), new FluidStack(500, Fluids.WATER));
recipes.put(new ComparableStack(Blocks.ice), new FluidStack(1000, Fluids.WATER));
recipes.put(new ComparableStack(Blocks.packed_ice), new FluidStack(1000, Fluids.WATER));
recipes.put(new ComparableStack(Items.sugar), new FluidStack(150, Fluids.ETHANOL));
recipes.put(new ComparableStack(ModItems.biomass), new FluidStack(250, Fluids.BIOGAS));
//TODO: more recipes as the crack oil derivatives are added
}

View File

@ -52,25 +52,14 @@ public class RadiolysisRecipes {
//automatically add cracking recipes to the radiolysis recipe list
//we want the numbers and types to stay consistent anyway and this will save us a lot of headache later on
Map<FluidType, Quartet<FluidType, FluidType, Integer, Integer>> cracking = RefineryRecipes.getCrackingRecipes();
Map<FluidType, Pair<FluidStack, FluidStack>> cracking = RefineryRecipes.getCrackingRecipes();
if(cracking.isEmpty()) {
throw new IllegalStateException("RefineryRecipes.getCrackingRecipes has yielded an empty map while registering the radiolysis recipes! Either the load order is broken or cracking recipes have been removed!");
}
for(Entry<FluidType, Quartet<FluidType, FluidType, Integer, Integer>> recipe : cracking.entrySet()) {
FluidType input = recipe.getKey();
FluidType out1 = recipe.getValue().getW();
FluidType out2 = recipe.getValue().getX();
int amount1 = recipe.getValue().getY();
int amount2 = recipe.getValue().getZ();
radiolysis.put(input,
new Pair(
new FluidStack(amount1, out1),
new FluidStack(amount2, out2)
)
);
for(Entry<FluidType, Pair<FluidStack, FluidStack>> recipe : cracking.entrySet()) {
radiolysis.put(recipe.getKey(), recipe.getValue());
}
}

View File

@ -2,14 +2,19 @@ package com.hbm.inventory.recipes;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import com.hbm.inventory.FluidStack;
import com.hbm.inventory.OreDictManager.DictFrame;
import com.hbm.inventory.fluid.FluidType;
import com.hbm.inventory.fluid.Fluids;
import com.hbm.items.ItemEnums.EnumTarType;
import com.hbm.items.ModItems;
import com.hbm.items.machine.ItemFluidIcon;
import com.hbm.util.ItemStackUtil;
import com.hbm.util.Tuple.Pair;
import com.hbm.util.Tuple.Quartet;
import com.hbm.util.Tuple.Quintet;
import net.minecraft.item.ItemStack;
@ -54,69 +59,75 @@ public class RefineryRecipes {
public static final int diesel_crack_petro = 30;
public static final int kero_crack_petro = 60;
//why didn't i use fluid stacks here? was there a reason?
private static Map<FluidType, Quartet<FluidType, FluidType, Integer, Integer>> fractions = new HashMap();
private static Map<FluidType, Quartet<FluidType, FluidType, Integer, Integer>> cracking = new HashMap();
private static Map<FluidType, Quintet<FluidStack, FluidStack, FluidStack, FluidStack, ItemStack>> refinery = new HashMap();
private static Map<FluidType, Pair<FluidStack, FluidStack>> fractions = new HashMap();
private static Map<FluidType, Pair<FluidStack, FluidStack>> cracking = new HashMap();
public static Map<Object, Object[]> getRefineryRecipe() {
Map<Object, Object[]> recipes = new HashMap<Object, Object[]>();
recipes.put(ItemFluidIcon.make(Fluids.HOTOIL, 1000),
new ItemStack[] {
ItemFluidIcon.make(Fluids.HEAVYOIL, oil_frac_heavy * 10),
ItemFluidIcon.make(Fluids.NAPHTHA, oil_frac_naph * 10),
ItemFluidIcon.make(Fluids.LIGHTOIL, oil_frac_light * 10),
ItemFluidIcon.make(Fluids.PETROLEUM, oil_frac_petro * 10),
new ItemStack(ModItems.sulfur, 1) });
recipes.put(ItemFluidIcon.make(Fluids.HOTCRACKOIL, 1000),
new ItemStack[] {
ItemFluidIcon.make(Fluids.NAPHTHA_CRACK, crack_frac_naph * 10),
ItemFluidIcon.make(Fluids.LIGHTOIL_CRACK, crack_frac_light * 10),
ItemFluidIcon.make(Fluids.AROMATICS, crack_frac_aroma * 10),
ItemFluidIcon.make(Fluids.UNSATURATEDS, crack_frac_unsat * 10),
DictFrame.fromOne(ModItems.oil_tar, EnumTarType.CRACK) });
/*recipes.put(ItemFluidIcon.make(Fluids.HOTCRACKOIL, 1000),
new ItemStack[] {
ItemFluidIcon.make(Fluids.NAPHTHA_CRACK, oil_frac_heavy * 10), //fractionates into crack diesel and heating oil
ItemFluidIcon.make(Fluids.LIGHTOIL_CRACK, oil_frac_naph * 10), //fractionates into kerosene and petroleum
ItemFluidIcon.make(Fluids.AROMATICS, oil_frac_light * 10), //used for making bakelite and TNT
ItemFluidIcon.make(Fluids.UNSATURATEDS, oil_frac_petro * 10), //for bakelite and perhaps acetylene torches
DictFrame.fromOne(ModItems.coke, EnumCokeType.PETROLEUM) });*/
for(Entry<FluidType, Quintet<FluidStack, FluidStack, FluidStack, FluidStack, ItemStack>> recipe : refinery.entrySet()) {
Quintet<FluidStack, FluidStack, FluidStack, FluidStack, ItemStack> fluids = recipe.getValue();
recipes.put(ItemFluidIcon.make(recipe.getKey(), 1000),
new ItemStack[] {
ItemFluidIcon.make(fluids.getV().type, fluids.getV().fill * 10),
ItemFluidIcon.make(fluids.getW().type, fluids.getW().fill * 10),
ItemFluidIcon.make(fluids.getX().type, fluids.getX().fill * 10),
ItemFluidIcon.make(fluids.getY().type, fluids.getY().fill * 10),
ItemStackUtil.carefulCopy(fluids.getZ()) });
}
return recipes;
}
public static void registerRefinery() {
refinery.put(Fluids.HOTOIL, new Quintet(
new FluidStack(Fluids.HEAVYOIL, oil_frac_heavy),
new FluidStack(Fluids.NAPHTHA, oil_frac_naph),
new FluidStack(Fluids.LIGHTOIL, oil_frac_light),
new FluidStack(Fluids.PETROLEUM, oil_frac_petro),
new ItemStack(ModItems.sulfur)
));
refinery.put(Fluids.HOTCRACKOIL, new Quintet(
new FluidStack(Fluids.NAPHTHA_CRACK, crack_frac_naph),
new FluidStack(Fluids.LIGHTOIL_CRACK, crack_frac_light),
new FluidStack(Fluids.AROMATICS, crack_frac_aroma),
new FluidStack(Fluids.UNSATURATEDS, crack_frac_unsat),
DictFrame.fromOne(ModItems.oil_tar, EnumTarType.CRACK)
));
}
public static void registerFractions() {
fractions.put(Fluids.HEAVYOIL, new Quartet(Fluids.BITUMEN, Fluids.SMEAR, heavy_frac_bitu, heavy_frac_smear));
fractions.put(Fluids.SMEAR, new Quartet(Fluids.HEATINGOIL, Fluids.LUBRICANT, smear_frac_heat, smear_frac_lube));
fractions.put(Fluids.NAPHTHA, new Quartet(Fluids.HEATINGOIL, Fluids.DIESEL, napht_frac_heat, napht_frac_diesel));
fractions.put(Fluids.NAPHTHA_CRACK, new Quartet(Fluids.HEATINGOIL, Fluids.DIESEL_CRACK, ncrack_frac_heat, ncrack_frac_diesel));
fractions.put(Fluids.LIGHTOIL, new Quartet(Fluids.DIESEL, Fluids.KEROSENE, light_frac_diesel, light_frac_kero));
fractions.put(Fluids.LIGHTOIL_CRACK, new Quartet(Fluids.KEROSENE, Fluids.PETROLEUM, lcrack_frac_kero, lcrack_frac_petro));
fractions.put(Fluids.COALOIL, new Quartet(Fluids.COALGAS, Fluids.GAS, coal_frac_coalgas, coal_frac_natgas));
fractions.put(Fluids.HEAVYOIL, new Pair(new FluidStack(Fluids.BITUMEN, heavy_frac_bitu), new FluidStack(Fluids.SMEAR, heavy_frac_smear)));
fractions.put(Fluids.SMEAR, new Pair(new FluidStack(Fluids.HEATINGOIL, smear_frac_heat), new FluidStack(Fluids.LUBRICANT, smear_frac_lube)));
fractions.put(Fluids.NAPHTHA, new Pair(new FluidStack(Fluids.HEATINGOIL, napht_frac_heat), new FluidStack(Fluids.DIESEL, napht_frac_diesel)));
fractions.put(Fluids.NAPHTHA_CRACK, new Pair(new FluidStack(Fluids.HEATINGOIL, ncrack_frac_heat), new FluidStack(Fluids.DIESEL_CRACK, ncrack_frac_diesel)));
fractions.put(Fluids.LIGHTOIL, new Pair(new FluidStack(Fluids.DIESEL, light_frac_diesel), new FluidStack(Fluids.KEROSENE, light_frac_kero)));
fractions.put(Fluids.LIGHTOIL_CRACK, new Pair(new FluidStack(Fluids.KEROSENE, lcrack_frac_kero), new FluidStack(Fluids.PETROLEUM, lcrack_frac_petro)));
fractions.put(Fluids.COALOIL, new Pair(new FluidStack(Fluids.COALGAS, coal_frac_coalgas), new FluidStack(Fluids.GAS, coal_frac_natgas)));
}
public static void registerCracking() {
cracking.put(Fluids.OIL, new Quartet(Fluids.CRACKOIL, Fluids.PETROLEUM, oil_crack_oil, oil_crack_petro));
cracking.put(Fluids.BITUMEN, new Quartet(Fluids.OIL, Fluids.AROMATICS, bitumen_crack_oil, bitumen_crack_aroma));
cracking.put(Fluids.SMEAR, new Quartet(Fluids.NAPHTHA, Fluids.PETROLEUM, smear_crack_napht, smear_crack_petro));
cracking.put(Fluids.GAS, new Quartet(Fluids.PETROLEUM, Fluids.UNSATURATEDS, gas_crack_petro, gas_crack_unsat));
cracking.put(Fluids.DIESEL, new Quartet(Fluids.KEROSENE, Fluids.PETROLEUM, diesel_crack_kero, diesel_crack_petro));
cracking.put(Fluids.KEROSENE, new Quartet(Fluids.PETROLEUM, Fluids.NONE, kero_crack_petro, 0));
cracking.put(Fluids.OIL, new Pair(new FluidStack(Fluids.CRACKOIL, oil_crack_oil), new FluidStack(Fluids.PETROLEUM, oil_crack_petro)));
cracking.put(Fluids.BITUMEN, new Pair(new FluidStack(Fluids.OIL, bitumen_crack_oil), new FluidStack(Fluids.AROMATICS, bitumen_crack_aroma)));
cracking.put(Fluids.SMEAR, new Pair(new FluidStack(Fluids.NAPHTHA, smear_crack_napht), new FluidStack(Fluids.PETROLEUM, smear_crack_petro)));
cracking.put(Fluids.GAS, new Pair(new FluidStack(Fluids.PETROLEUM, gas_crack_petro), new FluidStack(Fluids.UNSATURATEDS, gas_crack_unsat)));
cracking.put(Fluids.DIESEL, new Pair(new FluidStack(Fluids.KEROSENE, diesel_crack_kero), new FluidStack(Fluids.PETROLEUM, diesel_crack_petro)));
cracking.put(Fluids.KEROSENE, new Pair(new FluidStack(Fluids.PETROLEUM, kero_crack_petro), new FluidStack(Fluids.NONE, 0)));
}
public static Quartet<FluidType, FluidType, Integer, Integer> getFractions(FluidType oil) {
public static Pair<FluidStack, FluidStack> getFractions(FluidType oil) {
return fractions.get(oil);
}
public static Quartet<FluidType, FluidType, Integer, Integer> getCracking(FluidType oil) {
public static Pair<FluidStack, FluidStack> getCracking(FluidType oil) {
return cracking.get(oil);
}
protected static Map<FluidType, Quartet<FluidType, FluidType, Integer, Integer>> getCrackingRecipes() {
protected static Map<FluidType, Pair<FluidStack, FluidStack>> getCrackingRecipes() {
return cracking;
}
}

View File

@ -51,6 +51,8 @@ public class SolidificationRecipes {
registerRecipe(WATER, 1000, Blocks.ice);
registerRecipe(LAVA, 1000, Blocks.obsidian);
registerRecipe(MERCURY, 125, ModItems.ingot_mercury);
registerRecipe(BIOGAS, 250, ModItems.biomass_compressed);
registerRecipe(OIL, SF_OIL, DictFrame.fromOne(ModItems.oil_tar, EnumTarType.CRUDE));
registerRecipe(CRACKOIL, SF_OIL, DictFrame.fromOne(ModItems.oil_tar, EnumTarType.CRACK));

View File

@ -664,13 +664,6 @@ public class Library {
return flag;
}
public static ItemStack carefulCopy(ItemStack stack) {
if(stack == null)
return null;
else
return stack.copy();
}
public static boolean isObstructed(World world, double x, double y, double z, double a, double b, double c) {
MovingObjectPosition pos = world.rayTraceBlocks(Vec3.createVectorHelper(x, y, z), Vec3.createVectorHelper(a, b, c));

View File

@ -7,6 +7,7 @@ import java.util.Random;
import com.hbm.interfaces.IFluidAcceptor;
import com.hbm.interfaces.IFluidContainer;
import com.hbm.interfaces.IFluidSource;
import com.hbm.interfaces.Spaghetti;
import com.hbm.inventory.FluidStack;
import com.hbm.inventory.FluidTank;
import com.hbm.inventory.UpgradeManager;
@ -22,6 +23,7 @@ import com.hbm.packet.AuxParticlePacket;
import com.hbm.packet.LoopedSoundPacket;
import com.hbm.packet.PacketDispatcher;
import com.hbm.packet.TEChemplantPacket;
import com.hbm.util.ItemStackUtil;
import api.hbm.energy.IBatteryItem;
import api.hbm.energy.IEnergyUser;
@ -580,34 +582,35 @@ public class TileEntityMachineChemplant extends TileEntity implements ISidedInve
tanks[1].setFill(tanks[1].getFill() - fluids[1].fill);
}
@Spaghetti("what the fuck am i looking at")
public boolean hasSpaceForItems(ItemStack[] stacks) {
if(stacks == null)
return true;
if(stacks != null && Library.isArrayEmpty(stacks))
return true;
ItemStack sta0 = Library.carefulCopy(slots[5]);
ItemStack sta0 = ItemStackUtil.carefulCopy(slots[5]);
if(sta0 != null)
sta0.stackSize = 1;
ItemStack sta1 = Library.carefulCopy(stacks[0]);
ItemStack sta1 = ItemStackUtil.carefulCopy(stacks[0]);
if(sta1 != null)
sta1.stackSize = 1;
ItemStack sta2 = Library.carefulCopy(slots[6]);
ItemStack sta2 = ItemStackUtil.carefulCopy(slots[6]);
if(sta2 != null)
sta2.stackSize = 1;
ItemStack sta3 = Library.carefulCopy(stacks[1]);
ItemStack sta3 = ItemStackUtil.carefulCopy(stacks[1]);
if(sta3 != null)
sta3.stackSize = 1;
ItemStack sta4 = Library.carefulCopy(slots[7]);
ItemStack sta4 = ItemStackUtil.carefulCopy(slots[7]);
if(sta4 != null)
sta4.stackSize = 1;
ItemStack sta5 = Library.carefulCopy(stacks[2]);
ItemStack sta5 = ItemStackUtil.carefulCopy(stacks[2]);
if(sta5 != null)
sta5.stackSize = 1;
ItemStack sta6 = Library.carefulCopy(slots[8]);
ItemStack sta6 = ItemStackUtil.carefulCopy(slots[8]);
if(sta6 != null)
sta6.stackSize = 1;
ItemStack sta7 = Library.carefulCopy(stacks[3]);
ItemStack sta7 = ItemStackUtil.carefulCopy(stacks[3]);
if(sta7 != null)
sta7.stackSize = 1;

View File

@ -7,11 +7,13 @@ import com.hbm.blocks.BlockDummyable;
import com.hbm.blocks.ModBlocks;
import com.hbm.interfaces.IFluidAcceptor;
import com.hbm.interfaces.IFluidSource;
import com.hbm.inventory.FluidStack;
import com.hbm.inventory.FluidTank;
import com.hbm.inventory.fluid.FluidType;
import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.recipes.RefineryRecipes;
import com.hbm.lib.Library;
import com.hbm.util.Tuple.Pair;
import com.hbm.util.Tuple.Quartet;
import cpw.mods.fml.relauncher.Side;
@ -56,12 +58,12 @@ public class TileEntityMachineCatalyticCracker extends TileEntity implements IFl
private void crack() {
Quartet<FluidType, FluidType, Integer, Integer> quart = RefineryRecipes.getCracking(tanks[0].getTankType());
Pair<FluidStack, FluidStack> quart = RefineryRecipes.getCracking(tanks[0].getTankType());
if(quart != null) {
int left = quart.getY();
int right = quart.getZ();
int left = quart.getKey().fill;
int right = quart.getValue().fill;
if(tanks[0].getFill() >= 100 && tanks[1].getFill() >= 100 && hasSpace(left, right)) {
tanks[0].setFill(tanks[0].getFill() - 100);
@ -78,12 +80,12 @@ public class TileEntityMachineCatalyticCracker extends TileEntity implements IFl
private void setupTanks() {
Quartet<FluidType, FluidType, Integer, Integer> quart = RefineryRecipes.getCracking(tanks[0].getTankType());
Pair<FluidStack, FluidStack> quart = RefineryRecipes.getCracking(tanks[0].getTankType());
if(quart != null) {
tanks[1].setTankType(Fluids.STEAM);
tanks[2].setTankType(quart.getW());
tanks[3].setTankType(quart.getX());
tanks[2].setTankType(quart.getKey().type);
tanks[3].setTankType(quart.getValue().type);
} else {
tanks[0].setTankType(Fluids.NONE);
tanks[1].setTankType(Fluids.NONE);
@ -182,19 +184,15 @@ public class TileEntityMachineCatalyticCracker extends TileEntity implements IFl
@Override
public List<IFluidAcceptor> getFluidList(FluidType type) {
if(type.name().equals(tanks[2].getTankType().name()))
return list1;
if(type.name().equals(tanks[3].getTankType().name()))
return list2;
if(type == tanks[2].getTankType()) return list1;
if(type == tanks[3].getTankType()) return list2;
return new ArrayList<IFluidAcceptor>();
}
@Override
public void clearFluidList(FluidType type) {
if(type.name().equals(tanks[2].getTankType().name()))
list1.clear();
if(type.name().equals(tanks[3].getTankType().name()))
list2.clear();
if(type == tanks[2].getTankType()) list1.clear();
if(type == tanks[3].getTankType()) list2.clear();
}
AxisAlignedBB bb = null;

View File

@ -5,11 +5,13 @@ import java.util.List;
import com.hbm.interfaces.IFluidAcceptor;
import com.hbm.interfaces.IFluidSource;
import com.hbm.inventory.FluidStack;
import com.hbm.inventory.FluidTank;
import com.hbm.inventory.fluid.FluidType;
import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.recipes.RefineryRecipes;
import com.hbm.lib.Library;
import com.hbm.util.Tuple.Pair;
import com.hbm.util.Tuple.Quartet;
import cpw.mods.fml.relauncher.Side;
@ -77,11 +79,11 @@ public class TileEntityMachineFractionTower extends TileEntity implements IFluid
private void setupTanks() {
Quartet<FluidType, FluidType, Integer, Integer> quart = RefineryRecipes.getFractions(tanks[0].getTankType());
Pair<FluidStack, FluidStack> quart = RefineryRecipes.getFractions(tanks[0].getTankType());
if(quart != null) {
tanks[1].setTankType(quart.getW());
tanks[2].setTankType(quart.getX());
tanks[1].setTankType(quart.getKey().type);
tanks[2].setTankType(quart.getValue().type);
} else {
tanks[0].setTankType(Fluids.NONE);
tanks[1].setTankType(Fluids.NONE);
@ -91,12 +93,12 @@ public class TileEntityMachineFractionTower extends TileEntity implements IFluid
private void fractionate() {
Quartet<FluidType, FluidType, Integer, Integer> quart = RefineryRecipes.getFractions(tanks[0].getTankType());
Pair<FluidStack, FluidStack> quart = RefineryRecipes.getFractions(tanks[0].getTankType());
if(quart != null) {
int left = quart.getY();
int right = quart.getZ();
int left = quart.getKey().fill;
int right = quart.getValue().fill;
if(tanks[0].getFill() >= 100 && hasSpace(left, right)) {
tanks[0].setFill(tanks[0].getFill() - 100);
@ -163,7 +165,7 @@ public class TileEntityMachineFractionTower extends TileEntity implements IFluid
@Override
public int getMaxFluidFill(FluidType type) {
if(type.name().equals(tanks[0].getTankType().name()))
if(type == tanks[0].getTankType())
return tanks[0].getMaxFill();
else
return 0;
@ -190,19 +192,15 @@ public class TileEntityMachineFractionTower extends TileEntity implements IFluid
@Override
public List<IFluidAcceptor> getFluidList(FluidType type) {
if(type.name().equals(tanks[1].getTankType().name()))
return list1;
if(type.name().equals(tanks[2].getTankType().name()))
return list2;
if(type == tanks[1].getTankType()) return list1;
if(type == tanks[2].getTankType()) return list2;
return new ArrayList<IFluidAcceptor>();
}
@Override
public void clearFluidList(FluidType type) {
if(type.name().equals(tanks[1].getTankType().name()))
list1.clear();
if(type.name().equals(tanks[2].getTankType().name()))
list2.clear();
if(type == tanks[1].getTankType()) list1.clear();
if(type == tanks[2].getTankType()) list2.clear();
}
AxisAlignedBB bb = null;

View File

@ -13,8 +13,8 @@ import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.recipes.RefineryRecipes;
import com.hbm.items.ModItems;
import com.hbm.lib.Library;
import com.hbm.packet.AuxElectricityPacket;
import com.hbm.packet.PacketDispatcher;
import com.hbm.tileentity.TileEntityMachineBase;
import api.hbm.energy.IBatteryItem;
import api.hbm.energy.IEnergyUser;
@ -29,29 +29,24 @@ import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
public class TileEntityMachineRefinery extends TileEntity implements ISidedInventory, IEnergyUser, IFluidContainer, IFluidAcceptor, IFluidSource {
private ItemStack slots[];
public class TileEntityMachineRefinery extends TileEntityMachineBase implements IEnergyUser, IFluidContainer, IFluidAcceptor, IFluidSource {
public long power = 0;
public int sulfur = 0;
public static final int maxSulfur = 100;
public static final long maxPower = 1000;
public int age = 0;
public FluidTank[] tanks;
public List<IFluidAcceptor> list1 = new ArrayList();
public List<IFluidAcceptor> list2 = new ArrayList();
public List<IFluidAcceptor> list3 = new ArrayList();
public List<IFluidAcceptor> list4 = new ArrayList();
private static final int[] slots_top = new int[] { 1 };
private static final int[] slots_bottom = new int[] { 0, 2, 4, 6, 8, 10, 11};
private static final int[] slots_side = new int[] { 0, 3, 5, 7, 9 };
private static final int[] slot_access = new int[] {11};
private String customName;
public TileEntityMachineRefinery() {
slots = new ItemStack[12];
super(12);
tanks = new FluidTank[5];
tanks[0] = new FluidTank(Fluids.HOTOIL, 64000, 0);
tanks[1] = new FluidTank(Fluids.HEAVYOIL, 16000, 1);
@ -61,117 +56,18 @@ public class TileEntityMachineRefinery extends TileEntity implements ISidedInven
}
@Override
public int getSizeInventory() {
return slots.length;
public String getName() {
return "container.machineRefinery";
}
@Override
public ItemStack getStackInSlot(int i) {
return slots[i];
}
@Override
public ItemStack getStackInSlotOnClosing(int i) {
if(slots[i] != null)
{
ItemStack itemStack = slots[i];
slots[i] = null;
return itemStack;
} else {
return null;
}
}
@Override
public void setInventorySlotContents(int i, ItemStack itemStack) {
slots[i] = itemStack;
if(itemStack != null && itemStack.stackSize > getInventoryStackLimit())
{
itemStack.stackSize = getInventoryStackLimit();
}
}
@Override
public String getInventoryName() {
return this.hasCustomInventoryName() ? this.customName : "container.machineRefinery";
}
@Override
public boolean hasCustomInventoryName() {
return this.customName != null && this.customName.length() > 0;
}
public void setCustomName(String name) {
this.customName = name;
}
@Override
public int getInventoryStackLimit() {
return 64;
}
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
if(worldObj.getTileEntity(xCoord, yCoord, zCoord) != this)
{
return false;
}else{
return player.getDistanceSq(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D) <=128;
}
}
@Override
public void openInventory() {}
@Override
public void closeInventory() {}
@Override
public boolean isItemValidForSlot(int i, ItemStack stack) {
if(i == 0 && stack.getItem() instanceof IBatteryItem)
return true;
if(i == 1 && FluidContainerRegistry.getFluidContent(stack, Fluids.HOTOIL) > 0)
return true;
if(stack.getItem() == ModItems.canister_empty) {
if(i == 3)
return true;
if(i == 5)
return true;
if(i == 7)
return true;
if(i == 9)
return true;
}
return false;
}
@Override
public ItemStack decrStackSize(int i, int j) {
if(slots[i] != null)
{
if(slots[i].stackSize <= j)
{
ItemStack itemStack = slots[i];
slots[i] = null;
return itemStack;
}
ItemStack itemStack1 = slots[i].splitStack(j);
if (slots[i].stackSize == 0)
{
slots[i] = null;
}
return itemStack1;
} else {
return null;
}
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
NBTTagList list = nbt.getTagList("items", 10);
power = nbt.getLong("power");
tanks[0].readFromNBT(nbt, "input");
@ -180,22 +76,12 @@ public class TileEntityMachineRefinery extends TileEntity implements ISidedInven
tanks[3].readFromNBT(nbt, "light");
tanks[4].readFromNBT(nbt, "petroleum");
sulfur = nbt.getInteger("sulfur");
slots = new ItemStack[getSizeInventory()];
for(int i = 0; i < list.tagCount(); i++)
{
NBTTagCompound nbt1 = list.getCompoundTagAt(i);
byte b0 = nbt1.getByte("slot");
if(b0 >= 0 && b0 < slots.length)
{
slots[b0] = ItemStack.loadItemStackFromNBT(nbt1);
}
}
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
nbt.setLong("power", power);
tanks[0].writeToNBT(nbt, "input");
tanks[1].writeToNBT(nbt, "heavy");
@ -203,26 +89,12 @@ public class TileEntityMachineRefinery extends TileEntity implements ISidedInven
tanks[3].writeToNBT(nbt, "light");
tanks[4].writeToNBT(nbt, "petroleum");
nbt.setInteger("sulfur", sulfur);
NBTTagList list = new NBTTagList();
for(int i = 0; i < slots.length; i++)
{
if(slots[i] != null)
{
NBTTagCompound nbt1 = new NBTTagCompound();
nbt1.setByte("slot", (byte)i);
slots[i].writeToNBT(nbt1);
list.appendTag(nbt1);
}
}
nbt.setTag("items", list);
}
@Override
public int[] getAccessibleSlotsFromSide(int p_94128_1_)
{
return p_94128_1_ == 0 ? slots_bottom : (p_94128_1_ == 1 ? slots_top : slots_side);
}
public int[] getAccessibleSlotsFromSide(int side) {
return slot_access;
}
@Override
public boolean canInsertItem(int i, ItemStack itemStack, int j) {
@ -231,41 +103,19 @@ public class TileEntityMachineRefinery extends TileEntity implements ISidedInven
@Override
public boolean canExtractItem(int i, ItemStack itemStack, int j) {
if(i == 0)
if (itemStack.getItem() instanceof IBatteryItem && ((IBatteryItem)itemStack.getItem()).getCharge(itemStack) == 0)
return true;
if(i == 2)
return true;
if(i == 4)
return true;
if(i == 6)
return true;
if(i == 8)
return true;
if(i == 10)
return true;
if(i == 11)
return true;
return false;
return i == 11;
}
@Override
public void updateEntity() {
if (!worldObj.isRemote) {
if(!worldObj.isRemote) {
this.updateConnections();
power = Library.chargeTEFromItems(slots, 0, power, maxPower);
age++;
if(age >= 20)
{
age = 0;
}
if(age == 9 || age == 19) {
if(worldObj.getTotalWorldTime() % 10 == 0) {
fillFluidInit(tanks[1].getTankType());
fillFluidInit(tanks[2].getTankType());
fillFluidInit(tanks[3].getTankType());
@ -312,10 +162,18 @@ public class TileEntityMachineRefinery extends TileEntity implements ISidedInven
sulfur -= maxSulfur;
}
}
PacketDispatcher.wrapper.sendToAllAround(new AuxElectricityPacket(xCoord, yCoord, zCoord, power), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 50));
NBTTagCompound data = new NBTTagCompound();
data.setLong("power", this.power);
this.networkPack(data, 50);
}
}
@Override
public void networkUnpack(NBTTagCompound nbt) {
this.power = nbt.getLong("power");
}
private void updateConnections() {
this.trySubscribe(worldObj, xCoord + 2, yCoord, zCoord + 1, Library.POS_X);
this.trySubscribe(worldObj, xCoord + 2, yCoord, zCoord - 1, Library.POS_X);
@ -368,71 +226,51 @@ public class TileEntityMachineRefinery extends TileEntity implements ISidedInven
@Override
public boolean getTact() {
if (age >= 0 && age < 10) {
return true;
}
return false;
return worldObj.getTotalWorldTime() % 20 < 10;
}
@Override
public int getFluidFill(FluidType type) {
if(type.name().equals(tanks[0].getTankType().name()))
return tanks[0].getFill();
else if(type.name().equals(tanks[1].getTankType().name()))
return tanks[1].getFill();
else if(type.name().equals(tanks[2].getTankType().name()))
return tanks[2].getFill();
else if(type.name().equals(tanks[3].getTankType().name()))
return tanks[3].getFill();
else if(type.name().equals(tanks[4].getTankType().name()))
return tanks[4].getFill();
for(int i = 0; i < 5; i++) {
if(type == tanks[i].getTankType()) {
return tanks[i].getFill();
}
}
return 0;
}
@Override
public void setFluidFill(int i, FluidType type) {
if(type.name().equals(tanks[0].getTankType().name()))
tanks[0].setFill(i);
else if(type.name().equals(tanks[1].getTankType().name()))
tanks[1].setFill(i);
else if(type.name().equals(tanks[2].getTankType().name()))
tanks[2].setFill(i);
else if(type.name().equals(tanks[3].getTankType().name()))
tanks[3].setFill(i);
else if(type.name().equals(tanks[4].getTankType().name()))
tanks[4].setFill(i);
public void setFluidFill(int fill, FluidType type) {
for(int i = 0; i < 5; i++) {
if(type == tanks[i].getTankType()) {
tanks[i].setFill(fill);
}
}
}
@Override
public List<IFluidAcceptor> getFluidList(FluidType type) {
if(type.name().equals(tanks[1].getTankType().name()))
return list1;
if(type.name().equals(tanks[2].getTankType().name()))
return list2;
if(type.name().equals(tanks[3].getTankType().name()))
return list3;
if(type.name().equals(tanks[4].getTankType().name()))
return list4;
if(type == tanks[1].getTankType()) return list1;
if(type == tanks[2].getTankType()) return list2;
if(type == tanks[3].getTankType()) return list3;
if(type == tanks[4].getTankType()) return list4;
return new ArrayList<IFluidAcceptor>();
}
@Override
public void clearFluidList(FluidType type) {
if(type.name().equals(tanks[1].getTankType().name()))
list1.clear();
if(type.name().equals(tanks[2].getTankType().name()))
list2.clear();
if(type.name().equals(tanks[3].getTankType().name()))
list3.clear();
if(type.name().equals(tanks[4].getTankType().name()))
list4.clear();
if(type == tanks[1].getTankType()) list1.clear();
if(type == tanks[2].getTankType()) list2.clear();
if(type == tanks[3].getTankType()) list3.clear();
if(type == tanks[4].getTankType()) list4.clear();
}
@Override
public int getMaxFluidFill(FluidType type) {
if(type.name().equals(tanks[0].getTankType().name()))
if(type == tanks[0].getTankType())
return tanks[0].getMaxFill();
else
return 0;

View File

@ -7,6 +7,13 @@ import net.minecraft.nbt.NBTTagString;
import net.minecraft.util.EnumChatFormatting;
public class ItemStackUtil {
public static ItemStack carefulCopy(ItemStack stack) {
if(stack == null)
return null;
else
return stack.copy();
}
/**
* UNSAFE! Will ignore all existing display tags and override them! In its current state, only fit for items we know don't have any display tags!

View File

@ -195,4 +195,90 @@ public class Tuple {
return this.z;
}
}
public static class Quintet<V,W,X,Y,Z> {
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((v == null) ? 0 : v.hashCode());
result = prime * result + ((w == null) ? 0 : w.hashCode());
result = prime * result + ((x == null) ? 0 : x.hashCode());
result = prime * result + ((y == null) ? 0 : y.hashCode());
result = prime * result + ((z == null) ? 0 : z.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if(this == obj)
return true;
if(obj == null)
return false;
if(getClass() != obj.getClass())
return false;
Quintet other = (Quintet) obj;
if(v == null) {
if(other.v != null)
return false;
} else if(!v.equals(other.w))
return false;
if(w == null) {
if(other.w != null)
return false;
} else if(!w.equals(other.w))
return false;
if(x == null) {
if(other.x != null)
return false;
} else if(!x.equals(other.x))
return false;
if(y == null) {
if(other.y != null)
return false;
} else if(!y.equals(other.y))
return false;
if(z == null) {
if(other.z != null)
return false;
} else if(!z.equals(other.z))
return false;
return true;
}
V v;
W w;
X x;
Y y;
Z z;
public Quintet(V v, W w, X x, Y y, Z z) {
this.v = v;
this.w = w;
this.x = x;
this.y = y;
this.z = z;
}
public V getV() {
return this.v;
}
public W getW() {
return this.w;
}
public X getX() {
return this.x;
}
public Y getY() {
return this.y;
}
public Z getZ() {
return this.z;
}
}
}

View File

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB