mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
Merge pull request #1326 from MellowArpeggiation/siphon
Add fluid siphon
This commit is contained in:
commit
443e154e57
@ -134,6 +134,8 @@ public class ToolRecipes {
|
||||
CraftingManager.addRecipeAuto(new ItemStack(ModItems.pipette_boron, 1), new Object[] { " P", " B ", "B ", 'P', RUBBER.ingot(), 'B', ModBlocks.glass_boron});
|
||||
CraftingManager.addRecipeAuto(new ItemStack(ModItems.pipette_laboratory, 1), new Object[] { " C", " R ", "P ", 'C', ModItems.circuit_aluminium, 'R', RUBBER.ingot(), 'P', ModItems.pipette_boron });
|
||||
|
||||
CraftingManager.addRecipeAuto(new ItemStack(ModItems.siphon, 1), new Object[] { " GR", " GR", " G ", 'G', KEY_CLEARGLASS, 'R', ANY_RUBBER.ingot()});
|
||||
|
||||
CraftingManager.addRecipeAuto(new ItemStack(ModItems.mirror_tool), new Object[] { " A ", " IA", "I ", 'A', AL.ingot(), 'I', IRON.ingot() });
|
||||
CraftingManager.addRecipeAuto(new ItemStack(ModItems.rbmk_tool), new Object[] { " A ", " IA", "I ", 'A', PB.ingot(), 'I', IRON.ingot() });
|
||||
CraftingManager.addRecipeAuto(new ItemStack(ModItems.power_net_tool), new Object[] { "WRW", " I ", " B ", 'W', ModItems.wire_red_copper, 'R', REDSTONE.dust(), 'I', IRON.ingot(), 'B', ModItems.battery_su });
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.hbm.inventory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.hbm.blocks.ModBlocks;
|
||||
@ -18,8 +19,9 @@ import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
public class FluidContainerRegistry {
|
||||
|
||||
//TODO: somehow incorporate hashmaps into this
|
||||
//TODO: continue incorporating hashmaps into this
|
||||
public static List<FluidContainer> allContainers = new ArrayList<FluidContainer>();
|
||||
private static HashMap<FluidType, List<FluidContainer>> containerMap = new HashMap<FluidType, List<FluidContainer>>();
|
||||
|
||||
public static void register() {
|
||||
FluidContainerRegistry.registerContainer(new FluidContainer(new ItemStack(Items.water_bucket), new ItemStack(Items.bucket), Fluids.WATER, 1000));
|
||||
@ -88,6 +90,35 @@ public class FluidContainerRegistry {
|
||||
public static void registerContainer(FluidContainer con) {
|
||||
allContainers.add(con);
|
||||
OreDictionary.registerOre(con.type.getDict(con.content), con.fullContainer);
|
||||
|
||||
if (!containerMap.containsKey(con.type))
|
||||
containerMap.put(con.type, new ArrayList<FluidContainer>());
|
||||
|
||||
List<FluidContainer> items = containerMap.get(con.type);
|
||||
items.add(con);
|
||||
}
|
||||
|
||||
public static List<FluidContainer> getContainers(FluidType type) {
|
||||
return containerMap.get(type);
|
||||
}
|
||||
|
||||
public static FluidContainer getContainer(FluidType type, ItemStack stack) {
|
||||
if(stack == null)
|
||||
return null;
|
||||
|
||||
ItemStack sta = stack.copy();
|
||||
sta.stackSize = 1;
|
||||
|
||||
if (!containerMap.containsKey(type))
|
||||
return null;
|
||||
|
||||
for (FluidContainer container : getContainers(type)) {
|
||||
if (ItemStack.areItemStacksEqual(container.emptyContainer, sta) && ItemStack.areItemStackTagsEqual(container.emptyContainer, sta)) {
|
||||
return container;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int getFluidContent(ItemStack stack, FluidType type) {
|
||||
@ -97,11 +128,12 @@ public class FluidContainerRegistry {
|
||||
|
||||
ItemStack sta = stack.copy();
|
||||
sta.stackSize = 1;
|
||||
|
||||
if (!containerMap.containsKey(type))
|
||||
return 0;
|
||||
|
||||
for(FluidContainer container : allContainers) {
|
||||
if(container.type == type &&
|
||||
ItemStack.areItemStacksEqual(container.fullContainer, sta) &&
|
||||
ItemStack.areItemStackTagsEqual(container.fullContainer, sta))
|
||||
for(FluidContainer container : containerMap.get(type)) {
|
||||
if(ItemStack.areItemStacksEqual(container.fullContainer, sta) && ItemStack.areItemStackTagsEqual(container.fullContainer, sta))
|
||||
return container.content;
|
||||
}
|
||||
|
||||
@ -131,8 +163,11 @@ public class FluidContainerRegistry {
|
||||
ItemStack sta = stack.copy();
|
||||
sta.stackSize = 1;
|
||||
|
||||
for(FluidContainer container : allContainers) {
|
||||
if(ItemStack.areItemStacksEqual(container.emptyContainer, sta) && ItemStack.areItemStackTagsEqual(container.emptyContainer, sta) && container.type == type)
|
||||
if (!containerMap.containsKey(type))
|
||||
return null;
|
||||
|
||||
for(FluidContainer container : containerMap.get(type)) {
|
||||
if(ItemStack.areItemStacksEqual(container.emptyContainer, sta) && ItemStack.areItemStackTagsEqual(container.emptyContainer, sta))
|
||||
return container.fullContainer.copy();
|
||||
}
|
||||
|
||||
|
||||
@ -191,6 +191,7 @@ public class Fluids {
|
||||
public static final FT_NoID NOID = new FT_NoID();
|
||||
public static final FT_Delicious DELICIOUS = new FT_Delicious();
|
||||
public static final FT_Leaded LEADED = new FT_Leaded();
|
||||
public static final FT_Unsiphonable UNSIPHONABLE = new FT_Unsiphonable();
|
||||
|
||||
public static void init() {
|
||||
|
||||
@ -208,11 +209,11 @@ public class Fluids {
|
||||
*/
|
||||
|
||||
NONE = new FluidType("NONE", 0x888888, 0, 0, 0, EnumSymbol.NONE);
|
||||
WATER = new FluidType("WATER", 0x3333FF, 0, 0, 0, EnumSymbol.NONE).addTraits(LIQUID);
|
||||
STEAM = new FluidType("STEAM", 0xe5e5e5, 3, 0, 0, EnumSymbol.NONE).setTemp(100).addTraits(GASEOUS);
|
||||
HOTSTEAM = new FluidType("HOTSTEAM", 0xE7D6D6, 4, 0, 0, EnumSymbol.NONE).setTemp(300).addTraits(GASEOUS);
|
||||
SUPERHOTSTEAM = new FluidType("SUPERHOTSTEAM", 0xE7B7B7, 4, 0, 0, EnumSymbol.NONE).setTemp(450).addTraits(GASEOUS);
|
||||
ULTRAHOTSTEAM = new FluidType("ULTRAHOTSTEAM", 0xE39393, 4, 0, 0, EnumSymbol.NONE).setTemp(600).addTraits(GASEOUS);
|
||||
WATER = new FluidType("WATER", 0x3333FF, 0, 0, 0, EnumSymbol.NONE).addTraits(LIQUID, UNSIPHONABLE);
|
||||
STEAM = new FluidType("STEAM", 0xe5e5e5, 3, 0, 0, EnumSymbol.NONE).setTemp(100).addTraits(GASEOUS, UNSIPHONABLE);
|
||||
HOTSTEAM = new FluidType("HOTSTEAM", 0xE7D6D6, 4, 0, 0, EnumSymbol.NONE).setTemp(300).addTraits(GASEOUS, UNSIPHONABLE);
|
||||
SUPERHOTSTEAM = new FluidType("SUPERHOTSTEAM", 0xE7B7B7, 4, 0, 0, EnumSymbol.NONE).setTemp(450).addTraits(GASEOUS, UNSIPHONABLE);
|
||||
ULTRAHOTSTEAM = new FluidType("ULTRAHOTSTEAM", 0xE39393, 4, 0, 0, EnumSymbol.NONE).setTemp(600).addTraits(GASEOUS, UNSIPHONABLE);
|
||||
COOLANT = new FluidType("COOLANT", 0xd8fcff, 1, 0, 0, EnumSymbol.NONE).addTraits(LIQUID);
|
||||
LAVA = new FluidType("LAVA", 0xFF3300, 4, 0, 0, EnumSymbol.NOWATER).setTemp(1200).addTraits(LIQUID, VISCOUS);
|
||||
DEUTERIUM = new FluidType("DEUTERIUM", 0x0000FF, 3, 4, 0, EnumSymbol.NONE).addTraits(new FT_Flammable(5_000), new FT_Combustible(FuelGrade.HIGH, 10_000), GASEOUS);
|
||||
|
||||
@ -20,8 +20,6 @@ public class FluidLoaderStandard extends FluidLoadingHandler {
|
||||
|
||||
if(full != null && slots[in] != null && tank.getFill() - FluidContainerRegistry.getFluidContent(full, type) >= 0) {
|
||||
|
||||
ItemStack fullContainer = FluidContainerRegistry.getFullContainer(slots[in], type);
|
||||
|
||||
if(slots[out] == null) {
|
||||
|
||||
tank.setFill(tank.getFill() - FluidContainerRegistry.getFluidContent(full, type));
|
||||
@ -31,7 +29,7 @@ public class FluidLoaderStandard extends FluidLoadingHandler {
|
||||
slots[in] = null;
|
||||
}
|
||||
|
||||
} else if(slots[out] != null && slots[out].getItem() == fullContainer.getItem() && slots[out].getItemDamage() == fullContainer.getItemDamage() && slots[out].stackSize < slots[out].getMaxStackSize()) {
|
||||
} else if(slots[out] != null && slots[out].getItem() == full.getItem() && slots[out].getItemDamage() == full.getItemDamage() && slots[out].stackSize < slots[out].getMaxStackSize()) {
|
||||
|
||||
tank.setFill(tank.getFill() - FluidContainerRegistry.getFluidContent(full, type));
|
||||
slots[in].stackSize--;
|
||||
|
||||
@ -27,8 +27,8 @@ import net.minecraft.util.MathHelper;
|
||||
|
||||
public class FluidTank {
|
||||
|
||||
public static final List<FluidLoadingHandler> loadingHandlers = new ArrayList();
|
||||
public static final Set<Item> noDualUnload = new HashSet();
|
||||
public static final List<FluidLoadingHandler> loadingHandlers = new ArrayList<FluidLoadingHandler>();
|
||||
public static final Set<Item> noDualUnload = new HashSet<Item>();
|
||||
|
||||
static {
|
||||
loadingHandlers.add(new FluidLoaderStandard());
|
||||
|
||||
@ -38,6 +38,7 @@ public abstract class FluidTrait {
|
||||
traitNameMap.put("pheromone", FT_Pheromone.class);
|
||||
traitNameMap.put("noid", FT_NoID.class);
|
||||
traitNameMap.put("nocontainer", FT_NoContainer.class);
|
||||
traitNameMap.put("unsiphonable", FT_Unsiphonable.class);
|
||||
}
|
||||
|
||||
/** Important information that should always be displayed */
|
||||
|
||||
@ -62,6 +62,12 @@ public class FluidTraitSimple {
|
||||
}
|
||||
}
|
||||
|
||||
public static class FT_Unsiphonable extends FluidTrait {
|
||||
@Override public void addInfoHidden(List<String> info) {
|
||||
info.add(EnumChatFormatting.BLUE + "[Ignored by siphon]");
|
||||
}
|
||||
}
|
||||
|
||||
public static class FT_NoID extends FluidTrait { }
|
||||
public static class FT_NoContainer extends FluidTrait { }
|
||||
}
|
||||
|
||||
@ -942,6 +942,7 @@ public class ModItems {
|
||||
public static Item pipette;
|
||||
public static Item pipette_boron;
|
||||
public static Item pipette_laboratory;
|
||||
public static Item siphon;
|
||||
|
||||
public static Item disperser_canister_empty;
|
||||
public static Item disperser_canister;
|
||||
@ -4678,6 +4679,7 @@ public class ModItems {
|
||||
pipette = new ItemPipette().setUnlocalizedName("pipette").setMaxStackSize(1).setCreativeTab(MainRegistry.controlTab).setTextureName(RefStrings.MODID + ":pipette");
|
||||
pipette_boron = new ItemPipette().setUnlocalizedName("pipette_boron").setMaxStackSize(1).setCreativeTab(MainRegistry.controlTab).setTextureName(RefStrings.MODID + ":pipette_boron");
|
||||
pipette_laboratory = new ItemPipette().setUnlocalizedName("pipette_laboratory").setMaxStackSize(1).setCreativeTab(MainRegistry.controlTab).setTextureName(RefStrings.MODID + ":pipette_laboratory");
|
||||
siphon = new ItemFluidSiphon().setUnlocalizedName("siphon").setMaxStackSize(1).setCreativeTab(MainRegistry.controlTab).setTextureName(RefStrings.MODID + ":siphon");
|
||||
inf_water = new ItemInfiniteFluid(Fluids.WATER, 50).setUnlocalizedName("inf_water").setMaxStackSize(1).setCreativeTab(MainRegistry.controlTab).setTextureName(RefStrings.MODID + ":inf_water");
|
||||
inf_water_mk2 = new ItemInfiniteFluid(Fluids.WATER, 500).setUnlocalizedName("inf_water_mk2").setMaxStackSize(1).setCreativeTab(MainRegistry.controlTab).setTextureName(RefStrings.MODID + ":inf_water_mk2");
|
||||
|
||||
@ -6427,6 +6429,9 @@ public class ModItems {
|
||||
GameRegistry.registerItem(pipette_boron, pipette_boron.getUnlocalizedName());
|
||||
GameRegistry.registerItem(pipette_laboratory, pipette_laboratory.getUnlocalizedName());
|
||||
|
||||
//Siphon
|
||||
GameRegistry.registerItem(siphon, siphon.getUnlocalizedName());
|
||||
|
||||
//Disperser Canister
|
||||
GameRegistry.registerItem(disperser_canister_empty, disperser_canister_empty.getUnlocalizedName());
|
||||
GameRegistry.registerItem(disperser_canister, disperser_canister.getUnlocalizedName());
|
||||
|
||||
96
src/main/java/com/hbm/items/machine/ItemFluidSiphon.java
Normal file
96
src/main/java/com/hbm/items/machine/ItemFluidSiphon.java
Normal file
@ -0,0 +1,96 @@
|
||||
package com.hbm.items.machine;
|
||||
|
||||
import com.hbm.util.CompatExternal;
|
||||
|
||||
import com.hbm.inventory.FluidContainer;
|
||||
import com.hbm.inventory.FluidContainerRegistry;
|
||||
import com.hbm.inventory.fluid.FluidType;
|
||||
import com.hbm.inventory.fluid.tank.FluidTank;
|
||||
import com.hbm.inventory.fluid.trait.FluidTraitSimple.FT_Unsiphonable;
|
||||
import com.hbm.items.ModItems;
|
||||
import com.hbm.items.tool.ItemPipette;
|
||||
|
||||
import api.hbm.fluid.IFluidStandardReceiver;
|
||||
import api.hbm.fluid.IFluidStandardTransceiver;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemFluidSiphon extends Item {
|
||||
|
||||
@Override
|
||||
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int i, float f0, float f1, float f2) {
|
||||
TileEntity te = CompatExternal.getCoreFromPos(world, x, y, z);
|
||||
|
||||
if(te != null && (te instanceof IFluidStandardReceiver || te instanceof IFluidStandardTransceiver)) {
|
||||
FluidTank[] tanks;
|
||||
if (te instanceof IFluidStandardReceiver) {
|
||||
tanks = ((IFluidStandardReceiver) te).getReceivingTanks();
|
||||
} else {
|
||||
tanks = ((IFluidStandardTransceiver) te).getReceivingTanks();
|
||||
}
|
||||
|
||||
boolean hasDrainedTank = false;
|
||||
|
||||
// We need to iterate through the inventory for _each_ siphonable tank, so we can handle fluids that can only go into certain containers
|
||||
// After we successfully siphon any fluid from a tank, we stop further processing, multiple fluid types require multiple clicks
|
||||
for (FluidTank tank : tanks) {
|
||||
if (tank.getFill() <= 0) continue;
|
||||
|
||||
ItemStack availablePipette = null;
|
||||
FluidType tankType = tank.getTankType();
|
||||
|
||||
if (tankType.hasTrait(FT_Unsiphonable.class)) continue;
|
||||
|
||||
for (int j = 0; j < player.inventory.mainInventory.length; j++) {
|
||||
ItemStack inventoryStack = player.inventory.mainInventory[j];
|
||||
if (inventoryStack == null) continue;
|
||||
|
||||
FluidContainer container = FluidContainerRegistry.getContainer(tankType, inventoryStack);
|
||||
|
||||
if (availablePipette == null && inventoryStack.getItem() instanceof ItemPipette) {
|
||||
ItemPipette pipette = (ItemPipette) inventoryStack.getItem();
|
||||
if (!pipette.willFizzle(tankType) && pipette != ModItems.pipette_laboratory) { // Ignoring laboratory pipettes for now
|
||||
availablePipette = inventoryStack;
|
||||
}
|
||||
}
|
||||
|
||||
if (container == null) continue;
|
||||
|
||||
ItemStack full = FluidContainerRegistry.getFullContainer(inventoryStack, tankType);
|
||||
|
||||
while (tank.getFill() >= container.content && inventoryStack.stackSize > 0) {
|
||||
hasDrainedTank = true;
|
||||
|
||||
inventoryStack.stackSize--;
|
||||
if (inventoryStack.stackSize <= 0) {
|
||||
player.inventory.mainInventory[j] = null;
|
||||
}
|
||||
|
||||
ItemStack filledContainer = full.copy();
|
||||
tank.setFill(tank.getFill() - container.content);
|
||||
player.inventory.addItemStackToInventory(filledContainer);
|
||||
}
|
||||
}
|
||||
|
||||
// If the remainder of the tank can only fit into a pipette, fill a pipette with the remainder
|
||||
// Will not auto-fill fizzlable pipettes, there is no feedback for the fizzle in this case, and that's a touch too unfair
|
||||
if (availablePipette != null && tank.getFill() < 1000) {
|
||||
ItemPipette pipette = (ItemPipette) availablePipette.getItem();
|
||||
|
||||
if (pipette.acceptsFluid(tankType, availablePipette)) {
|
||||
hasDrainedTank = true;
|
||||
tank.setFill(pipette.tryFill(tankType, tank.getFill(), availablePipette));
|
||||
}
|
||||
}
|
||||
|
||||
if (hasDrainedTank) return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@ -133,15 +133,18 @@ public class ItemPipette extends Item implements IFillableItem {
|
||||
this.setFill(stack, type, (short) (this.getFill(stack) + toFill));
|
||||
|
||||
// fizzling checks
|
||||
if(this.getFill(stack) > 0 && (this.getType(stack).isCorrosive() && type != Fluids.ACID)) {
|
||||
if(this == ModItems.pipette) {
|
||||
stack.stackSize = 0;
|
||||
}
|
||||
if(this.getFill(stack) > 0 && willFizzle(type)) {
|
||||
stack.stackSize = 0;
|
||||
}
|
||||
|
||||
return amount - toFill;
|
||||
}
|
||||
|
||||
public boolean willFizzle(FluidType type) {
|
||||
if (this != ModItems.pipette) return false;
|
||||
return type.isCorrosive() && type != Fluids.ACID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean providesFluid(FluidType type, ItemStack stack) {
|
||||
return this.getType(stack) == type;
|
||||
|
||||
@ -3667,6 +3667,7 @@ item.power_net_tool.name=Cable Network Analysis Tool
|
||||
item.pipette.name=Pipette
|
||||
item.pipette_boron.name=Boron Pipette
|
||||
item.pipette_laboratory.name=Laboratory Grade Pipette
|
||||
item.siphon.name=Siphon
|
||||
item.primer_357.name=.357 Magnum Primer (x24)
|
||||
item.primer_44.name=.44 Magnum Primer (x24)
|
||||
item.primer_50.name=Large Caliber Primer (x12)
|
||||
|
||||
BIN
src/main/resources/assets/hbm/textures/items/siphon.png
Normal file
BIN
src/main/resources/assets/hbm/textures/items/siphon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.3 KiB |
Loading…
x
Reference in New Issue
Block a user