Some fluid stuff maybe...

This commit is contained in:
Flanks255 2021-10-24 11:03:33 -05:00
parent 8c1da19930
commit 93fdf5a674
6 changed files with 69 additions and 57 deletions

View file

@ -93,6 +93,7 @@ public class ActuallyAdditions {
MinecraftForge.EVENT_BUS.register(new CommonEvents()); MinecraftForge.EVENT_BUS.register(new CommonEvents());
MinecraftForge.EVENT_BUS.register(new DungeonLoot()); MinecraftForge.EVENT_BUS.register(new DungeonLoot());
MinecraftForge.EVENT_BUS.addListener(ActuallyAdditions::reloadEvent); MinecraftForge.EVENT_BUS.addListener(ActuallyAdditions::reloadEvent);
InitFluids.init(eventBus);
eventBus.addListener(this::setup); eventBus.addListener(this::setup);
eventBus.addListener(this::clientSetup); eventBus.addListener(this::clientSetup);
@ -109,7 +110,6 @@ public class ActuallyAdditions {
commonCapsLoaded = false; // Loader.isModLoaded("commoncapabilities"); commonCapsLoaded = false; // Loader.isModLoaded("commoncapabilities");
InitFluids.init();
new UpdateChecker(); new UpdateChecker();
BannerHelper.init(); BannerHelper.init();
InitEntities.init(); // todo: [port] replace InitEntities.init(); // todo: [port] replace

View file

@ -35,10 +35,10 @@ public final class InitCrafting {
int[] power = ConfigIntListValues.OIL_POWER.getValue(); int[] power = ConfigIntListValues.OIL_POWER.getValue();
int[] time = ConfigIntListValues.OIL_TIME.getValue(); int[] time = ConfigIntListValues.OIL_TIME.getValue();
ActuallyAdditionsAPI.addOilGenRecipe(InitFluids.fluidCanolaOil.getName(), power[0], time[0]); ActuallyAdditionsAPI.addOilGenRecipe(InitFluids.CANOLA_OIL.getName(), power[0], time[0]);
ActuallyAdditionsAPI.addOilGenRecipe(InitFluids.fluidRefinedCanolaOil.getName(), power[1], time[1]); ActuallyAdditionsAPI.addOilGenRecipe(InitFluids.REFINED_CANOLA_OIL.getName(), power[1], time[1]);
ActuallyAdditionsAPI.addOilGenRecipe(InitFluids.fluidCrystalOil.getName(), power[2], time[2]); ActuallyAdditionsAPI.addOilGenRecipe(InitFluids.CRYSTALIZED_OIL.getName(), power[2], time[2]);
ActuallyAdditionsAPI.addOilGenRecipe(InitFluids.fluidEmpoweredOil.getName(), power[3], time[3]); ActuallyAdditionsAPI.addOilGenRecipe(InitFluids.EMPOWERED_OIL.getName(), power[3], time[3]);
ActuallyAdditionsAPI.addFarmerBehavior(new DefaultFarmerBehavior()); ActuallyAdditionsAPI.addFarmerBehavior(new DefaultFarmerBehavior());
ActuallyAdditionsAPI.addFarmerBehavior(new CactusFarmerBehavior()); ActuallyAdditionsAPI.addFarmerBehavior(new CactusFarmerBehavior());

View file

@ -11,17 +11,62 @@
package de.ellpeck.actuallyadditions.mod.fluids; package de.ellpeck.actuallyadditions.mod.fluids;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks;
import de.ellpeck.actuallyadditions.mod.items.ActuallyItems;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.FlowingFluidBlock;
import net.minecraft.block.material.Material;
import net.minecraft.fluid.FlowingFluid;
import net.minecraft.fluid.Fluid; import net.minecraft.fluid.Fluid;
import net.minecraft.item.BucketItem;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.FluidAttributes;
import net.minecraftforge.fluids.ForgeFlowingFluid;
import net.minecraftforge.fml.RegistryObject;
public class FluidAA extends Fluid { import java.util.function.Supplier;
public class FluidAA implements Supplier<Fluid> {
private String name;
private RegistryObject<ForgeFlowingFluid> source;
private RegistryObject<ForgeFlowingFluid> flowing;
private RegistryObject<FlowingFluidBlock> fluidBlock;
private RegistryObject<Item> bucket;
public String getName() {
return name;
}
public FluidAA(String fluidName, String textureName) { public FluidAA(String fluidName, String textureName) {
super(fluidName, new ResourceLocation(ActuallyAdditions.MODID, "blocks/" + textureName + "_still"), new ResourceLocation(ActuallyAdditions.MODID, "blocks/" + textureName + "_flowing")); name = fluidName;
ForgeFlowingFluid.Properties props = makeProperties(textureName, fluidBlock, source, flowing, bucket);
source = InitFluids.FLUIDS.register(name, () -> new ForgeFlowingFluid.Source(props));
flowing = InitFluids.FLUIDS.register(name + "_flowing", () -> new ForgeFlowingFluid.Flowing(props));
fluidBlock = ActuallyBlocks.BLOCKS.register(name, () -> new FlowingFluidBlock(source, AbstractBlock.Properties.of(Material.WATER)));
bucket = ActuallyItems.ITEMS.register(name + "_bucket", () -> new BucketItem(source.get(), new Item.Properties().craftRemainder(Items.BUCKET).tab(ActuallyAdditions.GROUP).stacksTo(1)));
}
public static ForgeFlowingFluid.Properties makeProperties(String texture, Supplier<FlowingFluidBlock> blockSupplier, Supplier<ForgeFlowingFluid> stillSupplier, Supplier<ForgeFlowingFluid> flowingSupplier, Supplier<Item> bucketSupplier) {
return new ForgeFlowingFluid.Properties(stillSupplier, flowingSupplier, FluidAttributes.builder(new ResourceLocation(ActuallyAdditions.MODID,texture), new ResourceLocation(ActuallyAdditions.MODID, texture))).bucket(bucketSupplier).block(blockSupplier);
} }
@Override @Override
public String getUnlocalizedName() { public Fluid get() {
return "fluid." + ActuallyAdditions.MODID + "." + this.unlocalizedName; return source.get();
}
public Block getBlock() {
return fluidBlock.get();
}
public Item getBucket() {
return bucket.get();
}
public FlowingFluid getFlowing() {
return flowing.get();
} }
} }

View file

@ -11,51 +11,24 @@
package de.ellpeck.actuallyadditions.mod.fluids; package de.ellpeck.actuallyadditions.mod.fluids;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockFluidFlowing;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.fluid.Fluid; import net.minecraft.fluid.Fluid;
import net.minecraft.item.Rarity; import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistries;
import java.util.Locale;
public final class InitFluids { public final class InitFluids {
public static final DeferredRegister<Fluid> FLUIDS = DeferredRegister.create(ForgeRegistries.FLUIDS, ActuallyAdditions.MODID); public static final DeferredRegister<Fluid> FLUIDS = DeferredRegister.create(ForgeRegistries.FLUIDS, ActuallyAdditions.MODID);
public static final DeferredRegister<Block> FLUID_BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, ActuallyAdditions.MODID);
public static final RegistryObject<Fluid> fluidCanolaOil = FLUIDS.register("canolaoil", () -> registerFluid("canolaoil","block_canola_oil")); public static final FluidAA CANOLA_OIL = new FluidAA("canolaoil", "canolaoil");
public static final RegistryObject<Fluid> fluidRefinedCanolaOil = FLUIDS.register("refinedcanolaoil", () -> registerFluid("refinedcanolaoil","block_refined_canola_oil")); public static final FluidAA REFINED_CANOLA_OIL = new FluidAA("refinedcanolaoil", "refinedcanolaoil");
public static final RegistryObject<Fluid> fluidCrystalOil = FLUIDS.register("crystaloil", () -> registerFluid("crystaloil","block_crystal_oil")); public static final FluidAA CRYSTALIZED_OIL = new FluidAA("crystaloil", "crystaloil");
public static final RegistryObject<Fluid> fluidEmpoweredOil = FLUIDS.register("empoweredoil", () -> registerFluid("empoweredoil","block_empowered_oil")); public static final FluidAA EMPOWERED_OIL = new FluidAA("empoweredoil", "empoweredoil");
public static Block blockCanolaOil;
public static Block blockRefinedCanolaOil;
public static Block blockCrystalOil;
public static Block blockEmpoweredOil;
public static void init() { public static void init(IEventBus bus) {
//fluidCanolaOil = registerFluid("canolaoil", "block_canola_oil", Rarity.COMMON); FLUIDS.register(bus);
//fluidRefinedCanolaOil = registerFluid("refinedcanolaoil", "block_refined_canola_oil", Rarity.UNCOMMON); FLUID_BLOCKS.register(bus);
//fluidCrystalOil = registerFluid("crystaloil", "block_crystal_oil", Rarity.RARE);
//fluidEmpoweredOil = registerFluid("empoweredoil", "block_empowered_oil", Rarity.EPIC);
blockCanolaOil = registerFluidBlock(fluidCanolaOil.get(), Material.WATER, "block_canola_oil");
blockRefinedCanolaOil = registerFluidBlock(fluidRefinedCanolaOil.get(), Material.WATER, "block_refined_canola_oil");
blockCrystalOil = registerFluidBlock(fluidCrystalOil.get(), Material.WATER, "block_crystal_oil");
blockEmpoweredOil = registerFluidBlock(fluidEmpoweredOil.get(), Material.WATER, "block_empowered_oil");
}
private static Fluid registerFluid(String fluidName, String fluidTextureName) {
Fluid fluid = new FluidAA(fluidName.toLowerCase(Locale.ROOT), fluidTextureName);
// FluidRegistry.registerFluid(fluid);
// FluidRegistry.addBucketForFluid(fluid);
return fluid;
}
private static Block registerFluidBlock(Fluid fluid, Material material, String name) {
return new BlockFluidFlowing(fluid, material, name); //TODO ohhhh boy, all this fluid stuff needs to be redone.
} }
} }

View file

@ -37,8 +37,6 @@ import net.minecraftforge.fluids.capability.templates.FluidTank;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase.NBTType;
public class TileEntityCanolaPress extends TileEntityInventoryBase implements INamedContainerProvider, ISharingFluidHandler { public class TileEntityCanolaPress extends TileEntityInventoryBase implements INamedContainerProvider, ISharingFluidHandler {
public static final int PRODUCE = 80; public static final int PRODUCE = 80;
@ -113,7 +111,7 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements IN
this.inv.setStackInSlot(0, StackUtil.shrink(this.inv.getStackInSlot(0), 1)); this.inv.setStackInSlot(0, StackUtil.shrink(this.inv.getStackInSlot(0), 1));
this.tank.fill(new FluidStack(InitFluids.fluidCanolaOil.get(), PRODUCE), IFluidHandler.FluidAction.EXECUTE); this.tank.fill(new FluidStack(InitFluids.CANOLA_OIL.get(), PRODUCE), IFluidHandler.FluidAction.EXECUTE);
this.setChanged(); this.setChanged();
} }
} }

