Inspired by 2020's April Fools' 20w14infinite Snapshot, this mod brings endless randomly generated dimensions into Minecraft.
at master 48 lines 2.2 kB view raw
1package net.lerariemann.infinity.item; 2 3import net.lerariemann.infinity.block.custom.AltarBlock; 4import net.lerariemann.infinity.block.custom.IridescentBlock; 5import net.lerariemann.infinity.block.entity.ChromaticBlockEntity; 6import net.lerariemann.infinity.util.InfinityMethods; 7import net.minecraft.core.BlockPos; 8import net.minecraft.sounds.SoundEvents; 9import net.minecraft.sounds.SoundSource; 10import net.minecraft.world.InteractionResult; 11import net.minecraft.world.entity.player.Player; 12import net.minecraft.world.item.Item; 13import net.minecraft.world.item.context.UseOnContext; 14import net.minecraft.world.level.Level; 15import net.minecraft.world.level.block.state.BlockState; 16 17public class IridescentStarItem extends Item { 18 public IridescentStarItem(Properties settings) { 19 super(settings); 20 } 21 22 @Override 23 public InteractionResult useOn(UseOnContext context) { 24 Player player = context.getPlayer(); 25 if (player == null) return super.useOn(context); 26 Level world = context.getLevel(); 27 BlockPos pos = context.getClickedPos(); 28 BlockState oldState = world.getBlockState(pos); 29 boolean reverse = player.isShiftKeyDown(); 30 if (world.getBlockEntity(pos) instanceof ChromaticBlockEntity cbe) { 31 cbe.onIridStarUse(reverse); 32 } 33 else if (oldState.getBlock() instanceof AltarBlock) { 34 AltarBlock.setColor(world, pos, oldState, 35 InfinityMethods.properMod(oldState.getValue(AltarBlock.COLOR) + (reverse ? -1 : 1), 36 AltarBlock.numColors)); 37 } 38 else if (oldState.getBlock() instanceof IridescentBlock) { 39 world.setBlockAndUpdate(pos, oldState.setValue(IridescentBlock.COLOR_OFFSET, 40 InfinityMethods.properMod(oldState.getValue(IridescentBlock.COLOR_OFFSET) + (reverse ? -1 : 1), 41 IridescentBlock.num_models))); 42 } 43 else return super.useOn(context); 44 if (!world.isClientSide()) 45 world.playSound(null, pos, SoundEvents.AMETHYST_BLOCK_RESONATE, SoundSource.BLOCKS, 1f, 1f); 46 return InteractionResult.SUCCESS; 47 } 48}