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

71 lines
2.4 KiB
Java
Raw Normal View History

2020-04-04 02:32:34 +00:00
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 (!world.isClient()) {
assert user != null;
RelicCraft.playRelicSound(user);
}
if (user != null && state.getBlock() == RelicCraft.TELEPORTATION_BEACON_BLOCK && state.get(AbstractDragonEggHolderBlock.ACTIVE)) {
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;
}
}
}