This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
RelicCraft/src/main/java/com/thebrokenrail/reliccraft/mixin/MixinEnderPearlItem.java
TheBrokenRail debafe02fb
All checks were successful
RelicCraft/pipeline/head This commit looks good
1.0.15
Fix Ender Pearl Bug
2020-04-10 20:25:42 -04:00

70 lines
2.4 KiB
Java

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 = Objects.requireNonNull(DimensionType.getId(world.getDimension().getType())).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;
}
}
}