Inspired by 2020's April Fools' 20w14infinite Snapshot, this mod brings endless randomly generated dimensions into Minecraft.
1package net.lerariemann.infinity.features;
2
3import com.mojang.serialization.Codec;
4import net.lerariemann.infinity.item.DiscItem;
5import net.minecraft.core.BlockPos;
6import net.minecraft.core.Direction;
7import net.minecraft.world.level.WorldGenLevel;
8import net.minecraft.world.level.block.Blocks;
9import net.minecraft.world.level.block.HopperBlock;
10import net.minecraft.world.level.levelgen.feature.Feature;
11import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
12import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
13import net.lerariemann.infinity.util.InfinityMethods;
14import net.minecraft.world.level.block.entity.HopperBlockEntity;
15import net.minecraft.util.RandomSource;
16import net.minecraft.world.item.ItemStack;
17
18public class NotesJukeboxFeature extends Feature<NoneFeatureConfiguration> {
19 public NotesJukeboxFeature(Codec<NoneFeatureConfiguration> codec) {
20 super(codec);
21 }
22
23 @Override
24 public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> context) {
25 WorldGenLevel level = context.level();
26 BlockPos origin = context.origin().below();
27 setBlock(level, origin, Blocks.JUKEBOX.defaultBlockState());
28 RandomSource random = context.random();
29 Direction dir = InfinityMethods.getRandomHorizontalDirection(random);
30 setBlock(level, origin.relative(dir), Blocks.HOPPER.defaultBlockState().setValue(HopperBlock.FACING, dir.getOpposite()));
31 if (level.getBlockEntity(origin.relative(dir)) instanceof HopperBlockEntity hpbe) {
32 ItemStack stack = DiscItem.getRandom(context.level().getServer());
33 hpbe.setItem(0, stack);
34 }
35 return true;
36 }
37}