stop already started flight close #58
This commit is contained in:
parent
2f0913c2bc
commit
2c9e4c70bf
@ -43,7 +43,7 @@ public class Flan implements ModInitializer {
|
||||
permissionAPI = FabricLoader.getInstance().isModLoaded("fabric-permissions-api-v0");
|
||||
gunpowder = FabricLoader.getInstance().isModLoaded("gunpowder-currency");
|
||||
playerAbilityLib = FabricLoader.getInstance().isModLoaded("playerabilitylib");
|
||||
if(playerAbilityLib)
|
||||
if (playerAbilityLib)
|
||||
PlayerAbilityEvents.register();
|
||||
}
|
||||
|
||||
|
@ -1,38 +0,0 @@
|
||||
package com.flemmli97.flan.claim;
|
||||
|
||||
import org.apache.commons.lang3.time.StopWatch;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class Benchmark {
|
||||
|
||||
private final StopWatch stopWatch = new StopWatch();
|
||||
private final List<Long> times = new LinkedList<>();
|
||||
|
||||
public Benchmark() {
|
||||
}
|
||||
public void start() {
|
||||
stopWatch.start();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
stopWatch.stop();
|
||||
times.add(stopWatch.getNanoTime());
|
||||
stopWatch.reset();
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
times.clear();
|
||||
stopWatch.reset();
|
||||
}
|
||||
|
||||
public long getAverage() {
|
||||
return times.stream().reduce(0L, Long::sum)/times.size();
|
||||
}
|
||||
|
||||
public long worstCase() {
|
||||
return times.stream().max(Long::compareTo).orElse(-1L);
|
||||
}
|
||||
}
|
@ -2,14 +2,12 @@ package com.flemmli97.flan.event;
|
||||
|
||||
import com.flemmli97.flan.api.ClaimPermission;
|
||||
import com.flemmli97.flan.api.PermissionRegistry;
|
||||
import com.flemmli97.flan.claim.Benchmark;
|
||||
import com.flemmli97.flan.claim.Claim;
|
||||
import com.flemmli97.flan.claim.ClaimStorage;
|
||||
import com.flemmli97.flan.claim.IPermissionContainer;
|
||||
import com.flemmli97.flan.claim.ObjectToPermissionMap;
|
||||
import com.flemmli97.flan.mixin.IPersistentProjectileVars;
|
||||
import com.flemmli97.flan.player.IOwnedItem;
|
||||
import com.flemmli97.flan.player.IPlayerClaimImpl;
|
||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
@ -35,6 +33,7 @@ import net.minecraft.entity.vehicle.BoatEntity;
|
||||
import net.minecraft.entity.vehicle.StorageMinecartEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.packet.s2c.play.InventoryS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.play.PlayerAbilitiesS2CPacket;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
@ -46,11 +45,10 @@ import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.hit.EntityHitResult;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import org.apache.commons.lang3.time.StopWatch;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@ -287,35 +285,44 @@ public class EntityInteractEvents {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static final Benchmark benchmark = new Benchmark();
|
||||
|
||||
public static void updateClaim(ServerPlayerEntity player, Consumer<Claim> cons) {
|
||||
benchmark.start();
|
||||
if(player.age % 5 == 0) {
|
||||
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
||||
Vec3d pos = player.getPos();
|
||||
BlockPos.Mutable bPos = new BlockPos(pos).mutableCopy();
|
||||
Claim claim = storage.getClaimAt(bPos);
|
||||
cons.accept(claim);
|
||||
if(!player.isSpectator()) {
|
||||
if (claim != null && !claim.canInteract(player, PermissionRegistry.CANSTAY, bPos, true)) {
|
||||
Vec3d tp = getTeleportPos(player, pos, storage, claim.getDimensions(), bPos);
|
||||
player.teleport(tp.getX(), tp.getY(), tp.getZ());
|
||||
public static void updateClaim(ServerPlayerEntity player, Claim currentClaim, Consumer<Claim> cons) {
|
||||
Vec3d pos = player.getPos();
|
||||
BlockPos rounded = roundedBlockPos(pos.add(0, player.getEyeHeight(player.getPose()), 0));
|
||||
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
||||
if (currentClaim != null) {
|
||||
if (!currentClaim.insideClaim(rounded)) {
|
||||
cons.accept(null);
|
||||
} else {
|
||||
if (!player.isSpectator()) {
|
||||
BlockPos.Mutable bPos = rounded.mutableCopy();
|
||||
if (!currentClaim.canInteract(player, PermissionRegistry.CANSTAY, bPos, true)) {
|
||||
Vec3d tp = getTeleportPos(player, pos, storage, currentClaim.getDimensions(), bPos);
|
||||
player.teleport(tp.getX(), tp.getY(), tp.getZ());
|
||||
}
|
||||
if (player.abilities.flying && !currentClaim.canInteract(player, PermissionRegistry.FLIGHT, rounded, true)) {
|
||||
player.abilities.flying = false;
|
||||
player.networkHandler.sendPacket(new PlayerAbilitiesS2CPacket(player.abilities));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (player.age % 3 == 0) {
|
||||
Claim claim = storage.getClaimAt(rounded);
|
||||
cons.accept(claim);
|
||||
}
|
||||
benchmark.stop();
|
||||
System.out.println(String.format("Average: %d, Worst: %d", benchmark.getAverage(), benchmark.worstCase()));
|
||||
}
|
||||
|
||||
private static Vec3d getTeleportPos(ServerPlayerEntity player, Vec3d playerPos, ClaimStorage storage, int [] dim, BlockPos.Mutable bPos) {
|
||||
private static BlockPos roundedBlockPos(Vec3d pos) {
|
||||
return new BlockPos(Math.round(pos.getX()), MathHelper.floor(pos.getY()), Math.round(pos.getZ()));
|
||||
}
|
||||
|
||||
private static Vec3d getTeleportPos(ServerPlayerEntity player, Vec3d playerPos, ClaimStorage storage, int[] dim, BlockPos.Mutable bPos) {
|
||||
Pair<Direction, Vec3d> pos = nearestOutside(dim, playerPos);
|
||||
bPos.set(pos.getRight().getX(), pos.getRight().getY(), pos.getRight().getZ());
|
||||
Claim claim = storage.getClaimAt(bPos);
|
||||
if(claim == null || claim.canInteract(player, PermissionRegistry.CANSTAY, bPos, false))
|
||||
if (claim == null || claim.canInteract(player, PermissionRegistry.CANSTAY, bPos, false))
|
||||
return pos.getRight();
|
||||
int[] newDim = claim.getDimensions();
|
||||
switch (pos.getLeft()){
|
||||
switch (pos.getLeft()) {
|
||||
case NORTH:
|
||||
dim[2] = newDim[2];
|
||||
break;
|
||||
@ -338,23 +345,23 @@ public class EntityInteractEvents {
|
||||
double southDist = Math.abs(dim[3] - from.getZ());
|
||||
double westDist = Math.abs(from.getX() - dim[0]);
|
||||
double eastDist = Math.abs(dim[1] - from.getX());
|
||||
if(northDist > southDist) {
|
||||
if(eastDist > westDist) {
|
||||
if(southDist > westDist)
|
||||
if (northDist > southDist) {
|
||||
if (eastDist > westDist) {
|
||||
if (southDist > westDist)
|
||||
return new Pair<>(Direction.WEST, new Vec3d(dim[0] - 1.5, from.getY(), from.getZ()));
|
||||
return new Pair<>(Direction.SOUTH, new Vec3d(from.getX(), from.getY(), dim[3] + 1.5));
|
||||
}
|
||||
if(southDist > eastDist)
|
||||
if (southDist > eastDist)
|
||||
return new Pair<>(Direction.EAST, new Vec3d(dim[1] + 1.5, from.getY(), from.getZ()));
|
||||
return new Pair<>(Direction.SOUTH, new Vec3d(from.getX(), from.getY(), dim[3]+1.5));
|
||||
return new Pair<>(Direction.SOUTH, new Vec3d(from.getX(), from.getY(), dim[3] + 1.5));
|
||||
}
|
||||
if(eastDist > westDist) {
|
||||
if(northDist > westDist)
|
||||
if (eastDist > westDist) {
|
||||
if (northDist > westDist)
|
||||
return new Pair<>(Direction.WEST, new Vec3d(dim[0] - 1.5, from.getY(), from.getZ()));
|
||||
return new Pair<>(Direction.NORTH, new Vec3d(from.getX(), from.getY(), dim[2] - 1.5));
|
||||
}
|
||||
if(northDist > eastDist)
|
||||
if (northDist > eastDist)
|
||||
return new Pair<>(Direction.EAST, new Vec3d(dim[1] + 1.5, from.getY(), from.getZ()));
|
||||
return new Pair<>(Direction.NORTH, new Vec3d(from.getX(), from.getY(), dim[2]-1.5));
|
||||
return new Pair<>(Direction.NORTH, new Vec3d(from.getX(), from.getY(), dim[2] - 1.5));
|
||||
}
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ import com.flemmli97.flan.claim.ClaimStorage;
|
||||
import com.flemmli97.flan.claim.IPermissionContainer;
|
||||
import com.flemmli97.flan.claim.ObjectToPermissionMap;
|
||||
import com.flemmli97.flan.claim.PermHelper;
|
||||
import com.flemmli97.flan.integration.permissionapi.CommandPermission;
|
||||
import com.flemmli97.flan.config.ConfigHandler;
|
||||
import com.flemmli97.flan.integration.permissionapi.CommandPermission;
|
||||
import com.flemmli97.flan.player.EnumDisplayType;
|
||||
import com.flemmli97.flan.player.EnumEditMode;
|
||||
import com.flemmli97.flan.player.PlayerClaimData;
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.flemmli97.flan.mixin;
|
||||
|
||||
import com.flemmli97.flan.claim.Claim;
|
||||
import com.flemmli97.flan.claim.ClaimStorage;
|
||||
import com.flemmli97.flan.event.EntityInteractEvents;
|
||||
import com.flemmli97.flan.player.IPlayerClaimImpl;
|
||||
import com.flemmli97.flan.player.PlayerClaimData;
|
||||
@ -53,8 +52,8 @@ public abstract class PlayerClaimMixin implements IPlayerClaimImpl {
|
||||
}
|
||||
|
||||
@Inject(method = "tick", at = @At("HEAD"))
|
||||
private void canStay(CallbackInfo info) {
|
||||
EntityInteractEvents.updateClaim((ServerPlayerEntity)(Object)this, claim->this.currentClaim = claim);
|
||||
private void claimupdate(CallbackInfo info) {
|
||||
EntityInteractEvents.updateClaim((ServerPlayerEntity) (Object) this, this.currentClaim, claim -> this.currentClaim = claim);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user