diff --git a/src/main/java/ru/betterend/blocks/VanillaBlockProperties.java b/src/main/java/ru/betterend/blocks/VanillaBlockProperties.java deleted file mode 100644 index 1afa178f..00000000 --- a/src/main/java/ru/betterend/blocks/VanillaBlockProperties.java +++ /dev/null @@ -1,7 +0,0 @@ -package ru.betterend.blocks; - -import net.minecraft.world.level.block.state.properties.BooleanProperty; - -public class VanillaBlockProperties { - public static final BooleanProperty ROOTS = BooleanProperty.create("roots"); -} diff --git a/src/main/java/ru/betterend/client/BetterEndClient.java b/src/main/java/ru/betterend/client/BetterEndClient.java index fe830f65..44be312b 100644 --- a/src/main/java/ru/betterend/client/BetterEndClient.java +++ b/src/main/java/ru/betterend/client/BetterEndClient.java @@ -1,10 +1,12 @@ package ru.betterend.client; import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Style; import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.block.Block; import ru.bclib.BCLib; import ru.bclib.blocks.BaseChestBlock; @@ -22,13 +24,13 @@ import ru.betterend.registry.EndEntitiesRenders; import ru.betterend.registry.EndModelProviders; import ru.betterend.registry.EndParticles; import ru.betterend.registry.EndScreens; +import ru.betterend.world.generator.GeneratorOptions; import java.util.List; public class BetterEndClient implements ClientModInitializer { @Override public void onInitializeClient() { - //registerRenderLayers(); EndBlockEntityRenders.register(); EndScreens.register(); EndParticles.register(); @@ -42,6 +44,22 @@ public class BetterEndClient implements ClientModInitializer { TranslationHelper.printMissingEnNames(BetterEnd.MOD_ID); TranslationHelper.printMissingNames(BetterEnd.MOD_ID, "ru_ru"); } + + ResourceLocation checkFlowerId = new ResourceLocation("item/chorus_flower"); + ResourceLocation checkPlantId = new ResourceLocation("item/chorus_plant"); + ResourceLocation toLoadFlowerId = new ResourceLocation("betterend", "item/custom_chorus_flower"); + ResourceLocation toLoadPlantId = new ResourceLocation("betterend", "item/custom_chorus_plant"); + ModelLoadingRegistry.INSTANCE.registerResourceProvider(manager -> (resourceId, context) -> { + if (GeneratorOptions.changeChorusPlant()) { + if (resourceId.equals(checkFlowerId)) { + return context.loadModel(toLoadFlowerId); + } + else if (resourceId.equals(checkPlantId)) { + return context.loadModel(toLoadPlantId); + } + } + return null; + }); } public static void registerTooltips() { diff --git a/src/main/java/ru/betterend/mixin/client/ModelLoaderMixin.java b/src/main/java/ru/betterend/mixin/client/ModelLoaderMixin.java index 04c66042..0c89dd50 100644 --- a/src/main/java/ru/betterend/mixin/client/ModelLoaderMixin.java +++ b/src/main/java/ru/betterend/mixin/client/ModelLoaderMixin.java @@ -5,20 +5,24 @@ import net.minecraft.resources.ResourceLocation; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyVariable; +import ru.betterend.BetterEnd; import ru.betterend.world.generator.GeneratorOptions; @Mixin(ModelBakery.class) public abstract class ModelLoaderMixin { - @ModifyVariable(method = "loadModel", ordinal = 2, at = @At(value = "INVOKE")) public ResourceLocation be_switchModel(ResourceLocation id) { - if (GeneratorOptions.changeChorusPlant() && id.getNamespace().equals("minecraft") && id.getPath() - .startsWith( - "blockstates/") && id - .getPath() - .contains("chorus") && !id.getPath().contains("custom_")) { - id = new ResourceLocation(id.getPath().replace("chorus", "custom_chorus")); + if (GeneratorOptions.changeChorusPlant() && be_changeModel(id)) { + String path = id.getPath().replace("chorus", "custom_chorus"); + id = BetterEnd.makeID(path); } return id; } + + private boolean be_changeModel(ResourceLocation id) { + return id.getNamespace().equals("minecraft") + && id.getPath().startsWith("blockstates/") + && id.getPath().contains("chorus") + && !id.getPath().contains("custom_"); + } } diff --git a/src/main/java/ru/betterend/mixin/common/ChorusFlowerBlockMixin.java b/src/main/java/ru/betterend/mixin/common/ChorusFlowerBlockMixin.java index 9e5c8bda..662eb096 100644 --- a/src/main/java/ru/betterend/mixin/common/ChorusFlowerBlockMixin.java +++ b/src/main/java/ru/betterend/mixin/common/ChorusFlowerBlockMixin.java @@ -25,7 +25,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import ru.bclib.api.TagAPI; import ru.bclib.util.BlocksHelper; -import ru.betterend.blocks.VanillaBlockProperties; import ru.betterend.registry.EndBlocks; import ru.betterend.world.generator.GeneratorOptions; @@ -64,19 +63,14 @@ public abstract class ChorusFlowerBlockMixin extends Block { BlocksHelper.setWithoutUpdate( world, pos, - plant.defaultBlockState() - .setValue(ChorusPlantBlock.UP, true) - .setValue(ChorusPlantBlock.DOWN, true) - .setValue(VanillaBlockProperties.ROOTS, true) + plant.defaultBlockState().setValue(ChorusPlantBlock.UP, true).setValue(ChorusPlantBlock.DOWN, true) ); } else { BlocksHelper.setWithoutUpdate( world, pos, - plant.defaultBlockState() - .setValue(ChorusPlantBlock.UP, true) - .setValue(ChorusPlantBlock.DOWN, true) + plant.defaultBlockState().setValue(ChorusPlantBlock.UP, true).setValue(ChorusPlantBlock.DOWN, true) ); } info.cancel(); @@ -85,26 +79,8 @@ public abstract class ChorusFlowerBlockMixin extends Block { } } - @Inject(method = "generatePlant", at = @At("RETURN"), cancellable = true) - private static void be_generatePlant(LevelAccessor world, BlockPos pos, Random random, int size, CallbackInfo info) { - BlockState state = world.getBlockState(pos); - if (GeneratorOptions.changeChorusPlant() && state.is(Blocks.CHORUS_PLANT)) { - BlocksHelper.setWithoutUpdate(world, pos, state.setValue(VanillaBlockProperties.ROOTS, true)); - } - } - @Shadow - private static boolean allNeighborsEmpty(LevelReader world, BlockPos pos, @Nullable Direction exceptDirection) { - return false; - } - - @Shadow - private void placeGrownFlower(Level world, BlockPos pos, int age) { - } - - @Shadow - private void placeDeadFlower(Level world, BlockPos pos) { - } + private void placeGrownFlower(Level world, BlockPos pos, int age) {} @Override public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) { diff --git a/src/main/java/ru/betterend/mixin/common/ChorusPlantBlockMixin.java b/src/main/java/ru/betterend/mixin/common/ChorusPlantBlockMixin.java index 26a233d0..74cfac6d 100644 --- a/src/main/java/ru/betterend/mixin/common/ChorusPlantBlockMixin.java +++ b/src/main/java/ru/betterend/mixin/common/ChorusPlantBlockMixin.java @@ -10,19 +10,14 @@ import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.ChorusPlantBlock; -import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BlockStateProperties; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import ru.bclib.api.TagAPI; -import ru.betterend.blocks.VanillaBlockProperties; import ru.betterend.registry.EndBlocks; -import ru.betterend.world.generator.GeneratorOptions; @Mixin(value = ChorusPlantBlock.class, priority = 100) public abstract class ChorusPlantBlockMixin extends Block { @@ -30,58 +25,21 @@ public abstract class ChorusPlantBlockMixin extends Block { super(settings); } - @Inject(method = "*", at = @At("TAIL")) - private void beOnInit(BlockBehaviour.Properties settings, CallbackInfo info) { - if (GeneratorOptions.changeChorusPlant()) { - this.registerDefaultState(this.defaultBlockState().setValue(VanillaBlockProperties.ROOTS, false)); - } - } - - @Inject(method = "createBlockStateDefinition", at = @At("TAIL")) - private void be_createBlockStateDefinition(StateDefinition.Builder builder, CallbackInfo info) { - GeneratorOptions.init(); - if (GeneratorOptions.changeChorusPlant()) { - builder.add(VanillaBlockProperties.ROOTS); - } - } - @Inject(method = "getStateForPlacement(Lnet/minecraft/world/item/context/BlockPlaceContext;)Lnet/minecraft/world/level/block/state/BlockState;", at = @At("RETURN"), cancellable = true) private void be_getStateForPlacement(BlockPlaceContext ctx, CallbackInfoReturnable info) { BlockPos pos = ctx.getClickedPos(); Level world = ctx.getLevel(); BlockState plant = info.getReturnValue(); if (ctx.canPlace() && plant.is(Blocks.CHORUS_PLANT) && world.getBlockState(pos.below()).is(TagAPI.BLOCK_END_GROUND)) { - if (GeneratorOptions.changeChorusPlant()) { - info.setReturnValue(plant.setValue(VanillaBlockProperties.ROOTS, true) - .setValue(BlockStateProperties.DOWN, true)); - } - else { - info.setReturnValue(plant.setValue(BlockStateProperties.DOWN, true)); - } - info.cancel(); + info.setReturnValue(plant.setValue(BlockStateProperties.DOWN, true)); } } @Inject(method = "Lnet/minecraft/world/level/block/ChorusPlantBlock;getStateForPlacement" + "(Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/core/BlockPos;)" + "Lnet/minecraft/world/level/block/state/BlockState;", at = @At("RETURN"), cancellable = true) private void be_getStateForPlacement(BlockGetter blockGetter, BlockPos blockPos, CallbackInfoReturnable info) { BlockState plant = info.getReturnValue(); - if (plant.is(Blocks.CHORUS_PLANT)) { - if (blockGetter.getBlockState(blockPos.below()).is(TagAPI.BLOCK_END_GROUND)) { - if (GeneratorOptions.changeChorusPlant()) { - info.setReturnValue(plant.setValue(BlockStateProperties.DOWN, true) - .setValue(VanillaBlockProperties.ROOTS, true)); - } - else { - info.setReturnValue(plant.setValue(BlockStateProperties.DOWN, true)); - } - info.cancel(); - } - else { - if (GeneratorOptions.changeChorusPlant()) { - info.setReturnValue(plant.setValue(VanillaBlockProperties.ROOTS, false)); - } - info.cancel(); - } + if (plant.is(Blocks.CHORUS_PLANT) && blockGetter.getBlockState(blockPos.below()).is(TagAPI.BLOCK_END_GROUND)) { + info.setReturnValue(plant.setValue(BlockStateProperties.DOWN, true)); } } @@ -90,32 +48,15 @@ public abstract class ChorusPlantBlockMixin extends Block { BlockState down = world.getBlockState(pos.below()); if (down.is(EndBlocks.CHORUS_NYLIUM) || down.is(Blocks.END_STONE)) { info.setReturnValue(true); - info.cancel(); } } @Inject(method = "updateShape", at = @At("RETURN"), cancellable = true) private void be_updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, BlockPos pos, BlockPos posFrom, CallbackInfoReturnable info) { BlockState plant = info.getReturnValue(); - if (plant.is(Blocks.CHORUS_PLANT)) { - if (world.getBlockState(pos.below()).is(TagAPI.BLOCK_END_GROUND)) { - if (GeneratorOptions.changeChorusPlant()) { - plant = plant.setValue(BlockStateProperties.DOWN, true) - .setValue(VanillaBlockProperties.ROOTS, true); - } - else { - plant = plant.setValue(BlockStateProperties.DOWN, true); - } - info.cancel(); - } - else { - if (GeneratorOptions.changeChorusPlant()) { - plant = plant.setValue(VanillaBlockProperties.ROOTS, false); - } - info.cancel(); - } + if (plant.is(Blocks.CHORUS_PLANT) && world.getBlockState(pos.below()).is(TagAPI.BLOCK_END_GROUND)) { + plant = plant.setValue(BlockStateProperties.DOWN, true); info.setReturnValue(plant); - info.cancel(); } } } diff --git a/src/main/java/ru/betterend/mixin/common/ChorusPlantFeatureMixin.java b/src/main/java/ru/betterend/mixin/common/ChorusPlantFeatureMixin.java index 76fa11cc..568d344a 100644 --- a/src/main/java/ru/betterend/mixin/common/ChorusPlantFeatureMixin.java +++ b/src/main/java/ru/betterend/mixin/common/ChorusPlantFeatureMixin.java @@ -15,9 +15,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import ru.bclib.util.BlocksHelper; import ru.bclib.util.MHelper; -import ru.betterend.blocks.VanillaBlockProperties; import ru.betterend.registry.EndBlocks; -import ru.betterend.world.generator.GeneratorOptions; import java.util.Random; @@ -28,25 +26,15 @@ public class ChorusPlantFeatureMixin { final Random random = featureConfig.random(); final BlockPos blockPos = featureConfig.origin(); final WorldGenLevel structureWorldAccess = featureConfig.level(); - if (structureWorldAccess.isEmptyBlock(blockPos) && structureWorldAccess.getBlockState(blockPos.below()) - .is(EndBlocks.CHORUS_NYLIUM)) { + if (structureWorldAccess.isEmptyBlock(blockPos) && structureWorldAccess.getBlockState(blockPos.below()).is(EndBlocks.CHORUS_NYLIUM)) { ChorusFlowerBlock.generatePlant(structureWorldAccess, blockPos, random, MHelper.randRange(8, 16, random)); BlockState bottom = structureWorldAccess.getBlockState(blockPos); if (bottom.is(Blocks.CHORUS_PLANT)) { - if ((GeneratorOptions.changeChorusPlant())) { - BlocksHelper.setWithoutUpdate( - structureWorldAccess, - blockPos, - bottom.setValue(VanillaBlockProperties.ROOTS, true).setValue(PipeBlock.DOWN, true) - ); - } - else { - BlocksHelper.setWithoutUpdate( - structureWorldAccess, - blockPos, - bottom.setValue(PipeBlock.DOWN, true) - ); - } + BlocksHelper.setWithoutUpdate( + structureWorldAccess, + blockPos, + bottom.setValue(PipeBlock.DOWN, true) + ); } info.setReturnValue(true); } diff --git a/src/main/resources/assets/minecraft/blockstates/custom_chorus_flower.json b/src/main/resources/assets/betterend/blockstates/custom_chorus_flower.json similarity index 95% rename from src/main/resources/assets/minecraft/blockstates/custom_chorus_flower.json rename to src/main/resources/assets/betterend/blockstates/custom_chorus_flower.json index fed5be0f..45269fb3 100644 --- a/src/main/resources/assets/minecraft/blockstates/custom_chorus_flower.json +++ b/src/main/resources/assets/betterend/blockstates/custom_chorus_flower.json @@ -1,22 +1,22 @@ -{ - "variants": { - "age=0": { - "model": "betterend:block/chorus_plant_flower" - }, - "age=1": { - "model": "betterend:block/chorus_plant_flower" - }, - "age=2": { - "model": "betterend:block/chorus_plant_flower" - }, - "age=3": { - "model": "betterend:block/chorus_plant_flower" - }, - "age=4": { - "model": "betterend:block/chorus_plant_flower" - }, - "age=5": { - "model": "betterend:block/chorus_plant_flower_open" - } - } +{ + "variants": { + "age=0": { + "model": "betterend:block/chorus_plant_flower" + }, + "age=1": { + "model": "betterend:block/chorus_plant_flower" + }, + "age=2": { + "model": "betterend:block/chorus_plant_flower" + }, + "age=3": { + "model": "betterend:block/chorus_plant_flower" + }, + "age=4": { + "model": "betterend:block/chorus_plant_flower" + }, + "age=5": { + "model": "betterend:block/chorus_plant_flower_open" + } + } } \ No newline at end of file diff --git a/src/main/resources/assets/minecraft/blockstates/custom_chorus_plant.json b/src/main/resources/assets/betterend/blockstates/custom_chorus_plant.json similarity index 92% rename from src/main/resources/assets/minecraft/blockstates/custom_chorus_plant.json rename to src/main/resources/assets/betterend/blockstates/custom_chorus_plant.json index 52268ebc..4db5e7db 100644 --- a/src/main/resources/assets/minecraft/blockstates/custom_chorus_plant.json +++ b/src/main/resources/assets/betterend/blockstates/custom_chorus_plant.json @@ -1,69 +1,65 @@ -{ - "multipart": [ - { - "when": { "OR": [ - {"up": "false"}, - {"down": "false"} - ]}, - "apply": { "model": "betterend:block/chorus_plant_center" } - }, - { - "when": {"roots": "true"}, - "apply": { "model": "betterend:block/chorus_plant_roots" } - }, - { - "when": {"north": "true"}, - "apply": [ - { "model": "betterend:block/chorus_plant_stem", "x": 90, "y": 180 }, - { "model": "betterend:block/chorus_plant_stem_2", "x": 90, "y": 180 }, - { "model": "betterend:block/chorus_plant_stem_3", "x": 90, "y": 180 }, - { "model": "betterend:block/chorus_plant_stem_4", "x": 90, "y": 180 } - ] - }, - { - "when": { "east": "true" }, - "apply": [ - { "model": "betterend:block/chorus_plant_stem", "x": 90, "y": 270 }, - { "model": "betterend:block/chorus_plant_stem_2", "x": 90, "y": 270 }, - { "model": "betterend:block/chorus_plant_stem_3", "x": 90, "y": 270 }, - { "model": "betterend:block/chorus_plant_stem_4", "x": 90, "y": 270 } - ] - }, - { - "when": { "south": "true" }, - "apply": [ - { "model": "betterend:block/chorus_plant_stem", "x": 90 }, - { "model": "betterend:block/chorus_plant_stem_2", "x": 90 }, - { "model": "betterend:block/chorus_plant_stem_3", "x": 90 }, - { "model": "betterend:block/chorus_plant_stem_4", "x": 90 } - ] - }, - { - "when": { "west": "true" }, - "apply": [ - { "model": "betterend:block/chorus_plant_stem", "x": 90, "y": 90 }, - { "model": "betterend:block/chorus_plant_stem_2", "x": 90, "y": 90 }, - { "model": "betterend:block/chorus_plant_stem_3", "x": 90, "y": 90 }, - { "model": "betterend:block/chorus_plant_stem_4", "x": 90, "y": 90 } - ] - }, - { - "when": { "up": "true" }, - "apply": [ - { "model": "betterend:block/chorus_plant_stem", "x": 180 }, - { "model": "betterend:block/chorus_plant_stem_2", "x": 180 }, - { "model": "betterend:block/chorus_plant_stem_3", "x": 180 }, - { "model": "betterend:block/chorus_plant_stem_4", "x": 180 } - ] - }, - { - "when": { "down": "true" }, - "apply": [ - { "model": "betterend:block/chorus_plant_stem" }, - { "model": "betterend:block/chorus_plant_stem_2" }, - { "model": "betterend:block/chorus_plant_stem_3" }, - { "model": "betterend:block/chorus_plant_stem_4" } - ] - } - ] +{ + "multipart": [ + { + "when": { "OR": [ + {"up": "false"}, + {"down": "false"} + ]}, + "apply": { "model": "betterend:block/chorus_plant_center" } + }, + { + "when": {"north": "true"}, + "apply": [ + { "model": "betterend:block/chorus_plant_stem", "x": 90, "y": 180 }, + { "model": "betterend:block/chorus_plant_stem_2", "x": 90, "y": 180 }, + { "model": "betterend:block/chorus_plant_stem_3", "x": 90, "y": 180 }, + { "model": "betterend:block/chorus_plant_stem_4", "x": 90, "y": 180 } + ] + }, + { + "when": { "east": "true" }, + "apply": [ + { "model": "betterend:block/chorus_plant_stem", "x": 90, "y": 270 }, + { "model": "betterend:block/chorus_plant_stem_2", "x": 90, "y": 270 }, + { "model": "betterend:block/chorus_plant_stem_3", "x": 90, "y": 270 }, + { "model": "betterend:block/chorus_plant_stem_4", "x": 90, "y": 270 } + ] + }, + { + "when": { "south": "true" }, + "apply": [ + { "model": "betterend:block/chorus_plant_stem", "x": 90 }, + { "model": "betterend:block/chorus_plant_stem_2", "x": 90 }, + { "model": "betterend:block/chorus_plant_stem_3", "x": 90 }, + { "model": "betterend:block/chorus_plant_stem_4", "x": 90 } + ] + }, + { + "when": { "west": "true" }, + "apply": [ + { "model": "betterend:block/chorus_plant_stem", "x": 90, "y": 90 }, + { "model": "betterend:block/chorus_plant_stem_2", "x": 90, "y": 90 }, + { "model": "betterend:block/chorus_plant_stem_3", "x": 90, "y": 90 }, + { "model": "betterend:block/chorus_plant_stem_4", "x": 90, "y": 90 } + ] + }, + { + "when": { "up": "true" }, + "apply": [ + { "model": "betterend:block/chorus_plant_stem", "x": 180 }, + { "model": "betterend:block/chorus_plant_stem_2", "x": 180 }, + { "model": "betterend:block/chorus_plant_stem_3", "x": 180 }, + { "model": "betterend:block/chorus_plant_stem_4", "x": 180 } + ] + }, + { + "when": { "down": "true" }, + "apply": [ + { "model": "betterend:block/chorus_plant_stem" }, + { "model": "betterend:block/chorus_plant_stem_2" }, + { "model": "betterend:block/chorus_plant_stem_3" }, + { "model": "betterend:block/chorus_plant_stem_4" } + ] + } + ] } \ No newline at end of file diff --git a/src/main/resources/assets/minecraft/models/item/custom_chorus_flower.json b/src/main/resources/assets/betterend/models/item/custom_chorus_flower.json similarity index 94% rename from src/main/resources/assets/minecraft/models/item/custom_chorus_flower.json rename to src/main/resources/assets/betterend/models/item/custom_chorus_flower.json index c26d27c1..30047d60 100644 --- a/src/main/resources/assets/minecraft/models/item/custom_chorus_flower.json +++ b/src/main/resources/assets/betterend/models/item/custom_chorus_flower.json @@ -1,3 +1,3 @@ -{ - "parent": "betterend:block/chorus_plant_flower" -} +{ + "parent": "betterend:block/chorus_plant_flower" +} diff --git a/src/main/resources/assets/minecraft/models/item/custom_chorus_plant.json b/src/main/resources/assets/betterend/models/item/custom_chorus_plant.json similarity index 94% rename from src/main/resources/assets/minecraft/models/item/custom_chorus_plant.json rename to src/main/resources/assets/betterend/models/item/custom_chorus_plant.json index 70794d60..96bfea4d 100644 --- a/src/main/resources/assets/minecraft/models/item/custom_chorus_plant.json +++ b/src/main/resources/assets/betterend/models/item/custom_chorus_plant.json @@ -1,3 +1,3 @@ -{ - "parent": "betterend:block/chorus_plant_center" -} +{ + "parent": "betterend:block/chorus_plant_center" +}