Inspired by 2020's April Fools' 20w14infinite Snapshot, this mod brings endless randomly generated dimensions into Minecraft.
at master 143 lines 5.1 kB view raw
1package net.lerariemann.infinity.block.custom; 2 3import com.mojang.serialization.MapCodec; 4import net.lerariemann.infinity.block.entity.ChromaticBlockEntity; 5import net.minecraft.core.BlockPos; 6import net.minecraft.core.Direction; 7import net.minecraft.util.RandomSource; 8import net.minecraft.world.InteractionHand; 9import net.minecraft.world.InteractionResult; 10import net.minecraft.world.entity.player.Player; 11import net.minecraft.world.item.ItemStack; 12import net.minecraft.world.level.*; 13import net.minecraft.world.level.block.BaseEntityBlock; 14import net.minecraft.world.level.block.Block; 15import net.minecraft.world.level.block.Blocks; 16import net.minecraft.world.level.block.RenderShape; 17import net.minecraft.world.level.block.entity.BlockEntity; 18import net.minecraft.world.level.block.state.BlockState; 19import net.minecraft.world.level.block.state.StateDefinition; 20import net.minecraft.world.phys.BlockHitResult; 21import net.minecraft.world.phys.shapes.CollisionContext; 22import net.minecraft.world.phys.shapes.VoxelShape; 23import org.jspecify.annotations.Nullable; 24 25public class ChromaticBlock extends BaseEntityBlock implements Boopable { 26 //? if >1.21 27 public static final MapCodec<ChromaticBlock> CODEC = simpleCodec(ChromaticBlock::new); 28 public ChromaticBlock(Properties settings) { 29 super(settings); 30 } 31 @Override 32 protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { 33 super.createBlockStateDefinition(builder); 34 appendBoop(builder); 35 } 36 37 @Override 38 public ItemStack getCloneItemStack( 39 //? if >1.21 { 40 LevelReader 41 //?} else { 42 /*BlockGetter 43 *///?} 44 world, BlockPos pos, BlockState state 45 //? if >1.21.2 { 46 , boolean bl 47 //?} 48 ) { 49 ItemStack res = super.getCloneItemStack(world, pos, state 50 //? if >1.21.2 { 51 , true 52 //?} 53 ); 54 if (!res.isEmpty() && world.getBlockEntity(pos) instanceof ChromaticBlockEntity cbe) { 55 //? if >1.21 { 56 res.applyComponents(cbe.asMap()); 57 //?} else { 58 /*res.setTag(cbe.asMap()); 59 *///?} 60 } 61 return res; 62 } 63 64 @Override 65 //? if <1.21 { 66 /*public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { 67 *///?} else { 68 protected InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) { 69 //?} 70 if (world.getBlockEntity(pos) instanceof ChromaticBlockEntity cbe) { 71 ItemStack stack = player.getItemInHand(InteractionHand.MAIN_HAND); 72 if (cbe.onUse(world, pos, stack)) { 73 return InteractionResult.SUCCESS; 74 } 75 } 76 //? if <1.21 { 77 /*return super.use(state, world, pos, player, hand, hit); 78 *///?} else { 79 return super.useWithoutItem(state, world, pos, player, hit); 80 //?} 81 } 82 83 public static class Carpet extends ChromaticBlock { 84 protected static final VoxelShape SHAPE = Block.box(0.0, 0.0, 0.0, 16.0, 1.0, 16.0); 85 86 public Carpet(Properties settings) { 87 super(settings); 88 } 89 90 @Override 91 //? if >1.21 { 92 protected 93 //?} else { 94 /*public 95 *///?} 96 VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) { 97 return SHAPE; 98 } 99 100 @Override 101 //? if >1.21 { 102 protected 103 //?} else { 104 /*public 105 *///?} 106 //? if >1.21.2 { 107 BlockState updateShape(BlockState state, LevelReader world, ScheduledTickAccess scheduledTickAccess, BlockPos pos, Direction direction, BlockPos neighborPos, BlockState neighborState, RandomSource random) { 108 //?} else { 109 /*BlockState updateShape(BlockState state, Direction direction, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { 110 *///?} 111 if (!state.canSurvive(world, pos)) return Blocks.AIR.defaultBlockState(); 112 //? if >1.21.2 { 113 return super.updateShape(state, world, scheduledTickAccess, pos, direction, neighborPos, neighborState, random); 114 //?} else { 115 /*return super.updateShape(state, direction, neighborState, world, pos, neighborPos); 116 *///?} 117 } 118 119 @Override 120 //? if >1.21 { 121 protected 122 //?} else { 123 /*public 124 *///?} 125 boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { 126 return !world.isEmptyBlock(pos.below()); 127 } 128 } 129 @Override 130 public RenderShape getRenderShape(BlockState state) { 131 return RenderShape.MODEL; 132 } 133 //? if >1.21 { 134 @Override 135 protected MapCodec<? extends BaseEntityBlock> codec() { 136 return CODEC; 137 } 138 //?} 139 @Override 140 public @Nullable BlockEntity newBlockEntity(BlockPos pos, BlockState state) { 141 return new ChromaticBlockEntity(pos, state); 142 } 143}