Merge remote-tracking branch 'architectury/1.18.2' into 1.19

# Conflicts:
#	gradle.properties
#	testmod-common/src/main/java/dev/architectury/test/item/TestBlockInteractions.java
This commit is contained in:
shedaniel
2022-05-13 07:13:53 +08:00
33 changed files with 2712 additions and 69 deletions

View File

@@ -30,28 +30,21 @@ import net.minecraft.world.level.block.Blocks;
public final class TestBlockInteractions {
private TestBlockInteractions() {
}
public static void init() {
AxeItemHooks.addStrippable(Blocks.QUARTZ_PILLAR, Blocks.OAK_LOG);
ShovelItemHooks.addFlattenable(Blocks.IRON_ORE, Blocks.DIAMOND_BLOCK.defaultBlockState());
HoeItemHooks.addTillable(Blocks.COAL_BLOCK, ctx -> {
if (!ctx.getLevel().isNight()) {
if (!ctx.getLevel().isClientSide) {
Player player = ctx.getPlayer();
if (player != null)
player.sendSystemMessage(Component.literal("These dark arts can only be done at night!"));
}
return false;
}
return true;
return ctx.getLevel().isNight();
}, ctx -> {
BlockPos pos = ctx.getClickedPos();
ctx.getLevel().setBlock(pos, Blocks.DIAMOND_BLOCK.defaultBlockState(), 3);
if (!ctx.getLevel().isClientSide) {
Player player = ctx.getPlayer();
if (player != null)
player.sendSystemMessage(Component.literal("Thou has successfully committed the dark arts of alchemy!!"));
}
}, ctx -> {
return Blocks.DIAMOND_BLOCK.defaultBlockState();
});
}
}

View File

@@ -19,12 +19,17 @@
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;
import dev.architectury.registry.registries.Registries;
import dev.architectury.registry.registries.RegistrySupplier;
import dev.architectury.test.TestMod;
import dev.architectury.test.entity.TestEntity;
@@ -33,6 +38,7 @@ import dev.architectury.test.registry.objects.EquippableTickingItem;
import dev.architectury.test.tab.TestCreativeTabs;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectCategory;
import net.minecraft.world.effect.MobEffectInstance;
@@ -46,20 +52,50 @@ 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 java.util.function.Supplier;
import static dev.architectury.test.TestMod.SINK;
public class TestRegistries {
public static final class TestInt extends RegistryEntry<TestInt> {
public final int value;
public TestInt(int value) {
this.value = value;
}
}
public static final Registrar<TestInt> INTS = Registries.get(TestMod.MOD_ID).<TestInt>builder(new ResourceLocation(TestMod.MOD_ID, "ints"))
.syncToClients()
.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) {
});
@@ -80,10 +116,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(Supplier.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);
@@ -91,6 +138,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(Supplier.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", () ->
@@ -110,6 +190,7 @@ public class TestRegistries {
public static void initialize() {
MOB_EFFECTS.register();
FLUIDS.register();
BLOCKS.register();
ITEMS.register();
ENTITY_TYPES.register();