From ab15c7bd3c399bec702c5c81c2db53ad2c4f93f0 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Sat, 1 Aug 2020 20:37:57 -0400 Subject: [PATCH] Add Sound --- .../block/portal/EnergyTeleporter.java | 17 ++++++++++++++++- .../energonrelics/config/HardcodedConfig.java | 4 +++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/thebrokenrail/energonrelics/block/portal/EnergyTeleporter.java b/src/main/java/com/thebrokenrail/energonrelics/block/portal/EnergyTeleporter.java index e05709d..a764464 100644 --- a/src/main/java/com/thebrokenrail/energonrelics/block/portal/EnergyTeleporter.java +++ b/src/main/java/com/thebrokenrail/energonrelics/block/portal/EnergyTeleporter.java @@ -8,14 +8,19 @@ import net.minecraft.block.Blocks; import net.minecraft.entity.Entity; import net.minecraft.network.packet.s2c.play.PlayerPositionLookS2CPacket; import net.minecraft.server.command.TeleportCommand; +import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; +import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvents; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import net.minecraft.util.registry.RegistryKey; import net.minecraft.world.Heightmap; import net.minecraft.world.World; import java.util.EnumSet; +import java.util.UUID; class EnergyTeleporter { private static void teleport(Entity entity, ServerWorld to, Vec3d pos) { @@ -29,6 +34,8 @@ class EnergyTeleporter { BlockPos center = EnergyPortalBlock.getCenterPos(world, blockPos); Vec3d offset = pos.subtract(Vec3d.ofBottomCenter(center)); + UUID uuid = entity.getUuid(); + RegistryKey worldKey = world.getRegistryKey(); if (worldKey == World.OVERWORLD) { teleportWithMultiplier(world, entity, center, offset, World.NETHER, 1d / HardcodedConfig.ENERGY_PORTAL_MULTIPLIER); @@ -37,6 +44,13 @@ class EnergyTeleporter { } else { teleportToWorldSpawn(world, entity); } + + if (entity instanceof ServerPlayerEntity) { + ServerPlayerEntity player = world.getServer().getPlayerManager().getPlayer(uuid); + if (player != null) { + player.playSound(SoundEvents.BLOCK_PORTAL_TRAVEL, SoundCategory.PLAYERS, 0.25f, world.random.nextFloat() * 0.4f + 0.8f); + } + } } private static void teleportWithMultiplier(ServerWorld world, Entity entity, BlockPos center, Vec3d offset, RegistryKey toKey, double multiplier) { @@ -45,6 +59,7 @@ class EnergyTeleporter { float yMultiplier = (float) to.getDimensionHeight() / (float) world.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 z = (int) (center.getZ() * multiplier); @@ -66,8 +81,8 @@ class EnergyTeleporter { } } + offset = new Vec3d(offset.getX(), Math.max(0, offset.getY()), offset.getZ()); Vec3d target = Vec3d.ofBottomCenter(targetBlock).add(offset); - target = new Vec3d(target.getX(), Math.max(0, target.getY()), target.getZ()); teleport(entity, to, target); } diff --git a/src/main/java/com/thebrokenrail/energonrelics/config/HardcodedConfig.java b/src/main/java/com/thebrokenrail/energonrelics/config/HardcodedConfig.java index a34aa20..5a30525 100644 --- a/src/main/java/com/thebrokenrail/energonrelics/config/HardcodedConfig.java +++ b/src/main/java/com/thebrokenrail/energonrelics/config/HardcodedConfig.java @@ -47,5 +47,7 @@ public class HardcodedConfig { public static final long ENERGY_PROJECTOR_ENERGY_REQUIRED = 37; public static final int ENERGY_PORTAL_COOLDOWN = 28; - public static final int ENERGY_PORTAL_MULTIPLIER = 32; + public static final int ENERGY_PORTAL_MULTIPLIER = 16; + public static final int ENERGY_PORTAL_Y_PADDING = 4; + public static final int ENERGY_PORTAL_Y_PADDING_EXTRA_TOP = 3; } \ No newline at end of file