package com.thebrokenrail.reliccraft.mixin; import com.thebrokenrail.reliccraft.RelicCraft; import com.thebrokenrail.reliccraft.block.AbstractDragonEggHolderBlock; import net.minecraft.block.BlockState; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.EnderPearlItem; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemUsageContext; import net.minecraft.nbt.CompoundTag; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.ActionResult; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.dimension.DimensionType; import org.spongepowered.asm.mixin.Mixin; import java.util.Objects; @SuppressWarnings("unused") @Mixin(EnderPearlItem.class) public class MixinEnderPearlItem extends Item { public MixinEnderPearlItem(Settings settings) { super(settings); } @Override public ActionResult useOnBlock(ItemUsageContext context) { World world = context.getWorld(); BlockPos pos = context.getBlockPos(); String dimension = world.getRegistryKey().toString(); BlockState state = world.getBlockState(pos); PlayerEntity user = context.getPlayer(); if (user != null && state.getBlock() == RelicCraft.TELEPORTATION_BEACON_BLOCK && state.get(AbstractDragonEggHolderBlock.ACTIVE)) { if (!world.isClient()) { RelicCraft.playRelicSound(user); } CompoundTag tag = new CompoundTag(); tag.putInt("TargetX", pos.getX()); tag.putInt("TargetY", pos.getY()); tag.putInt("TargetZ", pos.getZ()); tag.putString("TargetDimension", dimension); ItemStack itemStack = new ItemStack(RelicCraft.TARGETED_ENDER_PEARL_ITEM); itemStack.setTag(tag); ItemStack itemStack2 = user.getStackInHand(context.getHand()); if (!user.isCreative()) { itemStack2.decrement(1); } if (!user.inventory.insertStack(itemStack.copy())) { user.dropItem(itemStack, false); } if (!world.isClient()) { RelicCraft.USE_TELEPORTATION_BEACON_CRITERION.trigger((ServerPlayerEntity) user); } return ActionResult.SUCCESS; } else { return ActionResult.PASS; } } }