@SubscribeEvent public void playerTick(TickEvent.PlayerTickEvent event) { EntityPlayer player = event.player; TPlayerStats stats = TPlayerStats.get(player); // Wall climb if (stats.climbWalls) { double motionX = player.posX - player.lastTickPosX; double motionZ = player.posZ - player.lastTickPosZ; double motionY = player.posY - player.lastTickPosY - 0.762; if (motionY > 0.0D && (motionX == 0D || motionZ == 0D)) { player.fallDistance = 0.0F; } } // Feet changes ItemStack feet = player.getCurrentArmor(0); if (feet != null) { if (feet.getItem() instanceof IModifyable && !player.isSneaking()) { NBTTagCompound tag = feet.getTagCompound().getCompoundTag(((IModifyable) feet.getItem()).getBaseTagName()); int sole = tag.getInteger("Slimy Soles"); if (sole > 0) { if (!player.isSneaking() && player.onGround && prevMotionY < -0.4) player.motionY = -prevMotionY * (Math.min(0.99, sole * 0.2)); } } prevMotionY = player.motionY; } if (feet != prevFeet) { if (prevFeet != null && prevFeet.getItem() instanceof TravelGear) player.stepHeight -= 0.6f; if (feet != null && feet.getItem() instanceof TravelGear) player.stepHeight += 0.6f; prevFeet = feet; } // TODO: Proper minimap support /*ItemStack stack = player.inventory.getStackInSlot(8); if (stack != null && stack.getItem() instanceof ItemMap) { stack.getItem().onUpdate(stack, player.worldObj, player, 8, true); }*/ if (!player.isPlayerSleeping()) { ItemStack chest = player.getCurrentArmor(2); if (chest == null || !(chest.getItem() instanceof IModifyable)) { if (!morphLoaded || !morphed) PlayerAbilityHelper.setEntitySize(player, 0.6F, 1.8F); } else { NBTTagCompound tag = chest.getTagCompound().getCompoundTag(((IModifyable) chest.getItem()).getBaseTagName()); int dodge = tag.getInteger("Perfect Dodge"); if (dodge > 0) { if (!morphLoaded || !morphed) PlayerAbilityHelper.setEntitySize( player, Math.max(0.15F, 0.6F - (dodge * 0.09f)), 1.8F - (dodge * 0.04f)); } } } }
@ForgeSubscribe public void onPlayerJump(LivingJumpEvent event) { if (event.entityLiving instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) event.entityLiving; boolean hasArmor = player.getCurrentArmor(0) != null && player.getCurrentArmor(0).itemID == itemID; if (hasArmor) player.motionY += 0.3; } }
@Override public void tick() { if (getParent() instanceof EntityPlayer) { if (Morph.config.getSessionInt("allowFlight") == 0) { return; } EntityPlayer player = (EntityPlayer) getParent(); if (!player.capabilities.allowFlying) { player.capabilities.allowFlying = true; player.sendPlayerAbilities(); } if (player.capabilities.isFlying && !player.capabilities.isCreativeMode) { double motionX = player.worldObj.isRemote ? player.motionX : player.posX - player.lastTickPosX; double motionZ = player.worldObj.isRemote ? player.motionZ : player.posZ - player.lastTickPosZ; int i = Math.round(MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ) * 100.0F); if (i > 0 && i < 10) { if (player.isInWater() && slowdownInWater) { player.addExhaustion(0.125F * (float) i * 0.01F); } else { player.addExhaustion(0.035F * (float) i * 0.01F); } } else { player.addExhaustion(0.002F); } if (player.worldObj.isRemote && player.isInWater() && slowdownInWater) { MorphInfo info = Morph.proxy.tickHandlerClient.playerMorphInfo.get(player.getCommandSenderName()); if (info != null) { boolean swim = false; for (Ability ability : info.morphAbilities) { if (ability.getType().equalsIgnoreCase("swim")) { swim = true; break; } } if (!swim) { player.motionX *= 0.65D; player.motionZ *= 0.65D; player.motionY *= 0.2D; } } } } } getParent().fallDistance = 0.0F; // TODO make "Thing" take note of this so it can fly... }
@Override public ServerPacket onMessage(ClientPacket message, MessageContext ctx) { ByteBuf buffer = message.buffer; byte mess = buffer.readByte(); if (mess == 0) { double y = buffer.readDouble(); double dy = buffer.readDouble(); EntityPlayer player = ThutCore.proxy.getPlayer(); y += player.getYOffset(); player.motionY = Math.max(dy, player.motionY); ThutCore.proxy.getPlayer().setPosition(player.posX, y, player.posZ); } return null; }
public boolean onItemUse( ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { if (world.getBlock(x, y, z) != Blocks.air) { if (hammerType.equals(EnumHammerType.POGO)) { player.motionY = Math.abs(player.motionY) + 0.5; player.fallDistance = 0; stack.damageItem(1, player); return true; } } return false; }
@Override public ItemStack onFocusRightClick( ItemStack itemstack, World world, EntityPlayer p, MovingObjectPosition movingobjectposition) { ItemWandCasting wand = (ItemWandCasting) itemstack.getItem(); if (!ConfigHandler.enableFlight) { return itemstack; } if (wand.consumeAllVis(itemstack, p, getVisCost(), true, false)) { Vec3 vec = p.getLookVec(); double force = 1 / 1.5 * (1 + EnchantmentHelper.getEnchantmentLevel( Config.enchPotency.effectId, wand.getFocusItem(itemstack)) * 0.2); p.motionX = vec.xCoord * force; p.motionY = vec.yCoord * force; p.motionZ = vec.zCoord * force; p.fallDistance = 0F; if (p instanceof EntityPlayerMP) { ((EntityPlayerMP) p).playerNetServerHandler.floatingTickCount = 0; } for (int i = 0; i < 5; i++) ThaumicTinkerer.tcProxy.smokeSpiral( world, p.posX, p.posY - p.motionY, p.posZ, 2F, (int) (Math.random() * 360), (int) p.posY); world.playSoundAtEntity(p, "thaumcraft:wind", 0.4F, 1F); } if (world.isRemote) p.swingItem(); return itemstack; }
@SubscribeEvent public void onLivingUpdate(LivingUpdateEvent event) { if (event.entity instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) event.entity; ZSSPlayerInfo.get(player).onUpdate(); if (player.motionY < -0.25D) { boolean flag = player.getHeldItem() != null && player.getHeldItem().getItem() == ZSSItems.rocsFeather; if (flag || (player.getCurrentArmor(ArmorIndex.WORN_HELM) != null && player.getCurrentArmor(ArmorIndex.WORN_HELM).getItem() == ZSSItems.maskDeku)) { player.motionY = -0.25D; player.fallDistance = 0.0F; } } } if (event.entity instanceof EntityLivingBase) { ZSSEntityInfo.get((EntityLivingBase) event.entity).onUpdate(); } if (event.entity instanceof EntityVillager) { ZSSVillagerInfo.get((EntityVillager) event.entity).onUpdate(); } }
@Override public void control(EntityPlayerCustom playerCustom, EntityPlayer player, Side side) { int x = MathHelper.floor_double(player.posX); int y = MathHelper.floor_double(player.posY); int z = MathHelper.floor_double(player.posZ); int heading = MathHelper.floor_double((double) (player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; if (!playerCustom.isSneaking) { if (((((Util.isCube(player.worldObj.getBlock(x, y, z - 1)) && heading == 2) || (Util.isCube(player.worldObj.getBlock(x, y, z + 1)) && heading == 0) || (Util.isCube(player.worldObj.getBlock(x - 1, y, z)) && heading == 1) || (Util.isCube(player.worldObj.getBlock(x + 1, y, z)) && heading == 3)) && ((!Util.isCube(player.worldObj.getBlock(x, y + 1, z - 1)) && heading == 2) || (!Util.isCube(player.worldObj.getBlock(x, y + 1, z + 1)) && heading == 0) || (!Util.isCube(player.worldObj.getBlock(x - 1, y + 1, z)) && heading == 1) || (!Util.isCube(player.worldObj.getBlock(x + 1, y + 1, z)) && heading == 3)) && (!Util.isCube(player.worldObj.getBlock(x, y - 2, z))))) && player.worldObj.getBlock(x, y, z) != Blocks.ladder && player.getCurrentEquippedItem() == null) { playerCustom.isGrabbing = true; playerCustom.rotationYaw = player.rotationYaw; playerCustom.rotationPitch = player.rotationPitch; playerCustom.prevRotationPitch = player.prevRotationPitch; playerCustom.prevRotationYaw = player.prevRotationYaw; playerCustom.grabbingDirections[heading] = true; if (heading == 0) { playerCustom.grabbingDirections[3] = true; } else { playerCustom.grabbingDirections[heading - 1] = true; } if (heading == 3) { playerCustom.grabbingDirections[0] = true; } else { playerCustom.grabbingDirections[heading + 1] = true; } } else { playerCustom.isGrabbing = false; playerCustom.rotationYaw = 0; if (!playerCustom.isRolling) { playerCustom.rotationPitch = 0; } playerCustom.prevRotationPitch = 0; playerCustom.prevRotationYaw = 0; playerCustom.grabbingDirections[0] = false; playerCustom.grabbingDirections[1] = false; playerCustom.grabbingDirections[2] = false; playerCustom.grabbingDirections[3] = false; } if (playerCustom.isGrabbing && !playerCustom.wasSneaking && player.isSneaking()) { playerCustom.wasSneaking = true; } if (!playerCustom.isGrabbing) { playerCustom.wasSneaking = false; } if (playerCustom.wasSneaking) { return; } if (!player.isSneaking() && !(Boolean) ObfuscationReflectionHelper.getPrivateValue( EntityLivingBase.class, (EntityLivingBase) player, 41) && playerCustom.isGrabbing) { if (heading == 1 || heading == 3) { player.setPosition(x + 0.5F, y + 0.9F, player.posZ); player.motionX = 0; } if (heading == 2 || heading == 0) { player.setPosition(player.posX, y + 0.9F, z + 0.5F); player.motionZ = 0; } player.motionY = 0.0; if (player.isSprinting()) { player.setSprinting(false); } } else if ((Boolean) ObfuscationReflectionHelper.getPrivateValue( EntityLivingBase.class, (EntityLivingBase) player, 41) && playerCustom.isGrabbing) { player.motionY = 0.55D; } } // if(side == Side.CLIENT){ //// Util.channel.sendToServer(new CPacketPlayerAction(playerCustom.isGrabbing ? 0 : 1)); // } // // if(side == Side.SERVER){ // System.out.println("1 : " + playerCustom.isGrabbing); // } /* CLIENT */ if (!player.worldObj.isRemote) { if (playerCustom.isGrabbing && !player.capabilities.isCreativeMode) { PotionEffect potioneffect = player.getActivePotionEffect(Potion.jump); float f1 = potioneffect != null ? (float) (potioneffect.getAmplifier() + 1) : 0.0F; int i = MathHelper.ceiling_float_int(player.fallDistance - 3.0F - f1); if (i > 0) { player.playSound( i > 4 ? "game.neutral.hurt.fall.big" : "game.neutral.hurt.fall.small", 1.0F, 1.0F); damageEntity(EntityLivingBase.class, player, DamageSource.fall, (float) i); } player.fallDistance = 0; } } }
@SubscribeEvent public void playerTick(TickEvent.PlayerTickEvent event) { EntityPlayer player = event.player; TPlayerStats stats = TPlayerStats.get(player); if (mc.thePlayer.onGround) { controlInstance.landOnGround(); } if (stats.climbWalls && player.isCollidedHorizontally && !player.isSneaking()) { player.motionY = 0.1176D; player.fallDistance = 0.0f; } // Feet changes - moved to server side /*ItemStack feet = player.getCurrentArmor(0); if (feet != null) { if (feet.getItem() instanceof TravelGear && player.stepHeight < 1.0f) { player.stepHeight += 0.6f; } if (feet.getItem() instanceof IModifyable && !player.isSneaking()) { NBTTagCompound tag = feet.getTagCompound().getCompoundTag(((IModifyable) feet.getItem()).getBaseTagName()); int sole = tag.getInteger("Slimy Soles"); if (sole > 0) { if (!player.isSneaking() && player.onGround && prevMotionY < -0.4) player.motionY = -prevMotionY * (Math.min(0.99, sole * 0.2)); } } prevMotionY = player.motionY; } if (feet != prevFeet) { if (prevFeet != null && prevFeet.getItem() instanceof TravelGear) player.stepHeight -= 0.6f; if (feet != null && feet.getItem() instanceof TravelGear) player.stepHeight += 0.6f; prevFeet = feet; }*/ // Legs or wing changes /*ItemStack legs = player.getCurrentArmor(1); if (legs != null && legs.getItem() instanceof IModifyable) { NBTTagCompound tag = legs.getTagCompound().getCompoundTag(((IModifyable) legs.getItem()).getBaseTagName()); if (player.isSprinting()) { if (!sprint) { sprint = true; int sprintboost = tag.getInteger("Sprint Assist"); if (player.isSprinting() && sprintboost > 0) { prevMouseSensitivity = gs.mouseSensitivity; gs.mouseSensitivity *= 1 - (0.15 * sprintboost); } } } else if (sprint) { sprint = false; gs.mouseSensitivity = prevMouseSensitivity; } }*/ if (!player.isPlayerSleeping() && !morphed) { ItemStack chest = player.getCurrentArmor(2); if (chest == null || !(chest.getItem() instanceof IModifyable)) { PlayerAbilityHelper.setEntitySize(player, 0.6F, 1.8F); } else { NBTTagCompound tag = chest.getTagCompound().getCompoundTag(((IModifyable) chest.getItem()).getBaseTagName()); int dodge = tag.getInteger("Perfect Dodge"); if (dodge > 0) { PlayerAbilityHelper.setEntitySize( player, Math.max(0.15F, 0.6F - (dodge * 0.09f)), 1.8F - (dodge * 0.04f)); } } } }
public void tickStart(EntityPlayer player) { if (renderPlayer.isEmpty()) { Field[] fields = RenderManager.class.getDeclaredFields(); for (Field f : fields) { if (Map.class.isAssignableFrom(f.getType())) { boolean changed = false; if (!f.isAccessible()) { f.setAccessible(true); changed = true; } try { Map map = (Map) f.get(mc.getRenderManager()); Object object = map.keySet().iterator().next(); if (object instanceof String) { renderPlayer.addAll(map.values()); for (RenderPlayer render : renderPlayer) { render.layerRenderers.add(new LayerOffhandItem(render)); if (Arrays.binarySearch(BattlegearConfig.disabledRenderers, "quiver") < 0) render.layerRenderers.add(new LayerQuiver(render)); } break; } else if (changed) { f.setAccessible(false); } } catch (Throwable ignored) { } } } } if (((IBattlePlayer) player).isBattlemode()) { ItemStack offhand = ((InventoryPlayerBattle) player.inventory).getCurrentOffhandWeapon(); if (offhand != null) { if (offhand.getItem() instanceof IShield) { if (flashTimer == FLASH_MAX) { player.motionY = player.motionY / 2; } if (flashTimer > 0) { flashTimer--; } if (mc.gameSettings.keyBindUseItem.isKeyDown() && !player.isSwingInProgress) { blockBar -= ((IShield) offhand.getItem()).getDecayRate(offhand); if (blockBar > 0) { if (!wasBlocking) { Battlegear.packetHandler.sendPacketToServer( new BattlegearShieldBlockPacket(true, player).generatePacket()); } wasBlocking = true; } else { if (wasBlocking) { // Send packet Battlegear.packetHandler.sendPacketToServer( new BattlegearShieldBlockPacket(false, player).generatePacket()); } wasBlocking = false; blockBar = 0; } } else { if (wasBlocking) { // send packet Battlegear.packetHandler.sendPacketToServer( new BattlegearShieldBlockPacket(false, player).generatePacket()); } wasBlocking = false; blockBar += ((IShield) offhand.getItem()).getRecoveryRate(offhand); if (blockBar > 1) { blockBar = 1; } } } else if (mc.gameSettings.keyBindUseItem.isKeyDown() && mc.rightClickDelayTimer == 4 && !player.isUsingItem()) { tryCheckUseItem(offhand, player); } } } }
public static void eject(EntityPlayer p) { p.motionY += 1.2; }
@SubscribeEvent public void sleepInBed(PlayerSleepInBedEvent event) { SettingEntry se = null; if (event.entityPlayer.worldObj.isRemote) { se = PerfectSpawnClientHandler.currentServerSettings; } else { se = PerfectSpawn.settings.getValidSettingEntry(); } if (se != null && se.forceBed) { WorldProvider provider = event.entityPlayer.worldObj.provider; EntityPlayer player = event.entityPlayer; World worldObj = player.worldObj; if (provider.dimensionId == se.spawnDimension) { event.result = EntityPlayer.EnumStatus.OK; if (player.isPlayerSleeping() || !player.isEntityAlive()) { event.result = EntityPlayer.EnumStatus.OTHER_PROBLEM; } if (!player.worldObj.isDaytime() && provider.isSurfaceWorld()) { event.result = EntityPlayer.EnumStatus.NOT_POSSIBLE_NOW; } if (Math.abs(player.posX - (double) event.x) > 3.0D || Math.abs(player.posY - (double) event.y) > 2.0D || Math.abs(player.posZ - (double) event.z) > 3.0D) { event.result = EntityPlayer.EnumStatus.TOO_FAR_AWAY; } double d0 = 8.0D; double d1 = 5.0D; List list = player.worldObj.getEntitiesWithinAABB( EntityMob.class, AxisAlignedBB.getBoundingBox( (double) event.x - d0, (double) event.y - d1, (double) event.z - d0, (double) event.x + d0, (double) event.y + d1, (double) event.z + d0)); if (!list.isEmpty()) { event.result = EntityPlayer.EnumStatus.NOT_SAFE; } } if (player.isRiding()) { player.mountEntity((Entity) null); } this.setSize(player, 0.2F, 0.2F); player.yOffset = 0.2F; if (player.worldObj.blockExists(event.x, event.y, event.z)) { int l = worldObj .getBlock(event.x, event.y, event.z) .getBedDirection(worldObj, event.x, event.y, event.z); float f1 = 0.5F; float f = 0.5F; switch (l) { case 0: f = 0.9F; break; case 1: f1 = 0.1F; break; case 2: f = 0.1F; break; case 3: f1 = 0.9F; } this.func_71013_b(player, l); player.setPosition( (double) ((float) event.x + f1), (double) ((float) event.y + 0.9375F), (double) ((float) event.z + f)); } else { player.setPosition( (double) ((float) event.x + 0.5F), (double) ((float) event.y + 0.9375F), (double) ((float) event.z + 0.5F)); } try { sleepTimer.set(player, 0); sleeping.set(player, true); } catch (Exception e) { PerfectSpawn.instance.logger.log(Level.ERROR, "Couldn't reflect on player bed data"); e.printStackTrace(); } player.playerLocation = new ChunkCoordinates(event.x, event.y, event.z); player.motionX = player.motionZ = player.motionY = 0.0D; if (!player.worldObj.isRemote) { player.worldObj.updateAllPlayersSleepingFlag(); } } }