diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java index cc5b5b714..e37760c4c 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java @@ -93,6 +93,7 @@ public class ActuallyAdditions { MinecraftForge.EVENT_BUS.register(new CommonEvents()); MinecraftForge.EVENT_BUS.register(new DungeonLoot()); MinecraftForge.EVENT_BUS.addListener(ActuallyAdditions::reloadEvent); + InitFluids.init(eventBus); eventBus.addListener(this::setup); eventBus.addListener(this::clientSetup); @@ -109,7 +110,6 @@ public class ActuallyAdditions { commonCapsLoaded = false; // Loader.isModLoaded("commoncapabilities"); - InitFluids.init(); new UpdateChecker(); BannerHelper.init(); InitEntities.init(); // todo: [port] replace diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/InitCrafting.java b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/InitCrafting.java index 79dca5512..bac35ccc1 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/InitCrafting.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/InitCrafting.java @@ -35,10 +35,10 @@ public final class InitCrafting { int[] power = ConfigIntListValues.OIL_POWER.getValue(); int[] time = ConfigIntListValues.OIL_TIME.getValue(); - ActuallyAdditionsAPI.addOilGenRecipe(InitFluids.fluidCanolaOil.getName(), power[0], time[0]); - ActuallyAdditionsAPI.addOilGenRecipe(InitFluids.fluidRefinedCanolaOil.getName(), power[1], time[1]); - ActuallyAdditionsAPI.addOilGenRecipe(InitFluids.fluidCrystalOil.getName(), power[2], time[2]); - ActuallyAdditionsAPI.addOilGenRecipe(InitFluids.fluidEmpoweredOil.getName(), power[3], time[3]); + ActuallyAdditionsAPI.addOilGenRecipe(InitFluids.CANOLA_OIL.getName(), power[0], time[0]); + ActuallyAdditionsAPI.addOilGenRecipe(InitFluids.REFINED_CANOLA_OIL.getName(), power[1], time[1]); + ActuallyAdditionsAPI.addOilGenRecipe(InitFluids.CRYSTALIZED_OIL.getName(), power[2], time[2]); + ActuallyAdditionsAPI.addOilGenRecipe(InitFluids.EMPOWERED_OIL.getName(), power[3], time[3]); ActuallyAdditionsAPI.addFarmerBehavior(new DefaultFarmerBehavior()); ActuallyAdditionsAPI.addFarmerBehavior(new CactusFarmerBehavior()); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/fluids/FluidAA.java b/src/main/java/de/ellpeck/actuallyadditions/mod/fluids/FluidAA.java index fcf7e82db..a686f1907 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/fluids/FluidAA.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/fluids/FluidAA.java @@ -11,17 +11,62 @@ package de.ellpeck.actuallyadditions.mod.fluids; 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.item.BucketItem; +import net.minecraft.item.Item; +import net.minecraft.item.Items; 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 { + private String name; + private RegistryObject source; + private RegistryObject flowing; + private RegistryObject fluidBlock; + private RegistryObject bucket; + + public String getName() { + return name; + } 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 blockSupplier, Supplier stillSupplier, Supplier flowingSupplier, Supplier bucketSupplier) { + return new ForgeFlowingFluid.Properties(stillSupplier, flowingSupplier, FluidAttributes.builder(new ResourceLocation(ActuallyAdditions.MODID,texture), new ResourceLocation(ActuallyAdditions.MODID, texture))).bucket(bucketSupplier).block(blockSupplier); } @Override - public String getUnlocalizedName() { - return "fluid." + ActuallyAdditions.MODID + "." + this.unlocalizedName; + public Fluid get() { + return source.get(); + } + + public Block getBlock() { + return fluidBlock.get(); + } + + public Item getBucket() { + return bucket.get(); + } + + public FlowingFluid getFlowing() { + return flowing.get(); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/fluids/InitFluids.java b/src/main/java/de/ellpeck/actuallyadditions/mod/fluids/InitFluids.java index 4cc880cac..155525fd8 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/fluids/InitFluids.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/fluids/InitFluids.java @@ -11,51 +11,24 @@ package de.ellpeck.actuallyadditions.mod.fluids; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; -import de.ellpeck.actuallyadditions.mod.blocks.base.BlockFluidFlowing; import net.minecraft.block.Block; -import net.minecraft.block.material.Material; import net.minecraft.fluid.Fluid; -import net.minecraft.item.Rarity; -import net.minecraftforge.fml.RegistryObject; +import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; -import java.util.Locale; - public final class InitFluids { public static final DeferredRegister FLUIDS = DeferredRegister.create(ForgeRegistries.FLUIDS, ActuallyAdditions.MODID); + public static final DeferredRegister FLUID_BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, ActuallyAdditions.MODID); - public static final RegistryObject fluidCanolaOil = FLUIDS.register("canolaoil", () -> registerFluid("canolaoil","block_canola_oil")); - public static final RegistryObject fluidRefinedCanolaOil = FLUIDS.register("refinedcanolaoil", () -> registerFluid("refinedcanolaoil","block_refined_canola_oil")); - public static final RegistryObject fluidCrystalOil = FLUIDS.register("crystaloil", () -> registerFluid("crystaloil","block_crystal_oil")); - public static final RegistryObject fluidEmpoweredOil = FLUIDS.register("empoweredoil", () -> registerFluid("empoweredoil","block_empowered_oil")); + public static final FluidAA CANOLA_OIL = new FluidAA("canolaoil", "canolaoil"); + public static final FluidAA REFINED_CANOLA_OIL = new FluidAA("refinedcanolaoil", "refinedcanolaoil"); + public static final FluidAA CRYSTALIZED_OIL = new FluidAA("crystaloil", "crystaloil"); + 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() { - //fluidCanolaOil = registerFluid("canolaoil", "block_canola_oil", Rarity.COMMON); - //fluidRefinedCanolaOil = registerFluid("refinedcanolaoil", "block_refined_canola_oil", Rarity.UNCOMMON); - //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. + public static void init(IEventBus bus) { + FLUIDS.register(bus); + FLUID_BLOCKS.register(bus); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCanolaPress.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCanolaPress.java index 8d42c1857..554a5e7e3 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCanolaPress.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCanolaPress.java @@ -37,8 +37,6 @@ import net.minecraftforge.fluids.capability.templates.FluidTank; import javax.annotation.Nullable; -import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase.NBTType; - public class TileEntityCanolaPress extends TileEntityInventoryBase implements INamedContainerProvider, ISharingFluidHandler { 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.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(); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFermentingBarrel.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFermentingBarrel.java index d8df1484d..a2e500a34 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFermentingBarrel.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFermentingBarrel.java @@ -13,7 +13,6 @@ package de.ellpeck.actuallyadditions.mod.tile; import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; import de.ellpeck.actuallyadditions.mod.fluids.InitFluids; 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.PlayerInventory; 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.FluidStack; import net.minecraftforge.fluids.capability.IFluidHandler; -import net.minecraftforge.fluids.capability.templates.FluidTank; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase.NBTType; - public class TileEntityFermentingBarrel extends TileEntityBase implements ISharingFluidHandler, INamedContainerProvider { private static final int PROCESS_TIME = 100; @@ -155,8 +151,8 @@ public class TileEntityFermentingBarrel extends TileEntityBase implements IShari public class FermentingBarrelMultiTank implements IFluidHandler { - public FluidStack canolaTank = new FluidStack(InitFluids.fluidCanolaOil.get(), 0); - public FluidStack oilTank = new FluidStack(InitFluids.fluidRefinedCanolaOil.get(), 0); + public FluidStack canolaTank = new FluidStack(InitFluids.CANOLA_OIL.get(), 0); + public FluidStack oilTank = new FluidStack(InitFluids.REFINED_CANOLA_OIL.get(), 0); private int capacity = FluidAttributes.BUCKET_VOLUME * 2; @Override @@ -177,12 +173,12 @@ public class TileEntityFermentingBarrel extends TileEntityBase implements IShari @Override 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 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; if(action.simulate()) @@ -230,7 +226,7 @@ public class TileEntityFermentingBarrel extends TileEntityBase implements IShari @Nonnull @Override 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 drain(resource.getAmount(), action);