Skip to content

Commit

Permalink
Fluids !!!!!!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
Leclowndu93150 committed Sep 5, 2024
1 parent 7e95a8d commit 16e2552
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ dependencies {
compileOnly "mezz.jei:jei-${minecraft_version}-neoforge-api:${jei_version}"

localRuntime "mezz.jei:jei-${minecraft_version}-neoforge:${jei_version}"
runtimeOnly "curse.maven:embeddium-908741:5556146"
//runtimeOnly "curse.maven:embeddium-908741:5556146"
}

tasks.withType(ProcessResources).configureEach {
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/portingdeadmods/modjam/ModJam.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import com.portingdeadmods.modjam.content.items.PrismMonocleItem;
import com.portingdeadmods.modjam.data.MJDataComponents;
import com.portingdeadmods.modjam.registries.MJBlocks;
import com.portingdeadmods.modjam.registries.MJCreativeTabs;
import com.portingdeadmods.modjam.registries.MJItems;
import com.portingdeadmods.modjam.registries.*;
import net.neoforged.neoforge.registries.NewRegistryEvent;
import org.slf4j.Logger;

Expand All @@ -25,12 +23,13 @@ public ModJam(IEventBus modEventBus, ModContainer modContainer) {

MJItems.ITEMS.register(modEventBus);
MJBlocks.BLOCKS.register(modEventBus);
MJFluids.FLUIDS.register(modEventBus);
MJFluidTypes.FLUID_TYPES.register(modEventBus);
MJCreativeTabs.CREATIVE_MODE_TABS.register(modEventBus);
MJDataComponents.DATA_COMPONENT_TYPES.register(modEventBus);

modEventBus.addListener(PrismMonocleItem::registerCapabilities);


modContainer.registerConfig(ModConfig.Type.COMMON, MJConfig.SPEC);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.portingdeadmods.modjam.api.fluids;

import net.minecraft.core.Vec3i;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.neoforge.fluids.FluidType;

public class BaseFluidType extends FluidType {
private final ResourceLocation stillTexture;
private final ResourceLocation flowingTexture;
private final ResourceLocation overlayTexture;
private final Vec3i color;

public BaseFluidType(ResourceLocation stillTexture, ResourceLocation flowingTexture, ResourceLocation overlayTexture, Vec3i color, FluidType.Properties properties) {
super(properties);
this.stillTexture = stillTexture;
this.flowingTexture = flowingTexture;
this.overlayTexture = overlayTexture;
this.color = color;
}

public ResourceLocation getStillTexture() {
return stillTexture;
}

public ResourceLocation getFlowingTexture() {
return flowingTexture;
}

public ResourceLocation getOverlayTexture() {
return overlayTexture;
}

public Vec3i getColor() {
return color;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.block.RotatedPillarBlock;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.neoforged.neoforge.registries.DeferredBlock;
Expand All @@ -21,6 +22,10 @@ public final class MJBlocks {
public static final DeferredBlock<Block> CHISELED_DARK_PRISMARINE = registerBlockAndItem("chiseled_dark_prismarine", Block::new, BlockBehaviour.Properties.ofFullCopy(Blocks.DARK_PRISMARINE));
public static final DeferredBlock<Block> AQUATIC_CATALYST = registerBlockAndItem("aquatic_catalyst", Block::new, BlockBehaviour.Properties.ofFullCopy(Blocks.DARK_PRISMARINE));

public static final DeferredBlock<LiquidBlock> SALT_WATER_FLUID_BLOCK = BLOCKS.register("salt_water_block",
() -> new LiquidBlock(MJFluids.SALT_WATER_SOURCE.get(), BlockBehaviour.Properties.ofFullCopy(Blocks.WATER)));


private static <T extends Block> DeferredBlock<T> registerBlockAndItem(String name, Function<BlockBehaviour.Properties, T> blockConstructor, BlockBehaviour.Properties properties) {
return registerBlockAndItem(name, blockConstructor, properties, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public final class MJCreativeTabs {
for (ItemLike item : MJItems.CREATIVE_TAB_ITEMS) {
output.accept(item);
}

output.accept(MJItems.SALT_WATER_BUCKET);
})
.build());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.portingdeadmods.modjam.registries;

import com.portingdeadmods.modjam.ModJam;
import com.portingdeadmods.modjam.api.fluids.BaseFluidType;
import net.minecraft.core.Vec3i;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
import net.neoforged.neoforge.common.SoundAction;
import net.neoforged.neoforge.fluids.FluidType;
import net.neoforged.neoforge.registries.DeferredRegister;
import net.neoforged.neoforge.registries.NeoForgeRegistries;

import java.util.function.Supplier;

public class MJFluidTypes {

public static final DeferredRegister<FluidType> FLUID_TYPES =
DeferredRegister.create(NeoForgeRegistries.FLUID_TYPES, ModJam.MODID);

public static final Supplier<FluidType> SALT_WATER_FLUID_TYPE = register("soap_water",
FluidType.Properties.create().lightLevel(2).density(15).viscosity(5).sound(SoundAction.get("drink"),
SoundEvents.HONEY_DRINK), new Vec3i(224, 56, 208), FluidTemplate.WATER);


private static Supplier<FluidType> register(String name, FluidType.Properties properties, Vec3i color, FluidTemplate template) {
return FLUID_TYPES.register(name, () -> new BaseFluidType(template.still, template.flowing, template.overlay, color, properties));
}


public enum FluidTemplate {
WATER(ResourceLocation.parse("block/salt_water_still"),
ResourceLocation.parse("block/salt_water_flow"),
ResourceLocation.fromNamespaceAndPath(ModJam.MODID, "misc/in_salt_water"));

private final ResourceLocation still;
private final ResourceLocation flowing;
private final ResourceLocation overlay;

FluidTemplate(ResourceLocation still, ResourceLocation flowing, ResourceLocation overlay) {
this.still = still;
this.flowing = flowing;
this.overlay = overlay;
}
}

}
27 changes: 27 additions & 0 deletions src/main/java/com/portingdeadmods/modjam/registries/MJFluids.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.portingdeadmods.modjam.registries;

import com.portingdeadmods.modjam.ModJam;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.level.material.FlowingFluid;
import net.minecraft.world.level.material.Fluid;
import net.neoforged.neoforge.fluids.BaseFlowingFluid;
import net.neoforged.neoforge.registries.DeferredRegister;

import java.util.function.Supplier;

public class MJFluids {

public static final DeferredRegister<Fluid> FLUIDS =
DeferredRegister.create(Registries.FLUID, ModJam.MODID);

public static final Supplier<FlowingFluid> SALT_WATER_SOURCE = FLUIDS.register("salt_water",
() -> new BaseFlowingFluid.Source(MJFluids.SALT_WATER_PROPERTIES));
public static final Supplier<FlowingFluid> SALT_WATER_FLOWING = FLUIDS.register("salt_water_flowing",
() -> new BaseFlowingFluid.Flowing(MJFluids.SALT_WATER_PROPERTIES));


public static final BaseFlowingFluid.Properties SALT_WATER_PROPERTIES = new BaseFlowingFluid.Properties(
MJFluidTypes.SALT_WATER_FLUID_TYPE, SALT_WATER_SOURCE, SALT_WATER_FLOWING)
.slopeFindDistance(2).levelDecreasePerBlock(2).block(MJBlocks.SALT_WATER_FLUID_BLOCK)
.bucket(MJItems.SALT_WATER_BUCKET);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import com.portingdeadmods.modjam.content.items.ExamplePowerItem;
import com.portingdeadmods.modjam.content.items.PrismMonocleItem;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.BucketItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.ItemLike;
import net.neoforged.neoforge.registries.DeferredItem;
import net.neoforged.neoforge.registries.DeferredRegister;
Expand All @@ -24,10 +26,17 @@ public final class MJItems {
public static final DeferredItem<PrismMonocleItem> PRISM_MONOCLE = registerItem("prism_monocle",
PrismMonocleItem::new, new Item.Properties());

public static final DeferredItem<BucketItem> SALT_WATER_BUCKET = registerItemBucket("salt_water_bucket",
() -> new BucketItem(MJFluids.SALT_WATER_SOURCE.get(), new Item.Properties().craftRemainder(Items.BUCKET).stacksTo(1)));

public static <T extends Item> DeferredItem<T> registerItem(String name, Function<Item.Properties, T> itemConstructor, Item.Properties properties) {
return registerItem(name, itemConstructor, properties, true);
}

private static <T extends Item> DeferredItem<T> registerItemBucket(String name, Supplier<T> item) {
return ITEMS.register(name, item);
}

public static <T extends Item> DeferredItem<T> registerItem(String name, Function<Item.Properties, T> itemConstructor, Item.Properties properties, boolean addToTab) {
DeferredItem<T> toReturn = ITEMS.registerItem(name, itemConstructor, properties);
if (addToTab) {
Expand Down

0 comments on commit 16e2552

Please sign in to comment.