View file

@ -13,7 +13,6 @@ package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks;
import de.ellpeck.actuallyadditions.mod.fluids.InitFluids; import de.ellpeck.actuallyadditions.mod.fluids.InitFluids;
import de.ellpeck.actuallyadditions.mod.inventory.ContainerFermentingBarrel; import de.ellpeck.actuallyadditions.mod.inventory.ContainerFermentingBarrel;
import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.Container;
@ -28,13 +27,10 @@ import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.fluids.FluidAttributes; import net.minecraftforge.fluids.FluidAttributes;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fluids.capability.templates.FluidTank;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase.NBTType;
public class TileEntityFermentingBarrel extends TileEntityBase implements ISharingFluidHandler, INamedContainerProvider { public class TileEntityFermentingBarrel extends TileEntityBase implements ISharingFluidHandler, INamedContainerProvider {
private static final int PROCESS_TIME = 100; private static final int PROCESS_TIME = 100;
@ -155,8 +151,8 @@ public class TileEntityFermentingBarrel extends TileEntityBase implements IShari
public class FermentingBarrelMultiTank implements IFluidHandler { public class FermentingBarrelMultiTank implements IFluidHandler {
public FluidStack canolaTank = new FluidStack(InitFluids.fluidCanolaOil.get(), 0); public FluidStack canolaTank = new FluidStack(InitFluids.CANOLA_OIL.get(), 0);
public FluidStack oilTank = new FluidStack(InitFluids.fluidRefinedCanolaOil.get(), 0); public FluidStack oilTank = new FluidStack(InitFluids.REFINED_CANOLA_OIL.get(), 0);
private int capacity = FluidAttributes.BUCKET_VOLUME * 2; private int capacity = FluidAttributes.BUCKET_VOLUME * 2;
@Override @Override
@ -177,12 +173,12 @@ public class TileEntityFermentingBarrel extends TileEntityBase implements IShari
@Override @Override
public boolean isFluidValid(int tank, @Nonnull FluidStack stack) { public boolean isFluidValid(int tank, @Nonnull FluidStack stack) {
return tank == 0? stack.getFluid() == InitFluids.fluidCanolaOil.get():stack.getFluid() == InitFluids.fluidRefinedCanolaOil.get(); return tank == 0? stack.getFluid() == InitFluids.CANOLA_OIL.get():stack.getFluid() == InitFluids.REFINED_CANOLA_OIL.get();
} }
@Override @Override
public int fill(FluidStack resource, FluidAction action) { public int fill(FluidStack resource, FluidAction action) {
if (resource.isEmpty() || resource.getFluid() != InitFluids.fluidCanolaOil.get()) if (resource.isEmpty() || resource.getFluid() != InitFluids.CANOLA_OIL.get())
return 0; return 0;
if(action.simulate()) if(action.simulate())
@ -230,7 +226,7 @@ public class TileEntityFermentingBarrel extends TileEntityBase implements IShari
@Nonnull @Nonnull
@Override @Override
public FluidStack drain(FluidStack resource, FluidAction action) { public FluidStack drain(FluidStack resource, FluidAction action) {
if (resource.isEmpty() || resource.getFluid() != InitFluids.fluidRefinedCanolaOil.get()) if (resource.isEmpty() || resource.getFluid() != InitFluids.REFINED_CANOLA_OIL.get())
return FluidStack.EMPTY; return FluidStack.EMPTY;
return drain(resource.getAmount(), action); return drain(resource.getAmount(), action);