Improve Y Padding
All checks were successful
EnergonRelics/pipeline/head This commit looks good

This commit is contained in:
TheBrokenRail 2020-08-01 23:15:12 -04:00
parent ab15c7bd3c
commit 1e78023ee4

View File

@ -53,13 +53,34 @@ class EnergyTeleporter {
} }
} }
private static int changeY(int y, int oldHeight, int newHeight) {
int bottomPadding = HardcodedConfig.ENERGY_PORTAL_Y_PADDING;
int topPadding = bottomPadding + HardcodedConfig.ENERGY_PORTAL_Y_PADDING_EXTRA_TOP;
int oldMax = oldHeight - topPadding;
y = MathHelper.clamp(y, bottomPadding, oldMax);
int totalPadding = bottomPadding + topPadding;
int oldPaddedHeight = oldHeight - totalPadding;
int newPaddedHeight = newHeight - totalPadding;
float multiplier = (float) newPaddedHeight / (float) oldPaddedHeight;
y = (int) (y * multiplier);
int newMax = newHeight - topPadding;
y = MathHelper.clamp(y, bottomPadding, newMax);
return y;
}
private static void teleportWithMultiplier(ServerWorld world, Entity entity, BlockPos center, Vec3d offset, RegistryKey<World> toKey, double multiplier) { private static void teleportWithMultiplier(ServerWorld world, Entity entity, BlockPos center, Vec3d offset, RegistryKey<World> toKey, double multiplier) {
ServerWorld to = world.getServer().getWorld(toKey); ServerWorld to = world.getServer().getWorld(toKey);
assert to != null; assert to != null;
float yMultiplier = (float) to.getDimensionHeight() / (float) world.getDimensionHeight(); int y = changeY(center.getY(), world.getDimensionHeight(), to.getDimensionHeight());
int y = (int) (center.getY() * yMultiplier);
y = MathHelper.clamp(y, HardcodedConfig.ENERGY_PORTAL_Y_PADDING, to.getDimensionHeight() - HardcodedConfig.ENERGY_PORTAL_Y_PADDING - HardcodedConfig.ENERGY_PORTAL_Y_PADDING_EXTRA_TOP);
int x = (int) (center.getX() * multiplier); int x = (int) (center.getX() * multiplier);
int z = (int) (center.getZ() * multiplier); int z = (int) (center.getZ() * multiplier);