More compatibility
This commit is contained in:
parent
491afd5236
commit
1caadde11a
2 changed files with 53 additions and 10 deletions
|
@ -13,6 +13,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.block.ChorusFlowerBlock;
|
import net.minecraft.block.ChorusFlowerBlock;
|
||||||
import net.minecraft.block.ChorusPlantBlock;
|
import net.minecraft.block.ChorusPlantBlock;
|
||||||
import net.minecraft.block.ShapeContext;
|
import net.minecraft.block.ShapeContext;
|
||||||
|
@ -22,12 +23,13 @@ import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.util.shape.VoxelShape;
|
import net.minecraft.util.shape.VoxelShape;
|
||||||
import net.minecraft.world.BlockView;
|
import net.minecraft.world.BlockView;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.WorldAccess;
|
||||||
import net.minecraft.world.WorldView;
|
import net.minecraft.world.WorldView;
|
||||||
import ru.betterend.registry.BlockRegistry;
|
import ru.betterend.registry.BlockRegistry;
|
||||||
import ru.betterend.registry.BlockTagRegistry;
|
import ru.betterend.registry.BlockTagRegistry;
|
||||||
import ru.betterend.util.BlocksHelper;
|
import ru.betterend.util.BlocksHelper;
|
||||||
|
|
||||||
@Mixin(ChorusFlowerBlock.class)
|
@Mixin(value = ChorusFlowerBlock.class, priority = 100)
|
||||||
public abstract class ChorusFlowerBlockMixin extends Block {
|
public abstract class ChorusFlowerBlockMixin extends Block {
|
||||||
private static final VoxelShape SHAPE_FULL = Block.createCuboidShape(0, 0, 0, 16, 16, 16);
|
private static final VoxelShape SHAPE_FULL = Block.createCuboidShape(0, 0, 0, 16, 16, 16);
|
||||||
private static final VoxelShape SHAPE_HALF = Block.createCuboidShape(0, 0, 0, 16, 4, 16);
|
private static final VoxelShape SHAPE_HALF = Block.createCuboidShape(0, 0, 0, 16, 4, 16);
|
||||||
|
@ -63,6 +65,14 @@ public abstract class ChorusFlowerBlockMixin extends Block {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject(method = "generate", at = @At("RETURN"), cancellable = true)
|
||||||
|
private static void beOnGenerate(WorldAccess world, BlockPos pos, Random random, int size, CallbackInfo info) {
|
||||||
|
BlockState state = world.getBlockState(pos);
|
||||||
|
if (state.isOf(Blocks.CHORUS_PLANT)) {
|
||||||
|
BlocksHelper.setWithoutUpdate(world, pos, state.with(BlocksHelper.ROOTS, true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Shadow
|
@Shadow
|
||||||
private static boolean isSurroundedByAir(WorldView world, BlockPos pos, @Nullable Direction exceptDirection) { return false; }
|
private static boolean isSurroundedByAir(WorldView world, BlockPos pos, @Nullable Direction exceptDirection) { return false; }
|
||||||
|
|
||||||
|
|
|
@ -11,16 +11,20 @@ import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.block.ChorusPlantBlock;
|
import net.minecraft.block.ChorusPlantBlock;
|
||||||
|
import net.minecraft.item.ItemPlacementContext;
|
||||||
import net.minecraft.state.StateManager;
|
import net.minecraft.state.StateManager;
|
||||||
import net.minecraft.state.property.Properties;
|
import net.minecraft.state.property.Properties;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.world.BlockView;
|
import net.minecraft.world.BlockView;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.WorldAccess;
|
||||||
import net.minecraft.world.WorldView;
|
import net.minecraft.world.WorldView;
|
||||||
import ru.betterend.registry.BlockRegistry;
|
import ru.betterend.registry.BlockRegistry;
|
||||||
import ru.betterend.registry.BlockTagRegistry;
|
import ru.betterend.registry.BlockTagRegistry;
|
||||||
import ru.betterend.util.BlocksHelper;
|
import ru.betterend.util.BlocksHelper;
|
||||||
|
|
||||||
@Mixin(value = ChorusPlantBlock.class, priority = 500)
|
@Mixin(value = ChorusPlantBlock.class, priority = 100)
|
||||||
public abstract class ChorusPlantBlockMixin extends Block {
|
public abstract class ChorusPlantBlockMixin extends Block {
|
||||||
public ChorusPlantBlockMixin(Settings settings) {
|
public ChorusPlantBlockMixin(Settings settings) {
|
||||||
super(settings);
|
super(settings);
|
||||||
|
@ -36,14 +40,6 @@ public abstract class ChorusPlantBlockMixin extends Block {
|
||||||
builder.add(BlocksHelper.ROOTS);
|
builder.add(BlocksHelper.ROOTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "canPlaceAt", at = @At("HEAD"), cancellable = true)
|
|
||||||
private void beCanPlace(BlockState state, WorldView world, BlockPos pos, CallbackInfoReturnable<Boolean> info) {
|
|
||||||
if (world.getBlockState(pos.down()).isOf(BlockRegistry.CHORUS_NYLIUM)) {
|
|
||||||
info.setReturnValue(true);
|
|
||||||
info.cancel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "withConnectionProperties", at = @At("RETURN"), cancellable = true)
|
@Inject(method = "withConnectionProperties", at = @At("RETURN"), cancellable = true)
|
||||||
private void beConnectionProperties(BlockView world, BlockPos pos, CallbackInfoReturnable<BlockState> info) {
|
private void beConnectionProperties(BlockView world, BlockPos pos, CallbackInfoReturnable<BlockState> info) {
|
||||||
BlockState plant = info.getReturnValue();
|
BlockState plant = info.getReturnValue();
|
||||||
|
@ -56,4 +52,41 @@ public abstract class ChorusPlantBlockMixin extends Block {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject(method = "canPlaceAt", at = @At("HEAD"), cancellable = true)
|
||||||
|
private void beCanPlace(BlockState state, WorldView world, BlockPos pos, CallbackInfoReturnable<Boolean> info) {
|
||||||
|
BlockState down = world.getBlockState(pos.down());
|
||||||
|
if (down.isOf(BlockRegistry.CHORUS_NYLIUM) || down.isOf(Blocks.END_STONE)) {
|
||||||
|
info.setReturnValue(true);
|
||||||
|
info.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "getStateForNeighborUpdate", at = @At("RETURN"), cancellable = true)
|
||||||
|
private void beStateForNeighborUpdate(BlockState state, Direction direction, BlockState newState, WorldAccess world, BlockPos pos, BlockPos posFrom, CallbackInfoReturnable<BlockState> info) {
|
||||||
|
BlockState plant = info.getReturnValue();
|
||||||
|
if (plant.isOf(Blocks.CHORUS_PLANT)) {
|
||||||
|
if (world.getBlockState(pos.down()).isIn(BlockTagRegistry.END_GROUND)) {
|
||||||
|
plant = plant.with(Properties.DOWN, true).with(BlocksHelper.ROOTS, true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
plant = plant.with(BlocksHelper.ROOTS, false);
|
||||||
|
}
|
||||||
|
info.setReturnValue(plant);
|
||||||
|
info.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "getPlacementState", at = @At("RETURN"), cancellable = true)
|
||||||
|
private void beGetPlacementState(ItemPlacementContext ctx, CallbackInfoReturnable<BlockState> info) {
|
||||||
|
BlockPos pos = ctx.getBlockPos();
|
||||||
|
World world = ctx.getWorld();
|
||||||
|
if (ctx.canPlace() && world.getBlockState(pos.down()).isIn(BlockTagRegistry.END_GROUND)) {
|
||||||
|
BlockState plant = info.getReturnValue();
|
||||||
|
if (plant.isOf(Blocks.CHORUS_PLANT)) {
|
||||||
|
info.setReturnValue(plant.with(BlocksHelper.ROOTS, true));
|
||||||
|
info.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue