Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.prototype.util;
- import de.prototype.Client;
- import net.minecraft.client.Minecraft;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.init.Blocks;
- import net.minecraft.inventory.Container;
- import net.minecraft.potion.Potion;
- import net.minecraft.util.*;
- public class PlayerUtil extends RotationUtil {
- private Minecraft mc = Minecraft.getMinecraft();
- /**
- * Introducing a method which returns the yaw of the player direction
- *
- * @return
- */
- public float getDirection() {
- float yaw = mc.thePlayer.rotationYaw;
- if (mc.thePlayer.moveForward < 0) yaw += 180;
- float forward = 1;
- if (mc.thePlayer.moveForward < 0)forward = -0.5F;
- else if (mc.thePlayer.moveForward > 0) forward = 0.5F;
- if (mc.thePlayer.moveStrafing > 0) yaw -= 90 * forward;
- if (mc.thePlayer.moveStrafing < 0) yaw += 90 * forward;
- //siehe EntityLivingBase jump()
- return yaw * 0.017453292F;
- }
- public void setMoveSpeed(final double moveSpeed) {
- float forward = mc.thePlayer.movementInput.moveForward;
- float strafe = mc.thePlayer.movementInput.moveStrafe;
- float yaw = mc.thePlayer.rotationYaw;
- if (forward == 0 && strafe == 0) {
- mc.thePlayer.motionX = 0;
- mc.thePlayer.motionZ = 0;
- }
- int i = 45;
- if (forward != 0) {
- if (strafe > 0) yaw += forward > 0 ? -i : i;
- else if (strafe < 0) yaw += forward > 0 ? i : -i;
- strafe = 0;
- if (forward > 0) forward = 1;
- else if (forward < 0) forward = -1;
- }
- mc.thePlayer.motionX = forward * moveSpeed * Math.cos(Math.toRadians(yaw + 90)) + strafe * moveSpeed * Math.sin(Math.toRadians(yaw + 90));
- mc.thePlayer.motionZ = forward * moveSpeed * Math.sin(Math.toRadians(yaw + 90)) - strafe * moveSpeed * Math.cos(Math.toRadians(yaw + 90));
- }
- /**
- * Introducing a method which returns the positions in front of the player where the distance from the player is blocks
- *
- * @param blocks
- * @return
- */
- public double[] getPortPositions(double blocks) {
- return new double[]{-(MathHelper.sin(getDirection()) * blocks), (MathHelper.cos(getDirection()) * blocks)};
- }
- /**
- * Introducing a method which teleports the player to the position, where addedX, addedY, addedZ gets added to his position
- *
- * @param addedX
- * @param addedY
- * @param addedZ
- */
- public void teleportPlayer(double addedX, double addedY, double addedZ) {
- mc.thePlayer.setPositionAndUpdate(mc.thePlayer.posX + addedX, mc.thePlayer.posY + addedY, mc.thePlayer.posZ + addedZ);
- }
- public void teleportPlayerSmooth(double addedX, double addedY, double addedZ) {
- mc.thePlayer.setPosition(mc.thePlayer.posX + addedX, mc.thePlayer.posY + addedY, mc.thePlayer.posZ + addedZ);
- }
- /**
- * Introducing a method which sets the speed of the game
- *
- * @param timerSpeed
- */
- public void setTimerSpeed(float timerSpeed) {
- mc.timer.timerSpeed = timerSpeed;
- }
- /**
- * Introducing a method which set's the speed(motion) of the player
- *
- * @param speed
- */
- public void setSpeed(final float speed) {
- mc.thePlayer.motionX *= speed;
- mc.thePlayer.motionZ *= speed;
- }
- public void setStrafingSpeed(double speed) {
- mc.thePlayer.motionX = (-(Math.sin(getDirection()) * speed));
- mc.thePlayer.motionZ = (Math.cos(getDirection()) * speed);
- }
- /**
- * Introducing a method which set's the speed(motion) of the player
- *
- * @param speedX
- * @param speedZ
- */
- public void setSpeed(final double speedX, final double speedZ) {
- mc.thePlayer.motionX *= speedX;
- mc.thePlayer.motionZ *= speedZ;
- }
- /**
- * Introducing a method which returns if the player is moving
- *
- * @return
- */
- public boolean isMoving() {
- return mc.thePlayer.movementInput.moveForward != 0 || mc.thePlayer.movementInput.moveStrafe != 0;
- }
- /**
- * Introducing a method which returns true if the inventory is full
- *
- * @return
- */
- public boolean isInventoryFull() {
- Container container = mc.thePlayer.inventoryContainer;
- for (int i = 0; i < container.getInventory().size(); i++)
- if (container.getSlot(i).getStack() == null) return true;
- return false;
- }
- /**
- * Introducing a method which send a chat message for me(clientSide or for everyone)
- *
- * @param message
- * @param forEveryone
- */
- public void sendChatMessage(final String message, final boolean forEveryone) {
- if (forEveryone) this.mc.thePlayer.sendChatMessage(message);
- else
- this.mc.thePlayer.addChatMessage(new ChatComponentText("§f[§6" + Client.getINSTANCE().getCLIENT_NAME() + "§f] §7" + message));
- }
- /**
- * Introducing a method which checks ob i can step true or false
- *
- * @param stepHeight
- * @return
- */
- public int isAllowedToStep(double stepHeight) {
- int toBlock = -1;
- final double[] positions = this.getPortPositions(0.4);
- for (int i = 0; i < stepHeight; i++) {
- final BlockPos pos = new BlockPos(mc.thePlayer.posX + positions[0], mc.thePlayer.posY + i, mc.thePlayer.posZ + positions[1]);
- if (mc.theWorld.getBlockState(pos) != null && mc.theWorld.getBlockState(pos).getBlock() != Blocks.air)
- if (mc.theWorld.getBlockState(pos.add(0, 1, 0)).getBlock() == Blocks.air && mc.theWorld.getBlockState(pos.add(0, 2, 0)).getBlock() == Blocks.air)
- toBlock = i;
- }
- return toBlock + 1;
- }
- /**
- * Introducing a method which returns the default speed of the player
- *
- * @return
- */
- public double getDefaultSpeed() {
- double defaultSpeed = 0.2873;
- if (mc.thePlayer.isPotionActive(Potion.moveSpeed)) {
- int speed = mc.thePlayer.getActivePotionEffect(Potion.moveSpeed).getAmplifier();
- defaultSpeed *= 1 + 0.2 * (speed + 1);
- }
- return defaultSpeed;
- }
- /**
- * Introducing a method which can see if the entity is in the same team
- *
- * @param entityPlayer
- * @return
- */
- public boolean isEnemy(EntityPlayer entityPlayer) {
- return (mc.thePlayer.getTeam().equals(entityPlayer.getTeam())
- || (mc.thePlayer.getDisplayName().getFormattedText().startsWith("§")
- && entityPlayer.getDisplayName().getFormattedText().startsWith("§")
- && mc.thePlayer.getDisplayName().getFormattedText().substring(0, 2).equals(entityPlayer.getDisplayName().getFormattedText().substring(0, 2))));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement