Skip to content

Commit

Permalink
fluids are fun...
Browse files Browse the repository at this point in the history
  • Loading branch information
ferriarnus committed Jan 1, 2024
1 parent 28a09d0 commit b31001d
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"variants": {
"": {
"model": "examplemod:block/examplemod"
"model": "minecraft:block/water"
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "examplemod:item/examplemod"
}
"parent": "neoforge:item/bucket",
"fluid": "examplemod:fluid_example_fluid_still",
"loader": "neoforge:fluid_container"
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,4 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
],
"entries": [
{
"type": "minecraft:item",
"name": "minecraft:air"
}
],
"rolls": 1.0
}
],
"random_sequence": "examplemod:blocks/examplemod"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.world.flag.FeatureFlags;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.storage.loot.BuiltInLootTables;
import net.minecraft.world.level.storage.loot.LootTable;
import net.neoforged.neoforge.registries.DeferredHolder;
Expand Down Expand Up @@ -77,4 +78,8 @@ public void createDoor(Block block) {
public void add(Block p_250610_, LootTable.Builder p_249817_) {
super.add(p_250610_, p_249817_);
}

public void noDrop(Block block) {
this.add(block, noDrop());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.data.PackOutput;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.BucketItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.ItemLike;
import net.neoforged.neoforge.client.model.generators.ItemModelBuilder;
import net.neoforged.neoforge.client.model.generators.ItemModelProvider;
import net.neoforged.neoforge.client.model.generators.ModelFile;
import net.neoforged.neoforge.client.model.generators.loaders.DynamicFluidContainerModelBuilder;
import net.neoforged.neoforge.common.data.ExistingFileHelper;
import net.neoforged.neoforge.internal.versions.neoforge.NeoForgeVersion;
import net.neoforged.neoforge.registries.DeferredHolder;

import java.util.Objects;
Expand All @@ -27,7 +30,7 @@ public EnderItemModelProvider(PackOutput output, String modid, ExistingFileHelpe
@Override
protected void registerModels() {
for (DeferredHolder<Item, ? extends Item> item : registry.getEntries()) {
BiConsumer<EnderItemModelProvider, Item> modelProvider = ((EnderDeferredItem<? extends Item>) item).getModelProvider();
BiConsumer<EnderItemModelProvider, Item> modelProvider = (BiConsumer<EnderItemModelProvider, Item>) ((EnderDeferredItem<? extends Item>) item).getModelProvider();
if (modelProvider != null) {
modelProvider.accept(this, item.get());
}
Expand All @@ -54,6 +57,11 @@ public ResourceLocation itemTexture(ItemLike item) {
return Objects.requireNonNull(BuiltInRegistries.ITEM.getKey(item.asItem()));
}


public ItemModelBuilder bucketItem(BucketItem item) {
return withExistingParent(BuiltInRegistries.ITEM.getKey(item).toString(), new ResourceLocation(NeoForgeVersion.MOD_ID, "item/bucket"))
.customLoader(DynamicFluidContainerModelBuilder::begin)
.fluid(item.getFluid())
.end();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.LiquidBlock;
import net.neoforged.neoforge.client.model.generators.BlockStateProvider;
import net.neoforged.neoforge.client.model.generators.ModelFile;
import net.neoforged.neoforge.fluids.FluidType;
import net.neoforged.neoforge.registries.DeferredBlock;
import net.neoforged.neoforge.registries.DeferredHolder;
Expand Down Expand Up @@ -110,6 +111,13 @@ public static class EnderDeferredLiquidBlock<T extends LiquidBlock> extends Ende

protected EnderDeferredLiquidBlock(ResourceKey<Block> key) {
super(key);
this.setLootTable(EnderBlockLootProvider::noDrop);
this.setBlockStateProvider((prov, t) -> prov.getVariantBuilder(t)
.partialState()
.modelForState()
.modelFile(prov.models().getExistingFile(new ResourceLocation("water")))
.addModel()
);
}

public EnderDeferredLiquidBlock<T> setFluid(EnderDeferredFluid<? extends FluidType> fluid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public EnderDeferredBlockItem<T,U> setTranslation(String translation) {
}

@Override
public EnderDeferredBlockItem<T,U> setModelProvider(BiConsumer<EnderItemModelProvider, Item> modelProvider) {
public EnderDeferredBlockItem<T,U> setModelProvider(BiConsumer<EnderItemModelProvider, T> modelProvider) {
this.modelProvider = modelProvider;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class EnderDeferredItem<T extends Item> extends DeferredItem<T> implement
protected Set<TagKey<Item>> ItemTags = new HashSet<>();
protected Map<ResourceKey<CreativeModeTab>, Consumer<CreativeModeTab.Output>> tab = new HashMap<>();
@Nullable
protected BiConsumer<EnderItemModelProvider, Item> modelProvider = EnderItemModelProvider::basicItem;
protected BiConsumer<EnderItemModelProvider, T> modelProvider = EnderItemModelProvider::basicItem;
protected Supplier<ItemColor> colorSupplier;

protected EnderDeferredItem(ResourceKey<Item> key) {
Expand Down Expand Up @@ -74,12 +74,12 @@ public Map<ResourceKey<CreativeModeTab>, Consumer<CreativeModeTab.Output>> getTa
return tab;
}

public EnderDeferredItem<T> setModelProvider(BiConsumer<EnderItemModelProvider, Item> modelProvider) {
public EnderDeferredItem<T> setModelProvider(BiConsumer<EnderItemModelProvider, T> modelProvider) {
this.modelProvider = modelProvider;
return this;
}

public BiConsumer<EnderItemModelProvider, Item> getModelProvider() {
public BiConsumer<EnderItemModelProvider, T> getModelProvider() {
return modelProvider;
}

Expand Down Expand Up @@ -112,6 +112,7 @@ public static class EnderDeferredBucketItem<T extends BucketItem> extends EnderD

protected EnderDeferredBucketItem(ResourceKey<Item> key) {
super(key);
this.modelProvider = EnderItemModelProvider::bucketItem;
}

public EnderDeferredBucketItem<T> setFluid(EnderDeferredFluid<? extends FluidType> fluid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.material.Fluid;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.client.extensions.common.IClientFluidTypeExtensions;
import net.neoforged.neoforge.fluids.FluidType;
import net.neoforged.neoforge.registries.DeferredHolder;
import net.neoforged.neoforge.registries.DeferredRegister;
import net.neoforged.neoforge.registries.NeoForgeRegistries;

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

Expand Down Expand Up @@ -43,7 +45,22 @@ public <I extends FluidType> EnderDeferredFluid<I> register(String name, Supplie
}

public EnderDeferredFluid<FluidType> registerFluid(String name, FluidType.Properties type) {
EnderDeferredFluid<FluidType> fluid = this.register(name, () -> new FluidType(type));
EnderDeferredFluid<FluidType> fluid = this.register(name, () -> new FluidType(type) {
@Override
public void initializeClient(Consumer<IClientFluidTypeExtensions> consumer) {
consumer.accept(new IClientFluidTypeExtensions() {
@Override
public ResourceLocation getStillTexture() {
return new ResourceLocation(getNamespace(), "block/" + name + "_still");
}

@Override
public ResourceLocation getFlowingTexture() {
return new ResourceLocation(getNamespace(), "block/" + name + "_flowing");
}
});
}
});
fluid.setRegistries(FLUID, BLOCKS, ITEMS);
return fluid;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/example/examplemod/testmod/Fluids.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.item.BucketItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.Fluid;
Expand All @@ -22,7 +23,7 @@ public class Fluids {

public static final EnderDeferredFluid<? extends FluidType> EXAMPLE_FLUID = FLUIDTYPES.registerFluid("example_fluid", FluidType.Properties.create())
.createFluid(properties -> {})
.withBlock(fluid -> new LiquidBlock(fluid, BlockBehaviour.Properties.of()))
.withBlock(fluid -> new LiquidBlock(fluid, BlockBehaviour.Properties.copy(Blocks.WATER)))
.finishLiquidBlock()
.withBucket(fluid -> new BucketItem(fluid, new Item.Properties()))
.finishBucket();
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b31001d

Please sign in to comment.