Inspired by 2020's April Fools' 20w14infinite Snapshot, this mod brings endless randomly generated dimensions into Minecraft.

notes refactor part 2

Lera 816255de 5f5fccc2

+172 -180
-156
src/main/java/net/lerariemann/infinity/block/custom/NotesBlock.java
··· 1 - package net.lerariemann.infinity.block.custom; 2 - 3 - import net.lerariemann.infinity.block.entity.ChromaticBlockEntity; 4 - import net.lerariemann.infinity.options.InfinityOptions; 5 - import net.minecraft.core.BlockPos; 6 - import net.minecraft.core.particles.ParticleTypes; 7 - import net.minecraft.server.level.ServerLevel; 8 - import net.minecraft.sounds.SoundSource; 9 - import net.minecraft.stats.Stats; 10 - import net.minecraft.util.RandomSource; 11 - import net.minecraft.world.InteractionHand; 12 - import net.minecraft.world.InteractionResult; 13 - import net.minecraft.world.entity.Entity; 14 - import net.minecraft.world.entity.player.Player; 15 - import net.minecraft.world.level.Level; 16 - import net.minecraft.world.level.block.Block; 17 - import net.minecraft.world.level.block.NoteBlock; 18 - import net.minecraft.world.level.block.state.BlockState; 19 - import net.minecraft.world.level.block.state.StateDefinition; 20 - import net.minecraft.world.level.block.state.properties.BlockStateProperties; 21 - import net.minecraft.world.level.block.state.properties.BooleanProperty; 22 - import net.minecraft.world.level.block.state.properties.NoteBlockInstrument; 23 - import net.minecraft.world.level.gameevent.GameEvent; 24 - //? if >1.21.4 { 25 - import net.minecraft.world.level.redstone.Orientation; 26 - //?} 27 - import net.minecraft.world.phys.BlockHitResult; 28 - import org.jetbrains.annotations.Nullable; 29 - 30 - public class NotesBlock extends Block { 31 - public static final BooleanProperty POWERED = BlockStateProperties.POWERED; 32 - public static final BooleanProperty TICKING = BooleanProperty.create("ticking"); 33 - public NotesBlock(Properties settings) { 34 - super(settings); 35 - this.registerDefaultState(this.defaultBlockState().setValue(POWERED, false).setValue(TICKING, true)); 36 - } 37 - 38 - @Override 39 - protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { 40 - super.createBlockStateDefinition(builder); 41 - builder.add(POWERED); 42 - builder.add(TICKING); 43 - } 44 - 45 - @Override 46 - //? if >1.21 { 47 - protected 48 - //?} else { 49 - /*public 50 - *///?} 51 - boolean isRandomlyTicking(BlockState state) { 52 - return state.hasProperty(TICKING) && state.getValue(TICKING); 53 - } 54 - 55 - @Override 56 - //? if >1.21 { 57 - protected 58 - //?} else { 59 - /*public 60 - *///?} 61 - void neighborChanged(BlockState state, Level world, BlockPos pos, Block sourceBlock, 62 - //? if >1.21.2 { 63 - Orientation orientation 64 - //?} else { 65 - /*BlockPos sourcePos 66 - *///?} 67 - , boolean notify) { 68 - boolean bl = world.hasNeighborSignal(pos); 69 - if (bl != state.getValue(POWERED)) { 70 - if (bl) this.play(null, world, pos); 71 - world.setBlock(pos, state.setValue(POWERED, bl), 3); 72 - } 73 - } 74 - 75 - public boolean isTicking(ServerLevel world, BlockState state) { 76 - return state.getValue(TICKING) && (!InfinityOptions.access(world).isHaunted()); 77 - } 78 - 79 - @Override 80 - //? if >1.21 { 81 - protected 82 - //?} else { 83 - /*public 84 - *///?} 85 - void randomTick(BlockState state, ServerLevel world, BlockPos pos, RandomSource random) { 86 - if (isTicking(world, state) && random.nextInt(115) == 0) { 87 - this.play(null, world, pos); 88 - } 89 - } 90 - 91 - @Override 92 - //? if <1.21 { 93 - /*public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { 94 - *///?} else { 95 - protected InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) { 96 - //?} 97 - if (world.isClientSide()) { 98 - return InteractionResult.SUCCESS; 99 - } else { 100 - boolean bl = state.getValue(TICKING); 101 - world.setBlock(pos, state.setValue(TICKING, !bl), 3); 102 - play(player, world, pos); 103 - player.awardStat(Stats.TUNE_NOTEBLOCK); 104 - return InteractionResult.CONSUME; 105 - } 106 - } 107 - 108 - @Override 109 - //? if >1.21 { 110 - protected 111 - //?} else { 112 - /*public 113 - *///?} 114 - void attack(BlockState state, Level world, BlockPos pos, Player player) { 115 - if (!world.isClientSide()) { 116 - play(player, world, pos); 117 - player.awardStat(Stats.PLAY_NOTEBLOCK); 118 - } 119 - } 120 - 121 - public void play(@Nullable Entity entity, Level world, BlockPos pos) { 122 - if (world.getBlockState(pos.above()).isAir()) { 123 - world.blockEvent(pos, this, 0, 0); 124 - world.gameEvent(entity, GameEvent.NOTE_BLOCK_PLAY, pos); 125 - } 126 - } 127 - 128 - @Override 129 - //? if >1.21 { 130 - protected 131 - //?} else { 132 - /*public 133 - *///?} 134 - boolean triggerEvent(BlockState state, Level world, BlockPos pos, int type, int data) { 135 - NoteBlockInstrument noteBlockInstrument; 136 - float f; 137 - if (world.getBlockEntity(pos.below()) instanceof ChromaticBlockEntity e) { 138 - noteBlockInstrument = NoteBlockInstrument.GUITAR; 139 - f = (float)Math.pow(2.0, 2 * (e.brightness / 255f) - 1); 140 - } 141 - else { 142 - NoteBlockInstrument[] instruments = NoteBlockInstrument.values(); 143 - noteBlockInstrument = instruments[world.random.nextInt(instruments.length-7)]; 144 - if (noteBlockInstrument.isTunable()) { 145 - int i = world.random.nextInt(24); 146 - f = NoteBlock.getPitchFromNote(i); 147 - world.addParticle(ParticleTypes.NOTE, pos.getX() + 0.5, pos.getY() + 1.2, pos.getZ() + 0.5, i / 24.0, 0.0F, 0.0F); 148 - } else { 149 - f = 1.0F; 150 - } 151 - } 152 - 153 - world.playSeededSound(null, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, noteBlockInstrument.getSoundEvent(), SoundSource.RECORDS, 3.0F, f, world.random.nextLong()); 154 - return true; 155 - } 156 - }
-1
src/main/java/net/lerariemann/infinity/data/loot/InfinityBlockLootTableProvider.java
··· 35 35 dropOther(ModBlocks.IRIDESCENT_KELP_PLANT.get(), Items.KELP); 36 36 createSlabItemTable(ModBlocks.NETHERITE_SLAB.get()); 37 37 dropSelf(ModBlocks.NETHERITE_STAIRS.get()); 38 - dropSelf(ModBlocks.NOTES_BLOCK.get()); 39 38 } 40 39 } 41 40 //?}
-1
src/main/java/net/lerariemann/infinity/data/recipe/InfinityRecipeProvider.java
··· 198 198 iridescence(CHROMATIC_MATTER, CHROMATIC_MATTER, "recipe_info.iridescence.infinity.chromatic_matter").save(output); 199 199 portal(AMETHYST_SHARD, TRANSFINITE_KEY.get(), "recipe_info.portal.infinity.attuned").save(output, "infinity:key_from_portal"); 200 200 iridescence(TRANSFINITE_KEY, TRANSFINITE_KEY, "recipe_info.iridescence.infinity.key").save(output, "infinity:key_from_iridescence"); 201 - portal(NOTE_BLOCK, NOTES_BLOCK_ITEM.get()).save(output); 202 201 portal(TNT, TIME_BOMB_ITEM.get()).save(output, "infinity:timebomb_from_portal"); 203 202 color(ItemTags.WOOL, CHROMATIC_WOOL).save(output, "infinity:chromatic_coloring_wool"); 204 203 color(ItemTags.WOOL_CARPETS, CHROMATIC_CARPET).save(output, "infinity:chromatic_coloring_carpet");
+17 -3
src/main/java/net/lerariemann/infinity/mixin/options/NoteBlockMixin.java
··· 2 2 3 3 import net.lerariemann.infinity.options.InfinityOptions; 4 4 import net.minecraft.core.BlockPos; 5 + import net.minecraft.server.level.ServerLevel; 5 6 import net.minecraft.world.entity.Entity; 6 7 import net.minecraft.world.level.Level; 7 8 import net.minecraft.world.level.block.Block; ··· 9 10 import net.minecraft.world.level.block.state.BlockState; 10 11 //? if >1.21.2 { 11 12 import net.minecraft.world.level.redstone.Orientation; 13 + import net.minecraft.world.level.LevelReader; 12 14 //?} 15 + import net.minecraft.world.level.LevelAccessor; 13 16 import org.jetbrains.annotations.Nullable; 14 17 import org.spongepowered.asm.mixin.Mixin; 15 18 import org.spongepowered.asm.mixin.Shadow; 16 19 import org.spongepowered.asm.mixin.injection.At; 17 20 import org.spongepowered.asm.mixin.injection.Inject; 18 21 import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 22 + import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 19 23 20 24 @Mixin(NoteBlock.class) 21 25 public abstract class NoteBlockMixin { ··· 33 37 if (bl) { 34 38 playNote(null, state, level, pos); 35 39 } 36 - 37 - level.setBlock(pos, state.setValue(NoteBlock.POWERED, bl), 0, 0); 38 - ci.cancel(); 40 + level.setBlock(pos, state.setValue(NoteBlock.POWERED, bl), 18, 0); 39 41 } 42 + ci.cancel(); 43 + } 44 + } 45 + 46 + @Inject(method = "setInstrument", at = @At("HEAD"), cancellable = true) 47 + //?if >1.21.2 { 48 + void inj(LevelReader level, BlockPos pos, BlockState state, CallbackInfoReturnable<BlockState> cir) { 49 + //?} else { 50 + /*void inj(LevelAccessor level, BlockPos pos, BlockState state, CallbackInfoReturnable<BlockState> cir) { 51 + *///?} 52 + if (level instanceof ServerLevel world && InfinityOptions.access(world).isHaunted()) { 53 + cir.setReturnValue(state); 40 54 } 41 55 } 42 56 }
+7 -2
src/main/java/net/lerariemann/infinity/mixin/options/ServerWorldMixin.java
··· 99 99 100 100 @Inject(method = "tickChunk", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/material/FluidState;isRandomlyTicking()Z")) 101 101 void inj(LevelChunk chunk, int randomTickSpeed, CallbackInfo ci, @Local BlockState bs, @Local BlockPos blockPos2, @Local FluidState fs) { 102 - if (infinity$options.isHaunted() && random.nextInt(200) < (int)(Math.floor(getMoonBrightness() * 4))) { 103 - updateNeighborsAt(blockPos2, bs.getBlock()); 102 + if (infinity$options.isHaunted() && random.nextInt(20) < (int)(Math.floor(getMoonBrightness() * 4))) { 103 + Direction direction = Direction.values()[InfinityMod.random.nextInt(6)]; 104 + //? if <1.21.2 { 105 + /*neighborUpdater.neighborChanged(blockPos2.relative(direction), bs.getBlock(), blockPos2); 106 + *///?} else { 107 + neighborUpdater.neighborChanged(blockPos2.relative(direction), bs.getBlock(), null); 108 + //?} 104 109 } 105 110 } 106 111
-2
src/main/java/net/lerariemann/infinity/registry/core/ModBlocks.java
··· 60 60 IridescentKelpBlock::new, (VersionMethods.copyBlockProperties(Blocks.KELP).mapColor(MapColor.COLOR_MAGENTA))); 61 61 public static final RegistrySupplier<IridescentKelpBlock.Plant> IRIDESCENT_KELP_PLANT = register("iridescent_kelp_plant", 62 62 IridescentKelpBlock.Plant::new, (VersionMethods.copyBlockProperties(Blocks.KELP).mapColor(MapColor.COLOR_MAGENTA))); 63 - public static final RegistrySupplier<Block> NOTES_BLOCK = register("notes_block", 64 - NotesBlock::new, (VersionMethods.copyBlockProperties(Blocks.NOTE_BLOCK).randomTicks())); 65 63 public static final RegistrySupplier<RailHelper> RAIL_HELPER = register("rail_helper", 66 64 RailHelper::new, (BlockBehaviour.Properties.of().strength(-1.0F, 3600000.8F).mapColor(MapColor.NONE) 67 65 .noLootTable().noOcclusion().isValidSpawn((state, getter, pos, type)-> false).pushReaction(PushReaction.BLOCK)
-2
src/main/java/net/lerariemann/infinity/registry/core/ModItems.java
··· 67 67 registerBlockItemAfter(ModBlocks.NETHERITE_SLAB, CreativeModeTabs.BUILDING_BLOCKS, Items.NETHERITE_BLOCK, BlockItem::new); 68 68 public static final RegistrySupplier<Item> NETHERITE_STAIRS_ITEM = 69 69 registerBlockItemAfter(ModBlocks.NETHERITE_STAIRS, CreativeModeTabs.BUILDING_BLOCKS, Items.NETHERITE_BLOCK, BlockItem::new); 70 - public static final RegistrySupplier<Item> NOTES_BLOCK_ITEM = 71 - registerBlockItemAfter(ModBlocks.NOTES_BLOCK, CreativeModeTabs.FUNCTIONAL_BLOCKS, Items.NOTE_BLOCK, BlockItem::new); 72 70 public static final RegistrySupplier<Item> TIME_BOMB_ITEM = 73 71 registerBlockItemAfter(ModBlocks.TIME_BOMB, CreativeModeTabs.FUNCTIONAL_BLOCKS, VAULT, BlockItem::new); 74 72 public static final RegistrySupplier<Item> IRIDESCENT_WOOL =
-1
src/main/java/net/lerariemann/infinity/registry/var/ModItemGroups.java
··· 78 78 addAfter(event, LECTERN, ModItems.ALTAR_ITEM.get()); 79 79 addAfter(event, LODESTONE, ModItems.ANT_ITEM.get()); 80 80 addAfter(event, CHISELED_BOOKSHELF, ModItems.BOOK_BOX_ITEM.get()); 81 - addAfter(event, NOTE_BLOCK, ModItems.NOTES_BLOCK_ITEM.get()); 82 81 addAfter(event, VAULT, ModItems.TIME_BOMB_ITEM.get()); 83 82 } else if (equals(creativeModeTab, CreativeModeTabs.INGREDIENTS)) { 84 83 addAfter(event, DISC_FRAGMENT_5, ModItems.FOOTPRINT.get());
+28
src/main/java/net/lerariemann/infinity/registry/var/ModMaterialRules.java
··· 4 4 import com.mojang.serialization.MapCodec; 5 5 import com.mojang.serialization.codecs.RecordCodecBuilder; 6 6 import dev.architectury.registry.registries.DeferredRegister; 7 + import net.lerariemann.infinity.InfinityMod; 7 8 import net.lerariemann.infinity.iridescence.Iridescence; 8 9 import net.lerariemann.infinity.registry.core.ModBlocks; 9 10 import net.lerariemann.infinity.util.InfinityMethods; ··· 18 19 import net.minecraft.util.Mth; 19 20 import net.minecraft.world.level.block.Blocks; 20 21 import net.minecraft.world.level.block.LadderBlock; 22 + import net.minecraft.world.level.block.NoteBlock; 21 23 import net.minecraft.world.level.block.state.BlockState; 22 24 import net.minecraft.world.level.block.state.properties.BlockStateProperties; 23 25 import net.minecraft.world.level.block.state.properties.Half; 26 + import net.minecraft.world.level.block.state.properties.NoteBlockInstrument; 24 27 import net.minecraft.world.level.levelgen.SurfaceRules; 28 + import org.jetbrains.annotations.Nullable; 25 29 26 30 //? if neoforge 27 31 /*import javax.annotation.ParametersAreNonnullByDefault;*/ ··· 94 98 @Override 95 99 public SurfaceRules.SurfaceRule apply(SurfaceRules.Context materialRuleContext) { 96 100 return new RandomColoredBlock(str); 101 + } 102 + } 103 + } 104 + 105 + public static class Notes implements SurfaceRules.SurfaceRule { 106 + @Override 107 + public @Nullable BlockState tryApply(int i, int j, int k) { 108 + NoteBlockInstrument instr = InfinityMethods.getRandomInstrument(); 109 + BlockState bs = Blocks.NOTE_BLOCK.defaultBlockState().setValue(NoteBlock.INSTRUMENT, instr); 110 + if (instr.isTunable()) bs = bs.setValue(NoteBlock.NOTE, InfinityMod.random.nextInt(24)); 111 + return bs; 112 + } 113 + 114 + enum Rule implements SurfaceRules.RuleSource { 115 + INSTANCE; 116 + static final KeyDispatchDataCodec<Rule> CODEC = KeyDispatchDataCodec.of(MapCodec.unit(INSTANCE)); 117 + @Override 118 + public KeyDispatchDataCodec<? extends SurfaceRules.RuleSource> codec() { 119 + return CODEC; 120 + } 121 + @Override 122 + public SurfaceRules.SurfaceRule apply(SurfaceRules.Context materialRuleContext) { 123 + return new Notes(); 97 124 } 98 125 } 99 126 } ··· 412 439 public static void registerRules() { 413 440 register("chaos", RandomBlockMaterialRule.CODEC); 414 441 register("colored_chaos", RandomColoredBlock.Rule.CODEC); 442 + register("notes", Notes.Rule.CODEC); 415 443 register("library", Library.Rule.CODEC); 416 444 register("backrooms", Backrooms.Rule.CODEC); 417 445 register("nexus", Nexus.Rule.CODEC);
+6
src/main/java/net/lerariemann/infinity/util/InfinityMethods.java
··· 27 27 import net.minecraft.world.level.biome.Biome; 28 28 import net.minecraft.world.level.block.entity.BlockEntity; 29 29 import net.minecraft.world.level.block.state.BlockState; 30 + import net.minecraft.world.level.block.state.properties.NoteBlockInstrument; 30 31 import net.minecraft.world.level.levelgen.LegacyRandomSource; 31 32 import net.minecraft.world.level.levelgen.synth.NormalNoise; 32 33 //? if <1.21 { ··· 325 326 } while (false); 326 327 327 328 return 1.0; 329 + } 330 + 331 + static NoteBlockInstrument getRandomInstrument() { 332 + NoteBlockInstrument[] instruments = NoteBlockInstrument.values(); 333 + return instruments[InfinityMod.random.nextInt(instruments.length-7)]; 328 334 } 329 335 }
+114 -12
src/main/resources/config/common/easter/notes.json
··· 1 1 { 2 - "infinity_version": 2006000, 2 + "infinity_version": 2006003, 3 3 "options": { 4 - "haunted": true 4 + "haunted": true, 5 + "solar_texture": "textures/block/redstone_lamp_on.png", 6 + "moons": [ 7 + { 8 + "lunar_texture": "textures/block/note_block.png" 9 + } 10 + ] 5 11 }, 6 12 "generator": { 7 - "type": "minecraft:flat", 13 + "type": "minecraft:noise", 8 14 "settings": { 9 - "biome": "minecraft:the_void", 10 - "lakes": false, 11 - "features": false, 12 - "layers": [ 13 - { 14 - "height": 1, 15 - "block": "minecraft:note_block" 16 - } 17 - ] 15 + "sea_level": 0, 16 + "disable_mob_generation": false, 17 + "ore_veins_enabled": false, 18 + "aquifers_enabled": false, 19 + "legacy_random_source": false, 20 + "default_block": { 21 + "Name": "minecraft:black_concrete" 22 + }, 23 + "default_fluid": { 24 + "Name": "minecraft:water" 25 + }, 26 + "spawn_target": [], 27 + "noise": { 28 + "min_y": 0, 29 + "height": 256, 30 + "size_horizontal": 2, 31 + "size_vertical": 2 32 + }, 33 + "noise_router": { 34 + "vein_ridged": "infinity:vein_ridged", 35 + "fluid_level_spread": 0.0, 36 + "vegetation": "infinity:vegetation", 37 + "vein_gap": "infinity:vein_gap", 38 + "continents": "minecraft:overworld/continents", 39 + "initial_density_without_jaggedness": { 40 + "to_y": 6, 41 + "from_value": 1.0, 42 + "to_value": -1.0, 43 + "from_y": 0, 44 + "type": "minecraft:y_clamped_gradient" 45 + }, 46 + "lava": 0.0, 47 + "barrier": 0.0, 48 + "depth": { 49 + "from_value": 1.5, 50 + "to_y": 256, 51 + "to_value": -1.5, 52 + "type": "minecraft:y_clamped_gradient", 53 + "from_y": 0 54 + }, 55 + "ridges": "minecraft:overworld/ridges", 56 + "erosion": "minecraft:overworld/erosion", 57 + "temperature": "infinity:temperature", 58 + "final_density": { 59 + "to_y": 6, 60 + "from_value": 1.0, 61 + "to_value": -1.0, 62 + "from_y": 0, 63 + "type": "minecraft:y_clamped_gradient" 64 + }, 65 + "vein_toggle": "infinity:vein_toggle", 66 + "fluid_level_floodedness": 0.0 67 + }, 68 + "surface_rule": { 69 + "type": "minecraft:sequence", 70 + "sequence": [ 71 + { 72 + "type": "minecraft:condition", 73 + "if_true": { 74 + "type": "minecraft:not", 75 + "invert": { 76 + "type": "y_above", 77 + "anchor": { 78 + "absolute": 1 79 + }, 80 + "surface_depth_multiplier": 0, 81 + "add_stone_depth": false 82 + } 83 + }, 84 + "then_run": { 85 + "type": "minecraft:block", 86 + "result_state": { 87 + "Name": "minecraft:bedrock" 88 + } 89 + } 90 + }, 91 + { 92 + "type": "minecraft:condition", 93 + "if_true": { 94 + "type": "minecraft:not", 95 + "invert": { 96 + "type": "y_above", 97 + "anchor": { 98 + "absolute": 2 99 + }, 100 + "surface_depth_multiplier": 0, 101 + "add_stone_depth": false 102 + } 103 + }, 104 + "then_run": { 105 + "type": "minecraft:block", 106 + "result_state": { 107 + "Name": "minecraft:stone" 108 + } 109 + } 110 + }, 111 + { 112 + "type": "infinity:notes" 113 + } 114 + ] 115 + } 116 + }, 117 + "biome_source": { 118 + "type": "fixed", 119 + "biome": "minecraft:the_void" 18 120 } 19 121 } 20 122 }