Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void createDamageVec(EntityPlayer shooter) {
- if (CompilationFlag.SERVER) {
- NBTTagCompound weaponNBT = shooter.getHeldItem().getTagCompound();
- ItemWeapon gun = (ItemWeapon) shooter.getCurrentEquippedItem().getItem();
- if (shooter != null) {
- if (shooter.worldObj != null) {
- World w = shooter.worldObj;
- for (int k = 0; k < gun.getShots(); k++) {
- pointedEntity = null;
- double d0 = weaponNBT.getFloat("distance");
- if (d0 > 190) {
- d0 = 190;
- }
- double d1 = d0;
- Vec3 vec3 = Vec3.createVectorHelper(shooter.posX, shooter.posY, shooter.posZ);
- vec3.yCoord += shooter.getEyeHeight();
- Vec3 vec31 = shooter.getLook(1);
- vec31.xCoord += w.rand.nextGaussian() * (double) (w.rand.nextBoolean() ? -1 : 1)
- * 0.007499999832361937D * (double) weaponNBT.getFloat("spread") / 1.2F;
- vec31.yCoord += w.rand.nextGaussian() * (double) (w.rand.nextBoolean() ? -1 : 1)
- * 0.007499999832361937D * (double) weaponNBT.getFloat("spread") / 1.2F;
- vec31.zCoord += w.rand.nextGaussian() * (double) (w.rand.nextBoolean() ? -1 : 1)
- * 0.007499999832361937D * (double) weaponNBT.getFloat("spread") / 1.2F;
- double xCord = vec31.xCoord;
- double yCord = vec31.yCoord - 0.12F / d1;
- double zCord = vec31.zCoord;
- // Minecraft.getMinecraft().effectRenderer.addEffect(new TracerFX(mc.thePlayer,
- // mc.theWorld, mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ, xCord,
- // yCord, zCord));
- ArrayList<MovingObjectPosition> blocklist = rayTrace(shooter, d0, 1F, xCord, yCord, zCord);
- for (int p = 0; p < blocklist.size(); p++) {
- MovingObjectPosition mop = blocklist.get(p);
- if (mop != null) {
- if (mop.typeOfHit.BLOCK != null) {
- Block block = w.getBlock(mop.blockX, mop.blockY, mop.blockZ);
- if (block == Blocks.iron_bars || block.getMaterial() == Material.glass
- || block.getMaterial() == Material.vine
- || block.getMaterial() == Material.plants
- || block.getMaterial() == Material.air
- || block.getMaterial() == Material.leaves
- || block.getMaterial() == Material.web) {
- } else {
- d0 = mop.hitVec.distanceTo(vec3);
- // System.out.println(d1);
- // Minecraft.getMinecraft().effectRenderer.addEffect(new
- // BulletHoleFX(mc.theWorld, mop.hitVec.xCoord, mop.hitVec.yCoord,
- // mop.hitVec.zCoord, mop.sideHit));
- if (!(block instanceof InvizibleBlock) && !(block instanceof BlockCollider)
- && !(block instanceof BlockCollider3D)) {
- BatthertPacketHandler.INSTANCE.sendToAll(new PacketBulletHole(
- (float) mop.hitVec.xCoord, (float) mop.hitVec.yCoord,
- (float) mop.hitVec.zCoord, mop.sideHit));
- if (k <= 1)
- BatthertPacketHandler.INSTANCE.sendToAll(new PacketSoundHit(
- (float) mop.hitVec.xCoord, (float) mop.hitVec.yCoord,
- (float) mop.hitVec.zCoord, mop.sideHit));
- }
- // Minecraft.getMinecraft().effectRenderer.addEffect(new
- // EntitySmokeFX(mc.theWorld, mop.hitVec.xCoord, mop.hitVec.yCoord,
- // mop.hitVec.zCoord, 0, 0, 0));
- // if(block.getMaterial() != Material.air)
- // System.out.println(block);
- break;
- }
- }
- }
- }
- Vec3 vec32 = vec3.addVector(vec31.xCoord * d0, vec31.yCoord * d0, vec31.zCoord * d0);
- this.pointedEntity = null;
- Vec3 vec33 = null;
- float f1 = 1.0F;
- double d4 = d0;
- //тут я сетаю всем игрокам бокс который у них был 20 тиков назад то есть секунду назад
- HashMap<EntityPlayer, AxisAlignedBB> boxes = new HashMap<>();
- for (Object o : w.playerEntities) {
- if (o instanceof EntityPlayer) {
- EntityPlayer player = (EntityPlayer) o;
- boxes.put(player, player.boundingBox.copy());
- AxisAlignedBB prevAABB = ExtendedPlayer.get(player).prevAABB;
- player.boundingBox.setBB(prevAABB);
- }
- }
- List list = w.getEntitiesWithinAABBExcludingEntity(shooter,
- shooter.boundingBox.addCoord(vec31.xCoord * d0, vec31.yCoord * d0, vec31.zCoord * d0)
- .expand((double) f1, (double) f1, (double) f1));
- double d2 = d4;
- for (int i = list.size(); i > 0; --i) {
- Entity entity = (Entity) list.get(i - 1);
- if (entity.canBeCollidedWith() && !entity.isDead) {
- float f2 = entity.getCollisionBorderSize();
- AxisAlignedBB axisalignedbb = entity.boundingBox.expand((double) f2, (double) f2,
- (double) f2);
- MovingObjectPosition movingobjectposition = axisalignedbb.calculateIntercept(vec3,
- vec32);
- if (axisalignedbb.isVecInside(vec3)) {
- if (0.0D < d2 || d2 == 0.0D) {
- this.pointedEntity = entity;
- vec33 = movingobjectposition == null ? vec3 : movingobjectposition.hitVec;
- if (entity instanceof EntityLivingBase
- && ((EntityLivingBase) entity).getHealth() > 0) {
- this.pointedEntity = entity;
- float headPosition = pointedEntity.getEyeHeight();
- double hitPos = vec33.yCoord - pointedEntity.posY;
- if (pointedEntity.height < 1F) {
- headPosition -= 1.4F;
- }
- // mc.thePlayer.addChatMessage(new ChatComponentText(""+headPosition));
- boolean headShot = ((hitPos - (headPosition - 0.45F))
- * (headPosition + 0.5F - hitPos) >= 0);
- pointedEntity.attackEntityFrom(DamageSource.causePlayerDamage(shooter),
- headShot ? gun.damage * 1.75F : gun.damage);
- if (shooter instanceof EntityPlayerMP)
- BatthertPacketHandler.INSTANCE.sendTo(new PacketHitmarker(headShot),
- (EntityPlayerMP) shooter);
- break;
- }
- d2 = 0D;
- break;
- }
- } else if (movingobjectposition != null) {
- double d3 = vec3.distanceTo(movingobjectposition.hitVec);
- // System.out.println(d3);
- if (d3 < d2 || d2 == 0.0D) {
- if (entity == shooter.ridingEntity && !entity.canRiderInteract()) {
- if (d2 == 0.0D) {
- this.pointedEntity = entity;
- vec33 = movingobjectposition.hitVec;
- }
- } else if (!(entity instanceof EntityEnderCrystal)) {
- if (entity instanceof EntityLivingBase
- && ((EntityLivingBase) entity).getHealth() > 0) {
- this.pointedEntity = entity;
- float headPosition = pointedEntity.getEyeHeight();
- vec33 = movingobjectposition.hitVec;
- d2 = d3;
- double hitPos = vec33.yCoord - pointedEntity.posY;
- if (pointedEntity.height < 1F) {
- headPosition -= 1.4F;
- }
- // mc.thePlayer.addChatMessage(new ChatComponentText(""+headPosition));
- boolean headShot = ((hitPos - (headPosition - 0.45F))
- * (headPosition + 0.5F - hitPos) >= 0);
- pointedEntity.attackEntityFrom(DamageSource.causePlayerDamage(shooter),
- headShot ? gun.damage * 1.75F : gun.damage);
- if (shooter instanceof EntityPlayerMP)
- BatthertPacketHandler.INSTANCE.sendTo(new PacketHitmarker(headShot),
- (EntityPlayerMP) shooter);
- break;
- }
- }
- }
- }
- }
- }
- //здесь возвращаю его обратно
- for (Object o : w.playerEntities) {
- if (o instanceof EntityPlayer) {
- EntityPlayer player = (EntityPlayer) o;
- if (boxes.containsKey(player)) {
- player.boundingBox.setBB(boxes.get(player));
- }
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement