Chorus plant changes & fixes

This commit is contained in:
paulevsGitch 2021-07-25 07:29:22 +03:00
parent 4b4d4bd5ae
commit b6cf041fc4
10 changed files with 135 additions and 219 deletions

View file

@ -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");
}

View file

@ -1,10 +1,12 @@
package ru.betterend.client; package ru.betterend.client;
import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Style; import net.minecraft.network.chat.Style;
import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import ru.bclib.BCLib; import ru.bclib.BCLib;
import ru.bclib.blocks.BaseChestBlock; import ru.bclib.blocks.BaseChestBlock;
@ -22,13 +24,13 @@ import ru.betterend.registry.EndEntitiesRenders;
import ru.betterend.registry.EndModelProviders; import ru.betterend.registry.EndModelProviders;
import ru.betterend.registry.EndParticles; import ru.betterend.registry.EndParticles;
import ru.betterend.registry.EndScreens; import ru.betterend.registry.EndScreens;
import ru.betterend.world.generator.GeneratorOptions;
import java.util.List; import java.util.List;
public class BetterEndClient implements ClientModInitializer { public class BetterEndClient implements ClientModInitializer {
@Override @Override
public void onInitializeClient() { public void onInitializeClient() {
//registerRenderLayers();
EndBlockEntityRenders.register(); EndBlockEntityRenders.register();
EndScreens.register(); EndScreens.register();
EndParticles.register(); EndParticles.register();
@ -42,6 +44,22 @@ public class BetterEndClient implements ClientModInitializer {
TranslationHelper.printMissingEnNames(BetterEnd.MOD_ID); TranslationHelper.printMissingEnNames(BetterEnd.MOD_ID);
TranslationHelper.printMissingNames(BetterEnd.MOD_ID, "ru_ru"); 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() { public static void registerTooltips() {

View file

@ -5,20 +5,24 @@ import net.minecraft.resources.ResourceLocation;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.ModifyVariable;
import ru.betterend.BetterEnd;
import ru.betterend.world.generator.GeneratorOptions; import ru.betterend.world.generator.GeneratorOptions;
@Mixin(ModelBakery.class) @Mixin(ModelBakery.class)
public abstract class ModelLoaderMixin { public abstract class ModelLoaderMixin {
@ModifyVariable(method = "loadModel", ordinal = 2, at = @At(value = "INVOKE")) @ModifyVariable(method = "loadModel", ordinal = 2, at = @At(value = "INVOKE"))
public ResourceLocation be_switchModel(ResourceLocation id) { public ResourceLocation be_switchModel(ResourceLocation id) {
if (GeneratorOptions.changeChorusPlant() && id.getNamespace().equals("minecraft") && id.getPath() if (GeneratorOptions.changeChorusPlant() && be_changeModel(id)) {
.startsWith( String path = id.getPath().replace("chorus", "custom_chorus");
"blockstates/") && id id = BetterEnd.makeID(path);
.getPath()
.contains("chorus") && !id.getPath().contains("custom_")) {
id = new ResourceLocation(id.getPath().replace("chorus", "custom_chorus"));
} }
return id; 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_");
}
} }

View file

@ -25,7 +25,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import ru.bclib.api.TagAPI; import ru.bclib.api.TagAPI;
import ru.bclib.util.BlocksHelper; import ru.bclib.util.BlocksHelper;
import ru.betterend.blocks.VanillaBlockProperties;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
import ru.betterend.world.generator.GeneratorOptions; import ru.betterend.world.generator.GeneratorOptions;
@ -64,19 +63,14 @@ public abstract class ChorusFlowerBlockMixin extends Block {
BlocksHelper.setWithoutUpdate( BlocksHelper.setWithoutUpdate(
world, world,
pos, pos,
plant.defaultBlockState() plant.defaultBlockState().setValue(ChorusPlantBlock.UP, true).setValue(ChorusPlantBlock.DOWN, true)
.setValue(ChorusPlantBlock.UP, true)
.setValue(ChorusPlantBlock.DOWN, true)
.setValue(VanillaBlockProperties.ROOTS, true)
); );
} }
else { else {
BlocksHelper.setWithoutUpdate( BlocksHelper.setWithoutUpdate(
world, world,
pos, pos,
plant.defaultBlockState() plant.defaultBlockState().setValue(ChorusPlantBlock.UP, true).setValue(ChorusPlantBlock.DOWN, true)
.setValue(ChorusPlantBlock.UP, true)
.setValue(ChorusPlantBlock.DOWN, true)
); );
} }
info.cancel(); 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 @Shadow
private static boolean allNeighborsEmpty(LevelReader world, BlockPos pos, @Nullable Direction exceptDirection) { private void placeGrownFlower(Level world, BlockPos pos, int age) {}
return false;
}
@Shadow
private void placeGrownFlower(Level world, BlockPos pos, int age) {
}
@Shadow
private void placeDeadFlower(Level world, BlockPos pos) {
}
@Override @Override
public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) { public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) {

View file

@ -10,19 +10,14 @@ import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.ChorusPlantBlock; 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.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import ru.bclib.api.TagAPI; import ru.bclib.api.TagAPI;
import ru.betterend.blocks.VanillaBlockProperties;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
import ru.betterend.world.generator.GeneratorOptions;
@Mixin(value = ChorusPlantBlock.class, priority = 100) @Mixin(value = ChorusPlantBlock.class, priority = 100)
public abstract class ChorusPlantBlockMixin extends Block { public abstract class ChorusPlantBlockMixin extends Block {
@ -30,59 +25,22 @@ public abstract class ChorusPlantBlockMixin extends Block {
super(settings); super(settings);
} }
@Inject(method = "<init>*", 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<Block, BlockState> 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) @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<BlockState> info) { private void be_getStateForPlacement(BlockPlaceContext ctx, CallbackInfoReturnable<BlockState> info) {
BlockPos pos = ctx.getClickedPos(); BlockPos pos = ctx.getClickedPos();
Level world = ctx.getLevel(); Level world = ctx.getLevel();
BlockState plant = info.getReturnValue(); BlockState plant = info.getReturnValue();
if (ctx.canPlace() && plant.is(Blocks.CHORUS_PLANT) && world.getBlockState(pos.below()).is(TagAPI.BLOCK_END_GROUND)) { 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.setReturnValue(plant.setValue(BlockStateProperties.DOWN, true));
} }
info.cancel();
}
} }
@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) @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<BlockState> info) { private void be_getStateForPlacement(BlockGetter blockGetter, BlockPos blockPos, CallbackInfoReturnable<BlockState> info) {
BlockState plant = info.getReturnValue(); BlockState plant = info.getReturnValue();
if (plant.is(Blocks.CHORUS_PLANT)) { if (plant.is(Blocks.CHORUS_PLANT) && blockGetter.getBlockState(blockPos.below()).is(TagAPI.BLOCK_END_GROUND)) {
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.setReturnValue(plant.setValue(BlockStateProperties.DOWN, true));
} }
info.cancel();
}
else {
if (GeneratorOptions.changeChorusPlant()) {
info.setReturnValue(plant.setValue(VanillaBlockProperties.ROOTS, false));
}
info.cancel();
}
}
} }
@Inject(method = "canSurvive", at = @At("HEAD"), cancellable = true) @Inject(method = "canSurvive", at = @At("HEAD"), cancellable = true)
@ -90,32 +48,15 @@ public abstract class ChorusPlantBlockMixin extends Block {
BlockState down = world.getBlockState(pos.below()); BlockState down = world.getBlockState(pos.below());
if (down.is(EndBlocks.CHORUS_NYLIUM) || down.is(Blocks.END_STONE)) { if (down.is(EndBlocks.CHORUS_NYLIUM) || down.is(Blocks.END_STONE)) {
info.setReturnValue(true); info.setReturnValue(true);
info.cancel();
} }
} }
@Inject(method = "updateShape", at = @At("RETURN"), cancellable = true) @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<BlockState> info) { private void be_updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, BlockPos pos, BlockPos posFrom, CallbackInfoReturnable<BlockState> info) {
BlockState plant = info.getReturnValue(); BlockState plant = info.getReturnValue();
if (plant.is(Blocks.CHORUS_PLANT)) { if (plant.is(Blocks.CHORUS_PLANT) && world.getBlockState(pos.below()).is(TagAPI.BLOCK_END_GROUND)) {
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); plant = plant.setValue(BlockStateProperties.DOWN, true);
}
info.cancel();
}
else {
if (GeneratorOptions.changeChorusPlant()) {
plant = plant.setValue(VanillaBlockProperties.ROOTS, false);
}
info.cancel();
}
info.setReturnValue(plant); info.setReturnValue(plant);
info.cancel();
} }
} }
} }

View file

@ -15,9 +15,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import ru.bclib.util.BlocksHelper; import ru.bclib.util.BlocksHelper;
import ru.bclib.util.MHelper; import ru.bclib.util.MHelper;
import ru.betterend.blocks.VanillaBlockProperties;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
import ru.betterend.world.generator.GeneratorOptions;
import java.util.Random; import java.util.Random;
@ -28,26 +26,16 @@ public class ChorusPlantFeatureMixin {
final Random random = featureConfig.random(); final Random random = featureConfig.random();
final BlockPos blockPos = featureConfig.origin(); final BlockPos blockPos = featureConfig.origin();
final WorldGenLevel structureWorldAccess = featureConfig.level(); final WorldGenLevel structureWorldAccess = featureConfig.level();
if (structureWorldAccess.isEmptyBlock(blockPos) && structureWorldAccess.getBlockState(blockPos.below()) if (structureWorldAccess.isEmptyBlock(blockPos) && structureWorldAccess.getBlockState(blockPos.below()).is(EndBlocks.CHORUS_NYLIUM)) {
.is(EndBlocks.CHORUS_NYLIUM)) {
ChorusFlowerBlock.generatePlant(structureWorldAccess, blockPos, random, MHelper.randRange(8, 16, random)); ChorusFlowerBlock.generatePlant(structureWorldAccess, blockPos, random, MHelper.randRange(8, 16, random));
BlockState bottom = structureWorldAccess.getBlockState(blockPos); BlockState bottom = structureWorldAccess.getBlockState(blockPos);
if (bottom.is(Blocks.CHORUS_PLANT)) { 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( BlocksHelper.setWithoutUpdate(
structureWorldAccess, structureWorldAccess,
blockPos, blockPos,
bottom.setValue(PipeBlock.DOWN, true) bottom.setValue(PipeBlock.DOWN, true)
); );
} }
}
info.setReturnValue(true); info.setReturnValue(true);
} }
} }

View file

@ -6,10 +6,6 @@
{"down": "false"} {"down": "false"}
]}, ]},
"apply": { "model": "betterend:block/chorus_plant_center" } "apply": { "model": "betterend:block/chorus_plant_center" }
},
{
"when": {"roots": "true"},
"apply": { "model": "betterend:block/chorus_plant_roots" }
}, },
{ {
"when": {"north": "true"}, "when": {"north": "true"},