Something went wrong. Try again.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152package net.codexarchonic.infinity.item;
import net.codexarchonic.infinity.block.custom.AltarBlock;import net.codexarchonic.infinity.block.custom.IridescentBlock;import net.codexarchonic.infinity.block.entity.ChromaticBlockEntity;import net.codexarchonic.infinity.util.InfinityMethods;import net.minecraft.core.BlockPos;import net.minecraft.sounds.SoundEvents;import net.minecraft.sounds.SoundSource;import net.minecraft.world.InteractionResult;import net.minecraft.world.entity.player.Player;import net.minecraft.world.item.Item;import net.minecraft.world.item.context.UseOnContext;import net.minecraft.world.level.Level;import net.minecraft.world.level.block.state.BlockState;import net.minecraft.world.level.gameevent.GameEvent;
public class IridescentStarItem extends Item { public IridescentStarItem(Properties settings) { super(settings); }
@Override public InteractionResult useOn(UseOnContext context) { Player player = context.getPlayer(); if (player == null) return super.useOn(context); Level world = context.getLevel(); BlockPos pos = context.getClickedPos(); BlockState oldState = world.getBlockState(pos); boolean reverse = player.isShiftKeyDown(); if (world.getBlockEntity(pos) instanceof ChromaticBlockEntity cbe) { cbe.onIridStarUse(reverse); } else if (oldState.getBlock() instanceof AltarBlock) { AltarBlock.setColor(world, pos, oldState, InfinityMethods.properMod(oldState.getValue(AltarBlock.COLOR) + (reverse ? -1 : 1), AltarBlock.numColors)); } else if (oldState.getBlock() instanceof IridescentBlock) { world.setBlockAndUpdate(pos, oldState.setValue(IridescentBlock.COLOR_OFFSET, InfinityMethods.properMod(oldState.getValue(IridescentBlock.COLOR_OFFSET) + (reverse ? -1 : 1), IridescentBlock.num_models))); } else return super.useOn(context); if (!world.isClientSide()) { world.playSound(null, pos, SoundEvents.AMETHYST_BLOCK_RESONATE, SoundSource.BLOCKS, 1f, 1f); world.gameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Context.of(player, world.getBlockState(pos))); } return InteractionResult.SUCCESS; }}