Skip to content

Commit

Permalink
Fully replace fluid module
Browse files Browse the repository at this point in the history
  • Loading branch information
Rover656 committed Jul 29, 2024
1 parent 1d44f11 commit 992f120
Show file tree
Hide file tree
Showing 20 changed files with 378 additions and 313 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import java.net.URI
plugins {
id("idea")
id("maven-publish")
id("net.neoforged.moddev") version "1.0.9"
id("net.neoforged.moddev") version "1.0.15"
id("org.cadixdev.licenser") version "0.6.1"
}

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ org.gradle.debug=false

## Environment Properties
minecraftVersion=1.21
neoForgeVersion=21.0.95-beta
neoForgeVersion=21.0.145
versionSeries=0.1

neoForge.parchment.minecraftVersion=1.21
neoForge.parchment.mappingsVersion=2024.07.07
neoForge.parchment.mappingsVersion=2024.07.28
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "examplemod:block/example_fluid"
}
}
}
3 changes: 2 additions & 1 deletion src/generated/resources/assets/examplemod/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"block.examplemod.example_block": "Test Example Block",
"fluid_type.examplemod.example_fluid": "Example Fluid",
"block.examplemod.example_fluid": "Example Fluid",
"item.examplemod.example_fluid_bucket": "Example Fluid Bucket",
"item.examplemod.example_item": "Test Example Item",
"itemGroup.examplemod.example_tab": "Example"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:block/cube_all",
"textures": {
"all": "examplemod:block/example_fluid"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"parent": "neoforge:item/bucket",
"fluid": "examplemod:fluid_example_fluid_source",
"loader": "neoforge:fluid_container"
}
15 changes: 7 additions & 8 deletions src/main/java/com/enderio/regilite/Regilite.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

package com.enderio.regilite;

