mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 00:38:35 +01:00
TeleStaff "Should" be ready...
This commit is contained in:
parent
62b1859abb
commit
0146333e37
1 changed files with 19 additions and 35 deletions
|
@ -11,17 +11,17 @@
|
||||||
package de.ellpeck.actuallyadditions.mod.items;
|
package de.ellpeck.actuallyadditions.mod.items;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.mod.items.base.ItemEnergy;
|
import de.ellpeck.actuallyadditions.mod.items.base.ItemEnergy;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||||
import net.minecraft.init.SoundEvents;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.ActionResult;
|
import net.minecraft.util.ActionResult;
|
||||||
import net.minecraft.util.EnumActionResult;
|
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
import net.minecraft.util.SoundCategory;
|
import net.minecraft.util.SoundCategory;
|
||||||
|
import net.minecraft.util.SoundEvents;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.BlockRayTraceResult;
|
||||||
import net.minecraft.util.math.RayTraceResult;
|
import net.minecraft.util.math.RayTraceResult;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.vector.Vector3d;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class ItemTeleStaff extends ItemEnergy {
|
public class ItemTeleStaff extends ItemEnergy {
|
||||||
|
@ -34,41 +34,25 @@ public class ItemTeleStaff extends ItemEnergy {
|
||||||
public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, Hand hand) {
|
public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, Hand hand) {
|
||||||
ItemStack stack = player.getHeldItem(hand);
|
ItemStack stack = player.getHeldItem(hand);
|
||||||
if (!world.isRemote) {
|
if (!world.isRemote) {
|
||||||
RayTraceResult pos = WorldUtil.getNearestPositionWithAir(world, player, 100);
|
RayTraceResult rayTraceResult = player.pick(100,0,false);
|
||||||
if (pos != null && (pos.typeOfHit == RayTraceResult.Type.BLOCK || player.rotationPitch >= -5)) {
|
if (rayTraceResult != null && (rayTraceResult.getType() == RayTraceResult.Type.BLOCK || player.rotationPitch >= -5)) {
|
||||||
int side = pos.sideHit.ordinal();
|
BlockRayTraceResult res = (BlockRayTraceResult)rayTraceResult;
|
||||||
if (side != -1) {
|
BlockPos pos = res.getPos().offset(res.getFace());
|
||||||
double x = pos.hitVec.x - (side == 4
|
int baseUse = 200;
|
||||||
? 0.5
|
int use = baseUse + (int) (baseUse * rayTraceResult.getHitVec().distanceTo(new Vector3d(player.getPosX(), player.getPosY() + (player.getEyeHeight() - player.getEyeHeight()), player.getPosZ())));
|
||||||
: 0) + (side == 5
|
if (this.getEnergyStored(stack) >= use) {
|
||||||
? 0.5
|
((ServerPlayerEntity) player).connection.setPlayerLocation(pos.getX(), pos.getY(), pos.getY(), player.rotationYaw, player.rotationPitch);
|
||||||
: 0);
|
player.dismount();
|
||||||
double y = pos.hitVec.y - (side == 0
|
world.playSound(null, player.getPosX(), player.getPosY(), player.getPosZ(), SoundEvents.ENTITY_ENDERMAN_TELEPORT, SoundCategory.PLAYERS, 1.0F, 1.0F);
|
||||||
? 2.0
|
if (!player.isCreative()) {
|
||||||
: 0) + (side == 1
|
this.extractEnergyInternal(stack, use, false);
|
||||||
? 0.5
|
player.getCooldownTracker().setCooldown(this, 50);
|
||||||
: 0);
|
|
||||||
double z = pos.hitVec.z - (side == 2
|
|
||||||
? 0.5
|
|
||||||
: 0) + (side == 3
|
|
||||||
? 0.5
|
|
||||||
: 0);
|
|
||||||
int baseUse = 200;
|
|
||||||
int use = baseUse + (int) (baseUse * pos.hitVec.distanceTo(new Vec3d(player.posX, player.posY + (player.getEyeHeight() - player.getDefaultEyeHeight()), player.posZ)));
|
|
||||||
if (this.getEnergyStored(stack) >= use) {
|
|
||||||
((ServerPlayerEntity) player).connection.setPlayerLocation(x, y, z, player.rotationYaw, player.rotationPitch);
|
|
||||||
player.dismountRidingEntity();
|
|
||||||
world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.PLAYERS, 1.0F, 1.0F);
|
|
||||||
if (!player.isCreative()) {
|
|
||||||
this.extractEnergyInternal(stack, use, false);
|
|
||||||
player.getCooldownTracker().setCooldown(this, 50);
|
|
||||||
}
|
|
||||||
return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
|
|
||||||
}
|
}
|
||||||
|
return ActionResult.resultSuccess(stack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
player.swingArm(hand);
|
player.swingArm(hand);
|
||||||
return ActionResult.newResult(EnumActionResult.FAIL, stack);
|
return ActionResult.resultFail(stack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue