Add Sound
EnergonRelics/pipeline/head This commit looks good Details

This commit is contained in:
TheBrokenRail 2020-08-01 20:37:57 -04:00
parent eb62b6bc77
commit ab15c7bd3c
2 changed files with 19 additions and 2 deletions

View File

@ -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<World> 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<World> 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);
}

View File

@ -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;
}