Skip to content

Commit

Permalink
Primitive Water Pump (GregTechCE#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
serenibyss committed Jul 18, 2021
1 parent 51818b5 commit 45a48b6
Show file tree
Hide file tree
Showing 19 changed files with 402 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ public class MultiblockAbility<T> {
public static final MultiblockAbility<IEnergyContainer> INPUT_ENERGY = new MultiblockAbility<>();
public static final MultiblockAbility<IEnergyContainer> OUTPUT_ENERGY = new MultiblockAbility<>();

public static final MultiblockAbility<IFluidTank> PUMP_FLUID_HATCH = new MultiblockAbility<>();
}
2 changes: 2 additions & 0 deletions src/main/java/gregtech/api/render/Textures.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ public class Textures {
public static SimpleCubeRenderer TITANIUM_FIREBOX_ACTIVE = new SimpleCubeRenderer("casings/firebox/machine_casing_firebox_titanium_active");
public static SimpleCubeRenderer TUNGSTENSTEEL_FIREBOX = new SimpleCubeRenderer("casings/firebox/machine_casing_firebox_tungstensteel");
public static SimpleCubeRenderer TUNGSTENSTEEL_FIREBOX_ACTIVE = new SimpleCubeRenderer("casings/firebox/machine_casing_firebox_tungstensteel_active");
public static SimpleSidedCubeRenderer PRIMITIVE_PUMP = new SimpleSidedCubeRenderer("casings/pump_deck");
public static SimpleSidedCubeRenderer TESLA_COIL = new SimpleSidedCubeRenderer("casings/tesla_coil");
public static SimpleOrientedCubeRenderer CRAFTING_TABLE = new SimpleOrientedCubeRenderer("casings/crafting_table");
public static OrientedOverlayRenderer COAL_BOILER_OVERLAY = new OrientedOverlayRenderer("generators/boiler/coal", FRONT);
public static OrientedOverlayRenderer LAVA_BOILER_OVERLAY = new OrientedOverlayRenderer("generators/boiler/lava", FRONT);
public static OrientedOverlayRenderer SOLAR_BOILER_OVERLAY = new OrientedOverlayRenderer("generators/boiler/solar", TOP);
public static OrientedOverlayRenderer PRIMITIVE_PUMP_OVERLAY = new OrientedOverlayRenderer("multiblock/primitive_pump", FRONT);
public static OrientedOverlayRenderer PRIMITIVE_BLAST_FURNACE_OVERLAY = new OrientedOverlayRenderer("machines/primitive_blast_furnace", FRONT);
public static OrientedOverlayRenderer COKE_OVEN_OVERLAY = new OrientedOverlayRenderer("machines/coke_oven", FRONT);
public static OrientedOverlayRenderer MULTIBLOCK_WORKABLE_OVERLAY = new OrientedOverlayRenderer("machines/multiblock_workable", FRONT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static void register() {
public static IngotMaterial Indium = new IngotMaterial(48, "indium", 0x400080, METALLIC, 2, of(), 0, Elements.get("Indium"));
public static DustMaterial Iodine = new DustMaterial(49, "iodine", 0x2C344F, SHINY, 2, of(), 0, Elements.get("Iodine"));
public static IngotMaterial Iridium = new IngotMaterial(50, "iridium", 0xF0F0F5, DULL, 3, of(), GENERATE_ORE | EXT2_METAL | GENERATE_ORE | GENERATE_RING | GENERATE_ROTOR | GENERATE_DENSE, Elements.get("Iridium"), 7.0F, 3.0f, 2560, 2719);
public static IngotMaterial Iron = new IngotMaterial(51, "iron", 0xC8C8C8, METALLIC, 2, of(), EXT2_METAL | GENERATE_ORE | MORTAR_GRINDABLE | GENERATE_RING | GENERATE_DENSE | GENERATE_FRAME | GENERATE_LONG_ROD | GENERATE_PLASMA | EXCLUDE_BLOCK_CRAFTING_BY_HAND_RECIPES, Elements.get("Iron"), 7.0F, 2.5f, 256);
public static IngotMaterial Iron = new IngotMaterial(51, "iron", 0xC8C8C8, METALLIC, 2, of(), EXT2_METAL | GENERATE_ORE | MORTAR_GRINDABLE | GENERATE_RING | GENERATE_DENSE | GENERATE_FRAME | GENERATE_LONG_ROD | GENERATE_ROTOR | GENERATE_PLASMA | EXCLUDE_BLOCK_CRAFTING_BY_HAND_RECIPES, Elements.get("Iron"), 7.0F, 2.5f, 256);
public static FluidMaterial Krypton = new FluidMaterial(52, "krypton", 0x31C42F, FLUID, of(), 0, Elements.get("Krypton"));
public static IngotMaterial Lanthanum = new IngotMaterial(53, "lanthanum", 0xFFFFFF, METALLIC, 2, of(), 0, Elements.get("Lanthanum"), 1193);
public static IngotMaterial Lawrencium = new IngotMaterial(54, "lawrencium", 0xFFFFFF, METALLIC, 3, of(), 0, Elements.get("Lawrencium"));
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/gregtech/common/blocks/BlockSteamCasing.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public boolean canCreatureSpawn(IBlockState state, IBlockAccess world, BlockPos

@Override
public void addInformation(ItemStack stack, @Nullable World player, List<String> tooltip, ITooltipFlag advanced) {
if (getState(stack).ordinal() < 2) {
if (getState(stack).ordinal() == 4) {
super.addInformation(stack, player, tooltip, advanced);
} else if (getState(stack).ordinal() < 2) {
tooltip.add(I18n.format("tile.steam_casing.bronze.tooltip"));
} else {
tooltip.add(I18n.format("tile.steam_casing.steel.tooltip"));
Expand All @@ -49,7 +51,8 @@ public enum SteamCasingType implements IStringSerializable {
BRONZE_HULL("bronze_hull"),
BRONZE_BRICKS_HULL("bronze_bricks_hull"),
STEEL_HULL("steel_hull"),
STEEL_BRICKS_HULL("steel_bricks_hull");
STEEL_BRICKS_HULL("steel_bricks_hull"),
PUMP_DECK("pump_deck");

private final String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@
import gregtech.common.metatileentities.electric.multiblockpart.MetaTileEntityFluidHatch;
import gregtech.common.metatileentities.electric.multiblockpart.MetaTileEntityItemBus;
import gregtech.common.metatileentities.electric.multiblockpart.MetaTileEntityRotorHolder;
import gregtech.common.metatileentities.multi.MetaTileEntityCokeOven;
import gregtech.common.metatileentities.multi.MetaTileEntityCokeOvenHatch;
import gregtech.common.metatileentities.multi.MetaTileEntityLargeBoiler;
import gregtech.common.metatileentities.multi.*;
import gregtech.common.metatileentities.multi.MetaTileEntityLargeBoiler.BoilerType;
import gregtech.common.metatileentities.multi.MetaTileEntityPrimitiveBlastFurnace;
import gregtech.common.metatileentities.multi.electric.*;
import gregtech.common.metatileentities.multi.electric.generator.MetaTileEntityLargeCombustionEngine;
import gregtech.common.metatileentities.multi.electric.generator.MetaTileEntityLargeTurbine;
Expand Down Expand Up @@ -59,8 +56,8 @@ public class MetaTileEntities {
public static SteamAlloySmelter STEAM_ALLOY_SMELTER_BRONZE;
public static SteamAlloySmelter STEAM_ALLOY_SMELTER_STEEL;

//public static MetaTileEntityPumpHatch PUMP_OUTPUT_HATCH;
//public static MetaTileEntityWaterPump PRIMITIVE_WATER_PUMP;
public static MetaTileEntityPumpHatch PUMP_OUTPUT_HATCH;
public static MetaTileEntityPrimitiveWaterPump PRIMITIVE_WATER_PUMP;

//SIMPLE MACHINES SECTION
public static SimpleMachineMetaTileEntity[] ELECTRIC_FURNACE = new SimpleMachineMetaTileEntity[GTValues.V.length - 1];
Expand Down Expand Up @@ -680,8 +677,8 @@ public static void init() {
GregTechAPI.registerMetaTileEntity(1625, TESLA_COIL);
LOCKED_SAFE = GregTechAPI.registerMetaTileEntity(1626, new MetaTileEntityLockedSafe(gregtechId("locked_safe")));
WORKBENCH = GregTechAPI.registerMetaTileEntity(1627, new MetaTileEntityWorkbench(gregtechId("workbench")));
//PRIMITIVE_WATER_PUMP = GregTechAPI.registerMetaTileEntity(1628, new MetaTileEntityWaterPump(gregtechId("primitive_pump")));
//PUMP_OUTPUT_HATCH = GregTechAPI.registerMetaTileEntity(1629, new MetaTileEntityPumpHatch(gregtechId("pump_hatch")));
PRIMITIVE_WATER_PUMP = GregTechAPI.registerMetaTileEntity(1628, new MetaTileEntityPrimitiveWaterPump(gregtechId("primitive_water_pump")));
PUMP_OUTPUT_HATCH = GregTechAPI.registerMetaTileEntity(1629, new MetaTileEntityPumpHatch(gregtechId("pump_hatch")));

INFINITE_EMITTER = GregTechAPI.registerMetaTileEntity(1630, new MetaTileEntityInfiniteEmitter(gregtechId("infinite_emitter")));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
public class MetaTileEntityFluidHatch extends MetaTileEntityMultiblockPart implements IMultiblockAbilityPart<IFluidTank> {

private static final int INITIAL_INVENTORY_SIZE = 8000;
private ItemStackHandler containerInventory;
private FluidTank fluidTank;
private boolean isExportHatch;
private final ItemStackHandler containerInventory;
private final FluidTank fluidTank;
private final boolean isExportHatch;

public MetaTileEntityFluidHatch(ResourceLocation metaTileEntityId, int tier, boolean isExportHatch) {
super(metaTileEntityId, tier);
Expand All @@ -56,13 +56,15 @@ public MetaTileEntity createMetaTileEntity(MetaTileEntityHolder holder) {
public NBTTagCompound writeToNBT(NBTTagCompound data) {
super.writeToNBT(data);
data.setTag("ContainerInventory", containerInventory.serializeNBT());
//fluidTank.writeToNBT(data);
return data;
}

@Override
public void readFromNBT(NBTTagCompound data) {
super.readFromNBT(data);
this.containerInventory.deserializeNBT(data.getCompoundTag("ContainerInventory"));
containerInventory.deserializeNBT(data.getCompoundTag("ContainerInventory"));
//fluidTank.readFromNBT(data);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
package gregtech.common.metatileentities.multi;

import codechicken.lib.render.CCRenderState;
import codechicken.lib.render.pipeline.IVertexOperation;
import codechicken.lib.vec.Matrix4;
import gregtech.api.gui.ModularUI;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.MetaTileEntityHolder;
import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart;
import gregtech.api.metatileentity.multiblock.IMultiblockPart;
import gregtech.api.metatileentity.multiblock.MultiblockAbility;
import gregtech.api.metatileentity.multiblock.MultiblockControllerBase;
import gregtech.api.multiblock.BlockPattern;
import gregtech.api.multiblock.BlockWorldState;
import gregtech.api.multiblock.FactoryBlockPattern;
import gregtech.api.multiblock.PatternMatchContext;
import gregtech.api.render.ICubeRenderer;
import gregtech.api.render.OrientedOverlayRenderer;
import gregtech.api.render.Textures;
import gregtech.api.unification.material.Materials;
import gregtech.common.blocks.BlockSteamCasing;
import gregtech.common.blocks.MetaBlocks;
import gregtech.common.metatileentities.electric.multiblockpart.MetaTileEntityFluidHatch;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.biome.*;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.IFluidTank;

import javax.annotation.Nonnull;
import java.util.List;
import java.util.function.Predicate;

public class MetaTileEntityPrimitiveWaterPump extends MultiblockControllerBase {

private IFluidTank waterTank;
private int biomeModifier = 0;
private int hatchModifier = 0;

public MetaTileEntityPrimitiveWaterPump(ResourceLocation metaTileEntityId) {
super(metaTileEntityId);
resetTileAbilities();
}

@Override
public MetaTileEntity createMetaTileEntity(MetaTileEntityHolder holder) {
return new MetaTileEntityPrimitiveWaterPump(metaTileEntityId);
}

@Override
public void update() {
super.update();
if (getOffsetTimer() % 20 == 0 && !getWorld().isRemote && isStructureFormed()) {
if (biomeModifier == 0) {
biomeModifier = getAmountForBiome(getWorld().getBiome(getPos()));
}
waterTank.fill(Materials.Water.getFluid(biomeModifier * hatchModifier), true);
}
}

private static int getAmountForBiome(Biome biome) {
Class<? extends Biome> biomeClass = biome.getBiomeClass();
if (biomeClass == BiomeOcean.class || biomeClass == BiomeRiver.class) {
return 1000;
} else if (biomeClass == BiomeSwamp.class) {
return 800;
} else if (biomeClass == BiomeJungle.class) {
return 350;
} else if (biomeClass == BiomeSnow.class) {
return 300;
} else if (biomeClass == BiomePlains.class || biomeClass == BiomeForest.class) {
return 250;
} else if (biomeClass == BiomeTaiga.class) {
return 175;
} else if (biomeClass == BiomeBeach.class) {
return 170;
} else {
return 100;
}
}

@Override
protected ModularUI createUI(EntityPlayer entityPlayer) {
return null;
}

@Override
protected boolean openGUIOnRightClick() {
return false;
}

@Override
protected void updateFormedValid() {

}

@Override
protected void formStructure(PatternMatchContext context) {
super.formStructure(context);
initializeAbilities();
}

@Override
public void invalidateStructure() {
super.invalidateStructure();
resetTileAbilities();
}

private void initializeAbilities() {
List<IFluidTank> tanks = getAbilities(MultiblockAbility.PUMP_FLUID_HATCH);
if (tanks == null || tanks.size() == 0) {
tanks = getAbilities(MultiblockAbility.EXPORT_FLUIDS);
this.hatchModifier = tanks.get(0).getCapacity() == 8000 ? 2 : 4;
} else {
this.hatchModifier = 1;
}
this.waterTank = tanks.get(0);
}

private void resetTileAbilities() {
this.waterTank = new FluidTank(0);
}

@Override
protected BlockPattern createStructurePattern() {
return FactoryBlockPattern.start()
.aisle("XXXX", "**F*", "**F*")
.aisle("XXHX", "F**F", "FFFF")
.aisle("SXXX", "**F*", "**F*")
.where('S', selfPredicate())
.where('X', statePredicate(MetaBlocks.STEAM_CASING.getState(BlockSteamCasing.SteamCasingType.PUMP_DECK)))
.where('F', statePredicate(MetaBlocks.FRAMES.get(Materials.Wood).getBlockState().getBaseState()))
.where('H', hatchPredicate())
.where('*', (x) -> true)
.build();
}

private static Predicate<BlockWorldState> hatchPredicate() {
return tilePredicate((state, tile) -> {
if (tile instanceof IMultiblockAbilityPart<?>) {
IMultiblockAbilityPart<?> abilityPart = (IMultiblockAbilityPart<?>) tile;
if (abilityPart.getAbility() == MultiblockAbility.PUMP_FLUID_HATCH) return true;
if (abilityPart.getAbility() == MultiblockAbility.EXPORT_FLUIDS) {
return ((MetaTileEntityFluidHatch) tile).getTier() <= 1;
}
}
return false;
});
}

@Override
public ICubeRenderer getBaseTexture(IMultiblockPart sourcePart) {
return Textures.PRIMITIVE_PUMP;
}

@Nonnull
@Override
protected OrientedOverlayRenderer getFrontOverlay() {
return Textures.PRIMITIVE_PUMP_OVERLAY;
}

@Override
public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) {
super.renderMetaTileEntity(renderState, translation, pipeline);
this.getFrontOverlay().render(renderState, translation, pipeline, getFrontFacing(), true);
}
}
Loading

0 comments on commit 45a48b6

Please sign in to comment.