Inspired by 2020's April Fools' 20w14infinite Snapshot, this mod brings endless randomly generated dimensions into Minecraft.
1package net.lerariemann.infinity.block.custom;
2
3import com.mojang.serialization.MapCodec;
4import net.lerariemann.infinity.compat.CreateCompat;
5import net.lerariemann.infinity.compat.ModCompat;
6import net.lerariemann.infinity.registry.core.ModBlockEntities;
7import net.lerariemann.infinity.util.platform.InfinityPlatform;
8import net.minecraft.core.BlockPos;
9import net.minecraft.resources.ResourceLocation;
10import net.minecraft.server.level.ServerLevel;
11import net.minecraft.util.RandomSource;
12import net.minecraft.world.level.Level;
13import net.minecraft.world.level.block.BaseEntityBlock;
14import net.minecraft.world.level.block.Blocks;
15import net.minecraft.world.level.block.entity.BlockEntity;
16import net.minecraft.world.level.block.state.BlockState;
17import org.jetbrains.annotations.Nullable;
18
19public class RailHelper extends BaseEntityBlock {
20 public RailHelper(Properties settings) {
21 super(settings);
22 }
23
24 //? if >1.21 {
25 @Override
26 protected MapCodec<? extends BaseEntityBlock> codec() {
27 return simpleCodec(RailHelper::new);
28 }
29 //?}
30
31 @Override
32 public void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean notify) {
33 world.scheduleTick(pos, this, 1);
34 }
35
36 @Override
37 public void tick(BlockState state, ServerLevel world, BlockPos pos, RandomSource random) {
38 //? if <1.21.2 || fabric {
39 if (ModCompat.CREATE) {
40 CreateCompat.reattachRails(world, pos, getBlockEntity(world, pos));
41 }else
42 //?}
43 world.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
44 }
45
46 public static RHBEntity getBlockEntity(ServerLevel world, BlockPos pos) {
47 return ((RHBEntity)world.getBlockEntity(pos));
48 }
49
50 @Override
51 public @Nullable BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
52 return new RHBEntity(pos, state);
53 }
54
55 public static class RHBEntity extends BlockEntity {
56 public ResourceLocation trackBlock;
57 public String shape;
58
59 public RHBEntity(BlockPos pos, BlockState state) {
60 super(ModBlockEntities.RAIL_HELPER.get(), pos, state);
61 trackBlock = null;
62 shape = "xo";
63 }
64 }
65}