From eaefefdf26ddc28af57a7fdaa47cbcd48807942f Mon Sep 17 00:00:00 2001 From: FirstMegaGame4 <84094287+FirstMegaGame4@users.noreply.github.com> Date: Wed, 15 Nov 2023 18:42:54 +0100 Subject: [PATCH] Add AdvancedBlockSettings Add ImmutableBlockSettings Breaking Changes: Change DefaultBlockSettings Remove BlockSettingsModifiers --- .../settings/AdvancedBlockSettings.java | 317 ++++++++++++++++ .../settings/BlockSettingsModifiers.java | 52 --- .../blocks/settings/DefaultBlockSettings.java | 83 ++--- .../settings/ImmutableBlockSettings.java | 337 ++++++++++++++++++ .../accessors/AbstractBlockAccessor.java | 12 + .../mixin/injectors/BlockEntityTypeMixin.java | 1 - src/main/resources/mmodding_lib.mixins.json | 1 + 7 files changed, 692 insertions(+), 111 deletions(-) create mode 100644 src/main/java/com/mmodding/mmodding_lib/library/blocks/settings/AdvancedBlockSettings.java delete mode 100644 src/main/java/com/mmodding/mmodding_lib/library/blocks/settings/BlockSettingsModifiers.java create mode 100644 src/main/java/com/mmodding/mmodding_lib/library/blocks/settings/ImmutableBlockSettings.java create mode 100644 src/main/java/com/mmodding/mmodding_lib/mixin/accessors/AbstractBlockAccessor.java diff --git a/src/main/java/com/mmodding/mmodding_lib/library/blocks/settings/AdvancedBlockSettings.java b/src/main/java/com/mmodding/mmodding_lib/library/blocks/settings/AdvancedBlockSettings.java new file mode 100644 index 0000000..d858e0c --- /dev/null +++ b/src/main/java/com/mmodding/mmodding_lib/library/blocks/settings/AdvancedBlockSettings.java @@ -0,0 +1,317 @@ +package com.mmodding.mmodding_lib.library.blocks.settings; + +import com.mmodding.mmodding_lib.ducks.AbstractBlockSettingsDuckInterface; +import com.mmodding.mmodding_lib.mixin.accessors.AbstractBlockAccessor; +import com.mmodding.mmodding_lib.mixin.accessors.BlocksAccessor; +import net.minecraft.block.*; +import net.minecraft.entity.EntityType; +import net.minecraft.sound.BlockSoundGroup; +import net.minecraft.util.DyeColor; +import net.minecraft.util.Identifier; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.BlockView; +import org.quiltmc.qsl.block.extensions.api.QuiltBlockSettings; + +import java.util.function.Function; +import java.util.function.ToIntFunction; + +public class AdvancedBlockSettings extends QuiltBlockSettings { + + protected AdvancedBlockSettings(Material material, Function mapColorProvider) { + super(material, mapColorProvider); + } + + protected AdvancedBlockSettings(Material material, MapColor mapColor) { + super(material, mapColor); + } + + protected AdvancedBlockSettings(AbstractBlock.Settings settings) { + super(settings); + this.ducked().mmodding_lib$setTranslucent(this.ducked(settings).mmodding_lib$getTranslucent()); + this.ducked().mmodding_lib$setNotTranslucent(this.ducked(settings).mmodding_lib$getNotTranslucent()); + this.ducked().mmodding_lib$setInvisibleSides(this.ducked(settings).mmodding_lib$getInvisibleSides()); + } + + public static AdvancedBlockSettings of(Material material) { + return AdvancedBlockSettings.of(material, material.getColor()); + } + + public static AdvancedBlockSettings of(Material material, Function mapColorProvider) { + return new AdvancedBlockSettings(material, mapColorProvider); + } + + public static AdvancedBlockSettings of(Material material, MapColor color) { + return new AdvancedBlockSettings(material, color); + } + + public static AdvancedBlockSettings of(Material material, DyeColor color) { + return new AdvancedBlockSettings(material, color.getMapColor()); + } + + public static AdvancedBlockSettings copyOf(AbstractBlock block) { + return new AdvancedBlockSettings(((AbstractBlockAccessor) block).getSettings()); + } + + public static AdvancedBlockSettings copyOf(AbstractBlock.Settings settings) { + return new AdvancedBlockSettings(settings); + } + + public AdvancedBlockSettings translucent() { + this.ducked().mmodding_lib$setTranslucent(true); + return this; + } + + public AdvancedBlockSettings notTranslucent() { + this.ducked().mmodding_lib$setNotTranslucent(true); + return this; + } + + public AdvancedBlockSettings invisibleSides() { + this.ducked().mmodding_lib$setInvisibleSides(true); + return this; + } + + public static boolean always(BlockState state, BlockView world, BlockPos pos) { + return BlocksAccessor.invokeAlways(state, world, pos); + } + + public static boolean never(BlockState state, BlockView world, BlockPos pos) { + return BlocksAccessor.invokeNever(state, world, pos); + } + + @Override + public AdvancedBlockSettings noCollision() { + super.noCollision(); + return this; + } + + @Override + public AdvancedBlockSettings nonOpaque() { + super.nonOpaque(); + return this; + } + + @Override + public AdvancedBlockSettings slipperiness(float slipperiness) { + super.slipperiness(slipperiness); + return this; + } + + @Override + public AdvancedBlockSettings velocityMultiplier(float velocityMultiplier) { + super.velocityMultiplier(velocityMultiplier); + return this; + } + + @Override + public AdvancedBlockSettings jumpVelocityMultiplier(float jumpVelocityMultiplier) { + super.jumpVelocityMultiplier(jumpVelocityMultiplier); + return this; + } + + @Override + public AdvancedBlockSettings sounds(BlockSoundGroup soundGroup) { + super.sounds(soundGroup); + return this; + } + + @Override + public AdvancedBlockSettings luminance(ToIntFunction luminance) { + super.luminance(luminance); + return this; + } + + @Override + public AdvancedBlockSettings strength(float hardness, float resistance) { + super.strength(hardness, resistance); + return this; + } + + @Override + public AdvancedBlockSettings breakInstantly() { + super.breakInstantly(); + return this; + } + + @Override + public AdvancedBlockSettings strength(float strength) { + super.strength(strength); + return this; + } + + @Override + public AdvancedBlockSettings ticksRandomly() { + super.ticksRandomly(); + return this; + } + + @Override + public AdvancedBlockSettings dynamicBounds() { + super.dynamicBounds(); + return this; + } + + @Override + public AdvancedBlockSettings dropsNothing() { + super.dropsNothing(); + return this; + } + + @Override + public AdvancedBlockSettings dropsLike(Block source) { + super.dropsLike(source); + return this; + } + + @Override + public AdvancedBlockSettings air() { + super.air(); + return this; + } + + @Override + public AdvancedBlockSettings allowsSpawning(AbstractBlock.TypedContextPredicate> predicate) { + super.allowsSpawning(predicate); + return this; + } + + @Override + public AdvancedBlockSettings solidBlock(AbstractBlock.ContextPredicate predicate) { + super.solidBlock(predicate); + return this; + } + + @Override + public AdvancedBlockSettings suffocates(AbstractBlock.ContextPredicate predicate) { + super.suffocates(predicate); + return this; + } + + @Override + public AdvancedBlockSettings blockVision(AbstractBlock.ContextPredicate predicate) { + super.blockVision(predicate); + return this; + } + + @Override + public AdvancedBlockSettings postProcess(AbstractBlock.ContextPredicate predicate) { + super.postProcess(predicate); + return this; + } + + @Override + public AdvancedBlockSettings emissiveLighting(AbstractBlock.ContextPredicate predicate) { + super.emissiveLighting(predicate); + return this; + } + + @Override + public AdvancedBlockSettings requiresTool() { + super.requiresTool(); + return this; + } + + @Override + public AdvancedBlockSettings mapColor(MapColor color) { + super.mapColor(color); + return this; + } + + @Override + public AdvancedBlockSettings hardness(float hardness) { + super.hardness(hardness); + return this; + } + + @Override + public AdvancedBlockSettings resistance(float resistance) { + super.resistance(resistance); + return this; + } + + @Override + public AdvancedBlockSettings material(Material material) { + super.material(material); + return this; + } + + @Override + public AdvancedBlockSettings collidable(boolean collidable) { + super.collidable(collidable); + return this; + } + + @Override + public AdvancedBlockSettings opaque(boolean opaque) { + super.opaque(opaque); + return this; + } + + @Override + public AdvancedBlockSettings ticksRandomly(boolean ticksRandomly) { + super.ticksRandomly(ticksRandomly); + return this; + } + + @Override + public AdvancedBlockSettings dynamicBounds(boolean dynamicBounds) { + super.dynamicBounds(dynamicBounds); + return this; + } + + @Override + public AdvancedBlockSettings requiresTool(boolean requiresTool) { + super.requiresTool(requiresTool); + return this; + } + + @Override + public AdvancedBlockSettings air(boolean isAir) { + super.air(isAir); + return this; + } + + @Override + public AdvancedBlockSettings luminance(int luminance) { + super.luminance(luminance); + return this; + } + + @Override + public AdvancedBlockSettings drops(Identifier dropTableId) { + super.drops(dropTableId); + return this; + } + + @Override + public AdvancedBlockSettings mapColor(DyeColor color) { + super.mapColor(color); + return this; + } + + @Override + public AdvancedBlockSettings mapColorProvider(Function mapColorProvider) { + super.mapColorProvider(mapColorProvider); + return this; + } + + @Override + public AdvancedBlockSettings offsetType(AbstractBlock.OffsetType offset) { + super.offsetType(offset); + return this; + } + + @Override + public AdvancedBlockSettings offsetType(Function function) { + super.offsetType(function); + return this; + } + + private AbstractBlockSettingsDuckInterface ducked(AbstractBlock.Settings settings) { + return (AbstractBlockSettingsDuckInterface) settings; + } + + private AbstractBlockSettingsDuckInterface ducked() { + return this.ducked(this); + } +} diff --git a/src/main/java/com/mmodding/mmodding_lib/library/blocks/settings/BlockSettingsModifiers.java b/src/main/java/com/mmodding/mmodding_lib/library/blocks/settings/BlockSettingsModifiers.java deleted file mode 100644 index 2f3bf37..0000000 --- a/src/main/java/com/mmodding/mmodding_lib/library/blocks/settings/BlockSettingsModifiers.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.mmodding.mmodding_lib.library.blocks.settings; - -import com.mmodding.mmodding_lib.ducks.AbstractBlockSettingsDuckInterface; -import com.mmodding.mmodding_lib.mixin.accessors.BlocksAccessor; -import net.minecraft.block.BlockState; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.BlockView; -import org.quiltmc.qsl.block.extensions.api.QuiltBlockSettings; - -public class BlockSettingsModifiers { - - private final QuiltBlockSettings settings; - - private BlockSettingsModifiers(QuiltBlockSettings settings) { - this.settings = settings; - } - - public static BlockSettingsModifiers ofSettings(QuiltBlockSettings settings) { - return new BlockSettingsModifiers(settings); - } - - public QuiltBlockSettings toSettings() { - return this.settings; - } - - private AbstractBlockSettingsDuckInterface ducked() { - return (AbstractBlockSettingsDuckInterface) this.settings; - } - - public BlockSettingsModifiers translucent() { - this.ducked().mmodding_lib$setTranslucent(true); - return this; - } - - public BlockSettingsModifiers notTranslucent() { - this.ducked().mmodding_lib$setNotTranslucent(true); - return this; - } - - public BlockSettingsModifiers invisibleSides() { - this.ducked().mmodding_lib$setInvisibleSides(true); - return this; - } - - public static boolean always(BlockState state, BlockView world, BlockPos pos) { - return BlocksAccessor.invokeAlways(state, world, pos); - } - - public static boolean never(BlockState state, BlockView world, BlockPos pos) { - return BlocksAccessor.invokeNever(state, world, pos); - } -} diff --git a/src/main/java/com/mmodding/mmodding_lib/library/blocks/settings/DefaultBlockSettings.java b/src/main/java/com/mmodding/mmodding_lib/library/blocks/settings/DefaultBlockSettings.java index f25caeb..515ba14 100644 --- a/src/main/java/com/mmodding/mmodding_lib/library/blocks/settings/DefaultBlockSettings.java +++ b/src/main/java/com/mmodding/mmodding_lib/library/blocks/settings/DefaultBlockSettings.java @@ -2,64 +2,31 @@ import net.minecraft.block.Material; import net.minecraft.sound.BlockSoundGroup; -import org.quiltmc.qsl.block.extensions.api.QuiltBlockSettings; -public enum DefaultBlockSettings { - STONE_SETTINGS, - DEEPSLATE_SETTINGS, - BEDROCK_SETTINGS, - DEEP_BEDROCK_SETTINGS, - WOOD_SETTINGS, - DIRT_SETTINGS, - GRASS_SETTINGS, - PLANT_SETTINGS, - SAPLING_SETTINGS, - REPLACEABLE_PLANT_SETTINGS, - LEAVES_SETTINGS, - SNOW_SETTINGS, - SNOW_BLOCK_SETTINGS, - METAL_SETTINGS, - AMETHYST_SETTINGS, - AMETHYST_CLUSTER_SETTINGS, - BONE_SETTINGS, - GLASS_SETTINGS, - SAND_SETTINGS, - CLAY_SETTINGS, - BASALT_SETTINGS, - LODESTONE_SETTINGS, - LEAVES_CARPET, - NETHERITE_SETTINGS; +public class DefaultBlockSettings { - public static QuiltBlockSettings ofDefault(DefaultBlockSettings defaultBlockSettings) { - return switch (defaultBlockSettings) { - case STONE_SETTINGS -> QuiltBlockSettings.of(Material.STONE).sounds(BlockSoundGroup.STONE).strength(1.5f, 6.0f).requiresTool(); - case DEEPSLATE_SETTINGS -> QuiltBlockSettings.of(Material.STONE).sounds(BlockSoundGroup.DEEPSLATE).strength(3.0f, 6.0f).requiresTool(); - case BEDROCK_SETTINGS -> QuiltBlockSettings.of(Material.STONE).sounds(BlockSoundGroup.STONE).strength(-1.0F, 3600000.0F).dropsNothing().allowsSpawning((state, world, pos, type) -> false); - case DEEP_BEDROCK_SETTINGS -> QuiltBlockSettings.of(Material.STONE).sounds(BlockSoundGroup.DEEPSLATE).strength(-1.0F, 3600000.0F).dropsNothing().allowsSpawning((state, world, pos, type) -> false); - case WOOD_SETTINGS -> QuiltBlockSettings.of(Material.WOOD).sounds(BlockSoundGroup.WOOD).strength(2.0f); - case DIRT_SETTINGS -> QuiltBlockSettings.of(Material.SOIL).sounds(BlockSoundGroup.GRAVEL).strength(0.5f); - case GRASS_SETTINGS -> QuiltBlockSettings.of(Material.SOIL).sounds(BlockSoundGroup.GRASS).strength(0.6f); - case SAPLING_SETTINGS -> QuiltBlockSettings.of(Material.PLANT).noCollision().ticksRandomly().breakInstantly().sounds(BlockSoundGroup.GRASS); - case PLANT_SETTINGS -> QuiltBlockSettings.of(Material.PLANT).sounds(BlockSoundGroup.GRASS).noCollision().breakInstantly(); - case REPLACEABLE_PLANT_SETTINGS -> QuiltBlockSettings.of(Material.REPLACEABLE_PLANT).sounds(BlockSoundGroup.GRASS).noCollision().breakInstantly(); - case LEAVES_SETTINGS -> QuiltBlockSettings.of(Material.LEAVES).sounds(BlockSoundGroup.GRASS).nonOpaque().strength(0.2f); - case SNOW_SETTINGS -> QuiltBlockSettings.of(Material.SNOW_LAYER).sounds(BlockSoundGroup.SNOW).nonOpaque().strength(0.1f); - case SNOW_BLOCK_SETTINGS -> QuiltBlockSettings.of(Material.SNOW_BLOCK).sounds(BlockSoundGroup.SNOW).strength(0.1f); - case METAL_SETTINGS -> QuiltBlockSettings.of(Material.METAL).sounds(BlockSoundGroup.METAL).strength(5.0f, 6.0f); - case AMETHYST_SETTINGS -> QuiltBlockSettings.of(Material.AMETHYST).sounds(BlockSoundGroup.AMETHYST_BLOCK).strength(1.5f).requiresTool(); - case AMETHYST_CLUSTER_SETTINGS -> QuiltBlockSettings.of(Material.AMETHYST).sounds(BlockSoundGroup.AMETHYST_CLUSTER).strength(1.5f).requiresTool(); - case BONE_SETTINGS -> QuiltBlockSettings.of(Material.STONE).sounds(BlockSoundGroup.BONE).strength(2.0f); - case GLASS_SETTINGS -> QuiltBlockSettings.of(Material.GLASS).sounds(BlockSoundGroup.GLASS).nonOpaque().strength(0.3f); - case SAND_SETTINGS -> QuiltBlockSettings.of(Material.AGGREGATE).sounds(BlockSoundGroup.SAND).strength(0.5f); - case CLAY_SETTINGS -> QuiltBlockSettings.of(Material.ORGANIC_PRODUCT).sounds(BlockSoundGroup.SAND).strength(0.6f); - case BASALT_SETTINGS -> QuiltBlockSettings.of(Material.STONE).sounds(BlockSoundGroup.BASALT).strength(1.25f, 4.2f).requiresTool(); - case LODESTONE_SETTINGS -> QuiltBlockSettings.of(Material.STONE).sounds(BlockSoundGroup.LODESTONE); - case LEAVES_CARPET -> QuiltBlockSettings.of(Material.CARPET).sounds(BlockSoundGroup.GRASS).nonOpaque().strength(0.2f); - case NETHERITE_SETTINGS -> QuiltBlockSettings.of(Material.METAL).sounds(BlockSoundGroup.NETHERITE).strength(50.0f, 1200.0f); - }; - } - - public static BlockSettingsModifiers ofDefaultForModifiers(DefaultBlockSettings defaultBlockSettings) { - return BlockSettingsModifiers.ofSettings(DefaultBlockSettings.ofDefault(defaultBlockSettings)); - } + public static final ImmutableBlockSettings STONE_SETTINGS = ImmutableBlockSettings.of(Material.STONE).sounds(BlockSoundGroup.STONE).strength(1.5f, 6.0f).requiresTool(); + public static final ImmutableBlockSettings DEEPSLATE_SETTINGS = ImmutableBlockSettings.of(Material.STONE).sounds(BlockSoundGroup.DEEPSLATE).strength(3.0f, 6.0f).requiresTool(); + public static final ImmutableBlockSettings BEDROCK_SETTINGS = ImmutableBlockSettings.of(Material.STONE).sounds(BlockSoundGroup.STONE).strength(-1.0F, 3600000.0F).dropsNothing().allowsSpawning((state, world, pos, type) -> false); + public static final ImmutableBlockSettings DEEP_BEDROCK_SETTINGS = ImmutableBlockSettings.of(Material.STONE).sounds(BlockSoundGroup.DEEPSLATE).strength(-1.0F, 3600000.0F).dropsNothing().allowsSpawning((state, world, pos, type) -> false); + public static final ImmutableBlockSettings WOOD_SETTINGS = ImmutableBlockSettings.of(Material.WOOD).sounds(BlockSoundGroup.WOOD).strength(2.0f); + public static final ImmutableBlockSettings DIRT_SETTINGS = ImmutableBlockSettings.of(Material.SOIL).sounds(BlockSoundGroup.GRAVEL).strength(0.5f); + public static final ImmutableBlockSettings GRASS_SETTINGS = ImmutableBlockSettings.of(Material.SOIL).sounds(BlockSoundGroup.GRASS).strength(0.6f); + public static final ImmutableBlockSettings PLANT_SETTINGS = ImmutableBlockSettings.of(Material.PLANT).noCollision().ticksRandomly().breakInstantly().sounds(BlockSoundGroup.GRASS); + public static final ImmutableBlockSettings SAPLING_SETTINGS = ImmutableBlockSettings.of(Material.PLANT).sounds(BlockSoundGroup.GRASS).noCollision().breakInstantly(); + public static final ImmutableBlockSettings REPLACEABLE_PLANT_SETTINGS = ImmutableBlockSettings.of(Material.REPLACEABLE_PLANT).sounds(BlockSoundGroup.GRASS).noCollision().breakInstantly(); + public static final ImmutableBlockSettings LEAVES_SETTINGS = ImmutableBlockSettings.of(Material.LEAVES).sounds(BlockSoundGroup.GRASS).nonOpaque().strength(0.2f); + public static final ImmutableBlockSettings SNOW_SETTINGS = ImmutableBlockSettings.of(Material.SNOW_LAYER).sounds(BlockSoundGroup.SNOW).nonOpaque().strength(0.1f); + public static final ImmutableBlockSettings SNOW_BLOCK_SETTINGS = ImmutableBlockSettings.of(Material.SNOW_BLOCK).sounds(BlockSoundGroup.SNOW).strength(0.1f); + public static final ImmutableBlockSettings METAL_SETTINGS = ImmutableBlockSettings.of(Material.METAL).sounds(BlockSoundGroup.METAL).strength(5.0f, 6.0f); + public static final ImmutableBlockSettings AMETHYST_SETTINGS = ImmutableBlockSettings.of(Material.AMETHYST).sounds(BlockSoundGroup.AMETHYST_BLOCK).strength(1.5f).requiresTool(); + public static final ImmutableBlockSettings AMETHYST_CLUSTER_SETTINGS = ImmutableBlockSettings.of(Material.AMETHYST).sounds(BlockSoundGroup.AMETHYST_CLUSTER).strength(1.5f).requiresTool(); + public static final ImmutableBlockSettings BONE_SETTINGS = ImmutableBlockSettings.of(Material.STONE).sounds(BlockSoundGroup.BONE).strength(2.0f); + public static final ImmutableBlockSettings GLASS_SETTINGS = ImmutableBlockSettings.of(Material.GLASS).sounds(BlockSoundGroup.GLASS).nonOpaque().strength(0.3f); + public static final ImmutableBlockSettings SAND_SETTINGS = ImmutableBlockSettings.of(Material.AGGREGATE).sounds(BlockSoundGroup.SAND).strength(0.5f); + public static final ImmutableBlockSettings CLAY_SETTINGS = ImmutableBlockSettings.of(Material.ORGANIC_PRODUCT).sounds(BlockSoundGroup.SAND).strength(0.6f); + public static final ImmutableBlockSettings BASALT_SETTINGS = ImmutableBlockSettings.of(Material.STONE).sounds(BlockSoundGroup.BASALT).strength(1.25f, 4.2f).requiresTool(); + public static final ImmutableBlockSettings LODESTONE_SETTINGS = ImmutableBlockSettings.of(Material.STONE).sounds(BlockSoundGroup.LODESTONE); + public static final ImmutableBlockSettings LEAVES_CARPET = ImmutableBlockSettings.of(Material.CARPET).sounds(BlockSoundGroup.GRASS).nonOpaque().strength(0.2f); + public static final ImmutableBlockSettings NETHERITE_SETTINGS = ImmutableBlockSettings.of(Material.METAL).sounds(BlockSoundGroup.NETHERITE).strength(50.0f, 1200.0f); } diff --git a/src/main/java/com/mmodding/mmodding_lib/library/blocks/settings/ImmutableBlockSettings.java b/src/main/java/com/mmodding/mmodding_lib/library/blocks/settings/ImmutableBlockSettings.java new file mode 100644 index 0000000..a3b0dce --- /dev/null +++ b/src/main/java/com/mmodding/mmodding_lib/library/blocks/settings/ImmutableBlockSettings.java @@ -0,0 +1,337 @@ +package com.mmodding.mmodding_lib.library.blocks.settings; + +import com.mmodding.mmodding_lib.mixin.accessors.AbstractBlockAccessor; +import net.minecraft.block.*; +import net.minecraft.entity.EntityType; +import net.minecraft.sound.BlockSoundGroup; +import net.minecraft.util.DyeColor; +import net.minecraft.util.Identifier; + +import java.util.function.Function; +import java.util.function.ToIntFunction; + +public class ImmutableBlockSettings extends AdvancedBlockSettings { + + protected ImmutableBlockSettings(Material material, Function mapColorProvider) { + super(material, mapColorProvider); + } + + protected ImmutableBlockSettings(Material material, MapColor mapColor) { + super(material, mapColor); + } + + protected ImmutableBlockSettings(AbstractBlock.Settings settings) { + super(settings); + } + + public static ImmutableBlockSettings of(Material material) { + return ImmutableBlockSettings.of(material, material.getColor()); + } + + public static ImmutableBlockSettings of(Material material, Function mapColorProvider) { + return new ImmutableBlockSettings(material, mapColorProvider); + } + + public static ImmutableBlockSettings of(Material material, MapColor color) { + return new ImmutableBlockSettings(material, color); + } + + public static ImmutableBlockSettings of(Material material, DyeColor color) { + return new ImmutableBlockSettings(material, color.getMapColor()); + } + + public static ImmutableBlockSettings copyOf(AbstractBlock block) { + return new ImmutableBlockSettings(((AbstractBlockAccessor) block).getSettings()); + } + + public static ImmutableBlockSettings copyOf(AbstractBlock.Settings settings) { + return new ImmutableBlockSettings(settings); + } + + @Override + public ImmutableBlockSettings translucent() { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.translucent(); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings notTranslucent() { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.notTranslucent(); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings invisibleSides() { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.invisibleSides(); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings noCollision() { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.noCollision(); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings nonOpaque() { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.nonOpaque(); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings slipperiness(float slipperiness) { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.slipperiness(slipperiness); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings velocityMultiplier(float velocityMultiplier) { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.velocityMultiplier(velocityMultiplier); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings jumpVelocityMultiplier(float jumpVelocityMultiplier) { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.jumpVelocityMultiplier(jumpVelocityMultiplier); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings sounds(BlockSoundGroup soundGroup) { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.sounds(soundGroup); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings luminance(ToIntFunction luminance) { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.luminance(luminance); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings strength(float hardness, float resistance) { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.strength(hardness, resistance); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings breakInstantly() { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.breakInstantly(); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings strength(float strength) { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.strength(strength); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings ticksRandomly() { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.ticksRandomly(); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings dynamicBounds() { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.dynamicBounds(); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings dropsNothing() { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.dropsNothing(); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings dropsLike(Block source) { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.dropsLike(source); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings air() { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.air(); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings allowsSpawning(AbstractBlock.TypedContextPredicate> predicate) { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.allowsSpawning(predicate); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings solidBlock(AbstractBlock.ContextPredicate predicate) { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.solidBlock(predicate); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings suffocates(AbstractBlock.ContextPredicate predicate) { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.suffocates(predicate); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings blockVision(AbstractBlock.ContextPredicate predicate) { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.blockVision(predicate); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings postProcess(AbstractBlock.ContextPredicate predicate) { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.postProcess(predicate); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings emissiveLighting(AbstractBlock.ContextPredicate predicate) { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.emissiveLighting(predicate); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings requiresTool() { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.requiresTool(); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings mapColor(MapColor color) { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.mapColor(color); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings hardness(float hardness) { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.hardness(hardness); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings resistance(float resistance) { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.resistance(resistance); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings material(Material material) { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.material(material); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings collidable(boolean collidable) { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.collidable(collidable); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings opaque(boolean opaque) { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.opaque(opaque); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings ticksRandomly(boolean ticksRandomly) { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.ticksRandomly(ticksRandomly); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings dynamicBounds(boolean dynamicBounds) { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.dynamicBounds(dynamicBounds); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings requiresTool(boolean requiresTool) { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.requiresTool(requiresTool); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings air(boolean isAir) { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.air(isAir); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings luminance(int luminance) { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.luminance(luminance); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings drops(Identifier dropTableId) { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.drops(dropTableId); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings mapColor(DyeColor color) { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.mapColor(color); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings mapColorProvider(Function mapColorProvider) { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.mapColorProvider(mapColorProvider); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings offsetType(AbstractBlock.OffsetType offset) { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.offsetType(offset); + return ImmutableBlockSettings.copyOf(settings); + } + + @Override + public ImmutableBlockSettings offsetType(Function function) { + AdvancedBlockSettings settings = AdvancedBlockSettings.copyOf(this); + settings.offsetType(function); + return ImmutableBlockSettings.copyOf(settings); + } +} diff --git a/src/main/java/com/mmodding/mmodding_lib/mixin/accessors/AbstractBlockAccessor.java b/src/main/java/com/mmodding/mmodding_lib/mixin/accessors/AbstractBlockAccessor.java new file mode 100644 index 0000000..8427c8a --- /dev/null +++ b/src/main/java/com/mmodding/mmodding_lib/mixin/accessors/AbstractBlockAccessor.java @@ -0,0 +1,12 @@ +package com.mmodding.mmodding_lib.mixin.accessors; + +import net.minecraft.block.AbstractBlock; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(AbstractBlock.class) +public interface AbstractBlockAccessor { + + @Accessor + AbstractBlock.Settings getSettings(); +} diff --git a/src/main/java/com/mmodding/mmodding_lib/mixin/injectors/BlockEntityTypeMixin.java b/src/main/java/com/mmodding/mmodding_lib/mixin/injectors/BlockEntityTypeMixin.java index 65fb416..b3d768e 100644 --- a/src/main/java/com/mmodding/mmodding_lib/mixin/injectors/BlockEntityTypeMixin.java +++ b/src/main/java/com/mmodding/mmodding_lib/mixin/injectors/BlockEntityTypeMixin.java @@ -4,7 +4,6 @@ import com.mmodding.mmodding_lib.library.blockentities.BlockEntityTypeBlockSupportCallback; import net.minecraft.block.Block; import net.minecraft.block.BlockState; -import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntityType; import org.quiltmc.qsl.base.api.event.Event; import org.spongepowered.asm.mixin.Mixin; diff --git a/src/main/resources/mmodding_lib.mixins.json b/src/main/resources/mmodding_lib.mixins.json index f36b551..a29d252 100644 --- a/src/main/resources/mmodding_lib.mixins.json +++ b/src/main/resources/mmodding_lib.mixins.json @@ -4,6 +4,7 @@ "package": "com.mmodding.mmodding_lib.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ + "accessors.AbstractBlockAccessor", "accessors.AreaHelperAccessor", "accessors.BlockEntityTypeBuilderAccessor", "accessors.BlocksAccessor",