Chorus plant changes & fixes
This commit is contained in:
parent
4b4d4bd5ae
commit
b6cf041fc4
10 changed files with 135 additions and 219 deletions
|
@ -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_");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 = "<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)
|
||||
private void be_getStateForPlacement(BlockPlaceContext ctx, CallbackInfoReturnable<BlockState> 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<BlockState> 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<BlockState> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue