mirror of
https://github.com/architectury/architectury-api.git
synced 2026-03-28 03:56:59 -05:00
Add fluid block and flowing fluid (#251)
[ci skip] Squash of the following commits: * Add way to register fluids and fluid attributes, WIP UNTESTED * Move to correct package * Update forge/build.gradle * Add bucket item wrapper and add test mod * Make it easier to declare attributes by suppliers * Fix fabric support * Change SimpleArchitecturyFluidAttributes to accept Supplier<Optional<T>> * Make ArchitecturyLiquidBlock and ArchitecturyBucketItem accept Supplier * Update testmod * Link javadocs in the builder to make it easier to check * Add ArchitecturyMobBucketItem and fix caps on ArchitecturyBucketItem * Make SimpleArchitecturyFluidAttributes accept wildcard fluids * getContainingFluid -> getContainedFluid * Add supplier variant of the methods Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com> Co-authored-by: Max <maxh2709@gmail.com>
This commit is contained in:
@@ -20,10 +20,12 @@
|
||||
package dev.architectury.test.registry;
|
||||
|
||||
import dev.architectury.core.RegistryEntry;
|
||||
import dev.architectury.core.fluid.ArchitecturyFluidAttributes;
|
||||
import dev.architectury.core.fluid.SimpleArchitecturyFluidAttributes;
|
||||
import dev.architectury.core.item.ArchitecturySpawnEggItem;
|
||||
import dev.architectury.hooks.item.food.FoodPropertiesHooks;
|
||||
import dev.architectury.hooks.level.entity.EntityHooks;
|
||||
import dev.architectury.registry.block.BlockProperties;
|
||||
import dev.architectury.platform.Platform;
|
||||
import dev.architectury.registry.level.entity.EntityAttributeRegistry;
|
||||
import dev.architectury.registry.registries.DeferredRegister;
|
||||
import dev.architectury.registry.registries.Registrar;
|
||||
@@ -50,10 +52,16 @@ import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
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.state.BlockBehaviour;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.FlowingFluid;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import static dev.architectury.test.TestMod.SINK;
|
||||
|
||||
public class TestRegistries {
|
||||
@@ -70,13 +78,23 @@ public class TestRegistries {
|
||||
.build();
|
||||
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(TestMod.MOD_ID, Registry.ITEM_REGISTRY);
|
||||
public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(TestMod.MOD_ID, Registry.BLOCK_REGISTRY);
|
||||
public static final DeferredRegister<Fluid> FLUIDS = DeferredRegister.create(TestMod.MOD_ID, Registry.FLUID_REGISTRY);
|
||||
public static final DeferredRegister<EntityType<?>> ENTITY_TYPES = DeferredRegister.create(TestMod.MOD_ID, Registry.ENTITY_TYPE_REGISTRY);
|
||||
public static final DeferredRegister<MobEffect> MOB_EFFECTS = DeferredRegister.create(TestMod.MOD_ID, Registry.MOB_EFFECT_REGISTRY);
|
||||
public static final DeferredRegister<RecipeSerializer<?>> RECIPE_SERIALIZERS = DeferredRegister.create(TestMod.MOD_ID, Registry.RECIPE_SERIALIZER_REGISTRY);
|
||||
public static final DeferredRegister<RecipeType<?>> RECIPE_TYPES = DeferredRegister.create(TestMod.MOD_ID, Registry.RECIPE_TYPE_REGISTRY);
|
||||
|
||||
public static final ArchitecturyFluidAttributes TEST_FLUID_ATTRIBUTES = SimpleArchitecturyFluidAttributes.ofSupplier(() -> TestRegistries.TEST_FLUID_FLOWING, () -> TestRegistries.TEST_FLUID)
|
||||
.convertToSource(true)
|
||||
.flowingTexture(new ResourceLocation("block/water_flow"))
|
||||
.sourceTexture(new ResourceLocation("block/water_still"))
|
||||
.blockSupplier(() -> TestRegistries.TEST_FLUID_BLOCK)
|
||||
.bucketItemSupplier(() -> TestRegistries.TEST_FLUID_BUCKET)
|
||||
.color(0xFF0000);
|
||||
|
||||
public static final RegistrySupplier<TestInt> TEST_INT = INTS.register(new ResourceLocation(TestMod.MOD_ID, "test_int"), () -> new TestInt(1));
|
||||
public static final RegistrySupplier<TestInt> TEST_INT_2 = INTS.register(new ResourceLocation(TestMod.MOD_ID, "test_int_2"), () -> new TestInt(2));
|
||||
|
||||
public static final RegistrySupplier<MobEffect> TEST_EFFECT = MOB_EFFECTS.register("test_effect", () ->
|
||||
new MobEffect(MobEffectCategory.NEUTRAL, 0x123456) {
|
||||
});
|
||||
@@ -97,10 +115,21 @@ public class TestRegistries {
|
||||
new ArchitecturySpawnEggItem(TestRegistries.TEST_ENTITY_2, 0xFFFFFFFF, 0xFF000000,
|
||||
new Item.Properties().tab(TestCreativeTabs.TEST_TAB)));
|
||||
|
||||
public static final RegistrySupplier<Item> TEST_FLUID_BUCKET = ITEMS.register("test_fluid_bucket", () -> {
|
||||
try {
|
||||
// In example mod the forge class isn't being replaced, this is not required in mods depending on architectury
|
||||
return (Item) Class.forName(!Platform.isForge() ? "dev.architectury.core.item.ArchitecturyBucketItem" : "dev.architectury.core.item.forge.imitator.ArchitecturyBucketItem")
|
||||
.getDeclaredConstructor(RegistrySupplier.class, Item.Properties.class)
|
||||
.newInstance(TestRegistries.TEST_FLUID, new Item.Properties().tab(TestCreativeTabs.TEST_TAB));
|
||||
} catch (InstantiationException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
|
||||
public static final RegistrySupplier<Block> TEST_BLOCK = BLOCKS.register("test_block", () ->
|
||||
new Block(BlockProperties.copy(Blocks.STONE)));
|
||||
new Block(BlockBehaviour.Properties.copy(Blocks.STONE)));
|
||||
public static final RegistrySupplier<Block> COLLISION_BLOCK = BLOCKS.register("collision_block", () ->
|
||||
new Block(BlockProperties.copy(Blocks.STONE)) {
|
||||
new Block(BlockBehaviour.Properties.copy(Blocks.STONE)) {
|
||||
@Override
|
||||
public VoxelShape getCollisionShape(BlockState state, BlockGetter bg, BlockPos pos, CollisionContext ctx) {
|
||||
SINK.accept(EntityHooks.fromCollision(ctx) + " is colliding with " + state);
|
||||
@@ -108,6 +137,39 @@ public class TestRegistries {
|
||||
}
|
||||
});
|
||||
|
||||
public static final RegistrySupplier<LiquidBlock> TEST_FLUID_BLOCK = BLOCKS.register("test_fluid", () -> {
|
||||
try {
|
||||
// In example mod the forge class isn't being replaced, this is not required in mods depending on architectury
|
||||
return (LiquidBlock) Class.forName(!Platform.isForge() ? "dev.architectury.core.block.ArchitecturyLiquidBlock" : "dev.architectury.core.block.forge.imitator.ArchitecturyLiquidBlock")
|
||||
.getDeclaredConstructor(RegistrySupplier.class, BlockBehaviour.Properties.class)
|
||||
.newInstance(TestRegistries.TEST_FLUID, BlockBehaviour.Properties.copy(Blocks.WATER).noCollission().strength(100.0F).noDrops());
|
||||
} catch (InstantiationException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
|
||||
public static final RegistrySupplier<Fluid> TEST_FLUID = FLUIDS.register("test_fluid", () -> {
|
||||
try {
|
||||
// In example mod the forge class isn't being replaced, this is not required in mods depending on architectury
|
||||
return (FlowingFluid) Class.forName(!Platform.isForge() ? "dev.architectury.core.fluid.ArchitecturyFlowingFluid$Source" : "dev.architectury.core.fluid.forge.imitator.ArchitecturyFlowingFluid$Source")
|
||||
.getDeclaredConstructor(ArchitecturyFluidAttributes.class)
|
||||
.newInstance(TestRegistries.TEST_FLUID_ATTRIBUTES);
|
||||
} catch (InstantiationException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
|
||||
public static final RegistrySupplier<Fluid> TEST_FLUID_FLOWING = FLUIDS.register("test_fluid_flowing", () -> {
|
||||
try {
|
||||
// In example mod the forge class isn't being replaced, this is not required in mods depending on architectury
|
||||
return (FlowingFluid) Class.forName(!Platform.isForge() ? "dev.architectury.core.fluid.ArchitecturyFlowingFluid$Flowing" : "dev.architectury.core.fluid.forge.imitator.ArchitecturyFlowingFluid$Flowing")
|
||||
.getDeclaredConstructor(ArchitecturyFluidAttributes.class)
|
||||
.newInstance(TestRegistries.TEST_FLUID_ATTRIBUTES);
|
||||
} catch (InstantiationException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
|
||||
public static final RegistrySupplier<Item> TEST_BLOCK_ITEM = ITEMS.register("test_block", () ->
|
||||
new BlockItem(TEST_BLOCK.get(), new Item.Properties().tab(TestCreativeTabs.TEST_TAB)));
|
||||
public static final RegistrySupplier<Item> COLLISION_BLOCK_ITEM = ITEMS.register("collision_block", () ->
|
||||
@@ -127,6 +189,7 @@ public class TestRegistries {
|
||||
|
||||
public static void initialize() {
|
||||
MOB_EFFECTS.register();
|
||||
FLUIDS.register();
|
||||
BLOCKS.register();
|
||||
ITEMS.register();
|
||||
ENTITY_TYPES.register();
|
||||
|
||||
Reference in New Issue
Block a user