2015-08-29 14:33:25 +02:00
|
|
|
/*
|
2016-05-16 22:52:27 +02:00
|
|
|
* This file ("ItemTeleStaff.java") is part of the Actually Additions mod for Minecraft.
|
2015-08-29 14:33:25 +02:00
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-05-16 22:52:27 +02:00
|
|
|
* http://ellpeck.de/actaddlicense
|
2015-08-29 14:33:25 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2017-01-01 16:23:26 +01:00
|
|
|
* © 2015-2017 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.items;
|
2015-07-07 20:20:24 +02:00
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.items.base.ItemEnergy;
|
2024-03-03 01:20:53 +01:00
|
|
|
import net.minecraft.core.BlockPos;
|
2024-03-02 21:23:08 +01:00
|
|
|
import net.minecraft.server.level.ServerPlayer;
|
|
|
|
import net.minecraft.sounds.SoundEvents;
|
|
|
|
import net.minecraft.sounds.SoundSource;
|
|
|
|
import net.minecraft.world.InteractionHand;
|
|
|
|
import net.minecraft.world.InteractionResultHolder;
|
|
|
|
import net.minecraft.world.entity.player.Player;
|
|
|
|
import net.minecraft.world.item.ItemStack;
|
|
|
|
import net.minecraft.world.level.Level;
|
|
|
|
import net.minecraft.world.phys.HitResult;
|
|
|
|
import net.minecraft.world.phys.Vec3;
|
2015-07-07 20:20:24 +02:00
|
|
|
|
2022-06-13 00:13:33 +02:00
|
|
|
public class ItemTeleportStaff extends ItemEnergy {
|
2015-07-07 20:20:24 +02:00
|
|
|
|
2022-06-13 00:13:33 +02:00
|
|
|
public ItemTeleportStaff() {
|
2021-04-19 21:20:23 +02:00
|
|
|
super(250000, 1000);
|
2015-07-07 20:20:24 +02:00
|
|
|
}
|
|
|
|
|
2015-07-07 21:13:52 +02:00
|
|
|
@Override
|
2024-03-02 21:23:08 +01:00
|
|
|
public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
|
2021-08-22 17:09:06 +02:00
|
|
|
ItemStack stack = player.getItemInHand(hand);
|
|
|
|
if (!world.isClientSide) {
|
2024-03-02 21:23:08 +01:00
|
|
|
HitResult rayTraceResult = player.pick(100,1F,false);
|
|
|
|
if (rayTraceResult.getType() == HitResult.Type.BLOCK || player.getXRot() >= -5) {
|
|
|
|
Vec3 location = rayTraceResult.getLocation();
|
2024-03-03 01:20:53 +01:00
|
|
|
Vec3 pos = Vec3.atBottomCenterOf(BlockPos.containing(location.x, location.y, location.z));
|
2021-05-01 23:05:32 +02:00
|
|
|
int baseUse = 200;
|
2024-03-03 01:20:53 +01:00
|
|
|
int use = baseUse + (int) (baseUse * player.blockPosition().distSqr(BlockPos.containing(pos.x, pos.y, pos.z)));
|
2021-05-01 23:05:32 +02:00
|
|
|
if (this.getEnergyStored(stack) >= use) {
|
2024-03-02 21:23:08 +01:00
|
|
|
((ServerPlayer) player).connection.teleport(pos.x, pos.y + 1F, pos.z, player.getYRot(), player.getXRot());
|
2021-08-22 17:09:06 +02:00
|
|
|
player.removeVehicle();
|
2024-03-02 21:23:08 +01:00
|
|
|
world.playSound(null, player.getX(), player.getY(), player.getZ(), SoundEvents.ENDERMAN_TELEPORT, SoundSource.PLAYERS, 1.0F, 1.0F);
|
2021-05-01 23:05:32 +02:00
|
|
|
if (!player.isCreative()) {
|
|
|
|
this.extractEnergyInternal(stack, use, false);
|
2021-08-22 17:09:06 +02:00
|
|
|
player.getCooldowns().addCooldown(this, 50);
|
2015-10-03 10:19:40 +02:00
|
|
|
}
|
2024-03-02 21:23:08 +01:00
|
|
|
return InteractionResultHolder.success(stack);
|
2015-10-03 10:19:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-08-22 17:09:06 +02:00
|
|
|
player.swing(hand);
|
2024-03-02 21:23:08 +01:00
|
|
|
return InteractionResultHolder.fail(stack);
|
2015-07-07 21:13:52 +02:00
|
|
|
}
|
2015-07-07 20:20:24 +02:00
|
|
|
}
|