import com.enderio.regilite.fluids.RegiliteFluidTypes;
import com.enderio.regilite.utils.BundledDataProvider;
import com.enderio.regilite.data.RegiliteDataProvider;
import com.enderio.regilite.events.BlockEntityCapabilityEvents;
import com.enderio.regilite.events.BlockEntityRendererEvents;
import com.enderio.regilite.events.EntityRendererEvents;
import com.enderio.regilite.events.FluidRenderTypeEvents;
import com.enderio.regilite.events.ScreenEvents;
import com.enderio.regilite.blocks.RegiliteBlocks;
import com.enderio.regilite.items.RegiliteItems;
Expand All @@ -19,7 +19,6 @@
import com.enderio.regilite.tags.RegiliteTags;
import com.enderio.regilite.registry.BlockEntityRegistry;
import com.enderio.regilite.registry.EntityRegistry;
import com.enderio.regilite.registry.FluidRegistry;
import com.enderio.regilite.registry.MenuRegistry;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import it.unimi.dsi.fastutil.objects.ObjectList;
Expand Down Expand Up @@ -59,6 +58,7 @@ public class Regilite {

private final RegiliteItems itemsModule;
private final RegiliteBlocks blocksRegistry;
private final RegiliteFluidTypes fluidTypesModule;

private final RegiliteDataProvider dataProvider;

Expand All @@ -77,6 +77,7 @@ public Regilite(String modId) {

this.itemsModule = registerModule(RegiliteItems.create(this));
this.blocksRegistry = registerModule(RegiliteBlocks.create(this));
this.fluidTypesModule = registerModule(RegiliteFluidTypes.create(this));
}

private <T> T registerModule(T module) {
Expand Down Expand Up @@ -111,6 +112,10 @@ public RegiliteBlocks blocks() {
return blocksRegistry;
}

public RegiliteFluidTypes fluidTypes() {
return fluidTypesModule;
}

public DeferredRegister.DataComponents dataComponents() {
throw new NotImplementedException();
}
Expand All @@ -133,8 +138,6 @@ public void register(IEventBus modbus) {
if (FMLEnvironment.dist.isClient()) {
modbus.addListener(new BlockEntityRendererEvents(this)::registerBER);

modbus.addListener(new FluidRenderTypeEvents(this)::registerRenderTypes);

modbus.addListener(new EntityRendererEvents(this)::registerER);

modbus.addListener(new ScreenEvents(this)::screenEvent);
Expand All @@ -159,10 +162,6 @@ public EntityRegistry entityRegistry() {
return EntityRegistry.create(this);
}

public FluidRegistry fluidRegistry() {
return FluidRegistry.create(this);
}

public MenuRegistry menuRegistry() {
return MenuRegistry.create(this);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/enderio/regilite/RegiliteBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected RegiliteBuilder(H holder) {
* This will allow all the builder data to be flushed after initialization.
* @return The holder.
*/
public final H finishHolder() {
public final H asHolder() {
return holder;
}

Expand Down
24 changes: 0 additions & 24 deletions src/main/java/com/enderio/regilite/data/RegiliteTagProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package com.enderio.regilite.data;

import com.enderio.regilite.holder.RegiliteFluid;
import com.enderio.regilite.registry.ITagagble;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.Registry;
Expand Down Expand Up @@ -44,27 +43,4 @@ protected void addTags(HolderLookup.Provider lookupProvider) {
}
}
}

public static class FluidTagProvider extends IntrinsicHolderTagsProvider<Fluid> {

public final List<DeferredHolder<FluidType, ? extends FluidType>> registered;

public FluidTagProvider(PackOutput output, ResourceKey<Registry<Fluid>> key, Function<Fluid, ResourceKey<Fluid>> func, CompletableFuture<HolderLookup.Provider> lookupProvider, String modId, @Nullable ExistingFileHelper existingFileHelper, List<DeferredHolder<FluidType, ? extends FluidType>> registered) {
super(output, key, lookupProvider, func, modId, existingFileHelper);
this.registered = registered;
}

@Override
protected void addTags(HolderLookup.Provider lookupProvider) {
for (DeferredHolder<FluidType, ? extends FluidType> entry : registered) {
if (entry instanceof RegiliteFluid<? extends FluidType> fluidtype) {
Set<TagKey<Fluid>> tag = ((ITagagble<Fluid>)entry).getTags();

if (tag != null) {
tag.forEach(t -> tag(t).add(fluidtype.getSource()));
}
}
}
}
}
}

This file was deleted.

129 changes: 129 additions & 0 deletions src/main/java/com/enderio/regilite/fluids/FluidTypeBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* Copyright (c) Team Ender IO and contributors
* SPDX-License-Identifier: LGPL-3.0-only
*/

package com.enderio.regilite.fluids;

import com.enderio.regilite.RegiliteBuilder;
import com.enderio.regilite.blocks.BlockBuilder;
import com.enderio.regilite.blocks.RegiliteBlocks;
import com.enderio.regilite.items.ItemBuilder;
import com.enderio.regilite.items.RegiliteItems;
import com.enderio.regilite.lang.RegiliteLang;
import com.enderio.regilite.tags.RegiliteTags;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.BucketItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.FlowingFluid;
import net.minecraft.world.level.material.Fluid;
import net.neoforged.neoforge.fluids.BaseFlowingFluid;
import net.neoforged.neoforge.fluids.FluidType;
import net.neoforged.neoforge.registries.DeferredRegister;

import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.function.UnaryOperator;

public class FluidTypeBuilder<T extends FluidType> extends RegiliteBuilder<FluidTypeBuilder<T>, FluidType, T, FluidTypeHolder<T>> {

private final RegiliteLang langModule;
private final RegiliteTags tagsModule;
private final RegiliteItems itemsModule;
private final RegiliteBlocks blocksModule;

private BaseFlowingFluid.Properties properties = new BaseFlowingFluid.Properties(holder, holder::sourceFluid, holder::flowingFluid).block(holder::block).bucket(holder::bucket);

protected Supplier<Supplier<RenderType>> renderTypeSupplier = () -> null;

protected FluidTypeBuilder(FluidTypeHolder<T> holder, DeferredRegister<Fluid> fluidRegister, RegiliteLang langModule, RegiliteTags tagsModule, RegiliteItems itemsModule, RegiliteBlocks blocksModule) {
super(holder);
this.langModule = langModule;
this.tagsModule = tagsModule;
this.itemsModule = itemsModule;
this.blocksModule = blocksModule;

// TODO: Make the factories configurable (and add opt-out).
holder.flowingFluidHolder(fluidRegister.register("fluid_" + getId().getPath() + "_flowing", () -> new BaseFlowingFluid.Flowing(properties)));
holder.sourceFluidHolder(fluidRegister.register("fluid_" + getId().getPath() + "_source", () -> new BaseFlowingFluid.Source(properties)));
}

public FluidTypeBuilder<T> tag(TagKey<Fluid> tag) {
tagsModule.fluids().tag(tag).add(holder::sourceFluid, holder::flowingFluid);
return this;
}

@SafeVarargs
public final FluidTypeBuilder<T> tags(TagKey<Fluid>... tags) {
tagsModule.fluids().addToTags(holder::sourceFluid, tags);
tagsModule.fluids().addToTags(holder::flowingFluid, tags);
return this;
}

public FluidTypeBuilder<T> translation(String translation) {
langModule.addFluid(this::get, translation);
return this;
}

public FluidTypeBuilder<T> properties(UnaryOperator<BaseFlowingFluid.Properties> propertiesOperator) {
properties = propertiesOperator.apply(properties);
return this;
}

public FluidTypeBuilder<T> bucket() {
return customBucket(f -> new BucketItem(f.get(), new Item.Properties().stacksTo(1)), i -> {
});
}

public FluidTypeBuilder<T> bucket(Consumer<ItemBuilder<BucketItem>> itemConfigure) {
return customBucket(f -> new BucketItem(f.get(), new Item.Properties().stacksTo(1)), itemConfigure);
}

public FluidTypeBuilder<T> bucket(Item.Properties properties) {
return customBucket(f -> new BucketItem(f.get(), properties), i -> {
});
}

public <I extends BucketItem> FluidTypeBuilder<T> customBucket(Function<Supplier<? extends FlowingFluid>, I> supplier) {
return customBucket(supplier, i -> {
});
}

public <I extends BucketItem> FluidTypeBuilder<T> customBucket(Function<Supplier<? extends FlowingFluid>, I> supplier, Consumer<ItemBuilder<I>> itemConfigure) {
var bucket = itemsModule.create(getId().getPath() + "_bucket", () -> supplier.apply(holder::sourceFluid));
bucket.modelProvider((prov, ctx) -> prov.bucketItem(ctx.get()));
itemConfigure.accept(bucket);
holder.bucketHolder(bucket.asHolder());
return this;
}

public FluidTypeBuilder<T> block(BlockBehaviour.Properties properties) {
return block(f -> new LiquidBlock(f.get(), properties), b -> {
});
}

public FluidTypeBuilder<T> block(BlockBehaviour.Properties properties, Consumer<BlockBuilder<LiquidBlock>> blockConfigure) {
return block(f -> new LiquidBlock(f.get(), properties), blockConfigure);
}

public <B extends LiquidBlock> FluidTypeBuilder<T> block(Function<Supplier<? extends BaseFlowingFluid>, B> supplier) {
return block(supplier, b -> {
});
}

public <B extends LiquidBlock> FluidTypeBuilder<T> block(Function<Supplier<? extends BaseFlowingFluid>, B> supplier, Consumer<BlockBuilder<B>> blockConfigure) {
var block = blocksModule.create(getId().getPath(), () -> supplier.apply(holder::flowingFluid));
blockConfigure.accept(block);
holder.blockHolder(block.asHolder());
return this;
}

public FluidTypeBuilder<T> renderType(Supplier<Supplier<RenderType>> renderTypeSupplier) {
this.renderTypeSupplier = renderTypeSupplier;
return this;
}
}
Loading

0 comments on commit 992f120

Please sign in to comment.