From daf81b897a8485596d00f41e82d0c24acb095518 Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Fri, 22 Apr 2022 09:30:04 +0100 Subject: [PATCH] Use vector helpers to convert BlockPos to Vector3d A little shorter and more explicit than constructing the Vector3d manually. Fixes an issue where sounds were centered on the bottom left of speakers, not the middle (see cc-tweaked/cc-restitched#85). --- .../shared/computer/blocks/TileCommandComputer.java | 2 +- .../shared/peripheral/modem/wired/TileCable.java | 6 ++---- .../shared/peripheral/modem/wired/TileWiredModemFull.java | 6 ++---- .../shared/peripheral/modem/wireless/TileWirelessModem.java | 4 +--- .../shared/peripheral/speaker/TileSpeaker.java | 4 +--- .../computercraft/shared/turtle/upgrades/TurtleSpeaker.java | 4 +--- 6 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/main/java/dan200/computercraft/shared/computer/blocks/TileCommandComputer.java b/src/main/java/dan200/computercraft/shared/computer/blocks/TileCommandComputer.java index 5e04cbd03..e72d1348e 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/TileCommandComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/TileCommandComputer.java @@ -97,7 +97,7 @@ public class TileCommandComputer extends TileComputer } return new CommandSource( receiver, - new Vector3d( worldPosition.getX() + 0.5, worldPosition.getY() + 0.5, worldPosition.getZ() + 0.5 ), Vector2f.ZERO, + Vector3d.atCenterOf( worldPosition ), Vector2f.ZERO, (ServerWorld) getLevel(), 2, name, new StringTextComponent( name ), getLevel().getServer(), null diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileCable.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileCable.java index 9e769a216..eefb53109 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileCable.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileCable.java @@ -60,8 +60,7 @@ public class TileCable extends TileGeneric @Override public Vector3d getPosition() { - BlockPos pos = getBlockPos(); - return new Vector3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ); + return Vector3d.atCenterOf( getBlockPos() ); } @Override @@ -106,8 +105,7 @@ public class TileCable extends TileGeneric @Override public Vector3d getPosition() { - BlockPos pos = getBlockPos().relative( modemDirection ); - return new Vector3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ); + return Vector3d.atCenterOf( getBlockPos().relative( modemDirection ) ); } @Nonnull diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileWiredModemFull.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileWiredModemFull.java index d4dd83701..e807ce499 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileWiredModemFull.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileWiredModemFull.java @@ -87,8 +87,7 @@ public class TileWiredModemFull extends TileGeneric @Override public Vector3d getPosition() { - BlockPos pos = entity.getBlockPos(); - return new Vector3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ); + return Vector3d.atCenterOf( entity.getBlockPos() ); } } @@ -418,8 +417,7 @@ public class TileWiredModemFull extends TileGeneric @Override public Vector3d getPosition() { - BlockPos pos = getBlockPos().relative( side ); - return new Vector3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ); + return Vector3d.atCenterOf( getBlockPos().relative( side ) ); } @Nonnull diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/TileWirelessModem.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/TileWirelessModem.java index 700543f47..f5b35696f 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/TileWirelessModem.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/TileWirelessModem.java @@ -14,7 +14,6 @@ import dan200.computercraft.shared.util.TickScheduler; import net.minecraft.block.BlockState; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.vector.Vector3d; import net.minecraft.world.World; import net.minecraftforge.common.capabilities.Capability; @@ -48,8 +47,7 @@ public class TileWirelessModem extends TileGeneric @Override public Vector3d getPosition() { - BlockPos pos = entity.getBlockPos().relative( entity.modemDirection ); - return new Vector3d( pos.getX(), pos.getY(), pos.getZ() ); + return Vector3d.atLowerCornerOf( entity.getBlockPos().relative( entity.modemDirection ) ); } @Override diff --git a/src/main/java/dan200/computercraft/shared/peripheral/speaker/TileSpeaker.java b/src/main/java/dan200/computercraft/shared/peripheral/speaker/TileSpeaker.java index 6e261c1dc..4c78ea7c2 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/speaker/TileSpeaker.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/speaker/TileSpeaker.java @@ -13,7 +13,6 @@ import dan200.computercraft.shared.util.CapabilityUtil; import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.vector.Vector3d; import net.minecraft.world.World; import net.minecraftforge.common.capabilities.Capability; @@ -90,8 +89,7 @@ public class TileSpeaker extends TileGeneric implements ITickableTileEntity @Override public Vector3d getPosition() { - BlockPos pos = speaker.getBlockPos(); - return new Vector3d( pos.getX(), pos.getY(), pos.getZ() ); + return Vector3d.atCenterOf( speaker.getBlockPos() ); } @Override diff --git a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleSpeaker.java b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleSpeaker.java index 1ec4b1d62..1188a28bc 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleSpeaker.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleSpeaker.java @@ -15,7 +15,6 @@ import dan200.computercraft.shared.Registry; import dan200.computercraft.shared.peripheral.speaker.UpgradeSpeakerPeripheral; import net.minecraft.client.renderer.model.ModelResourceLocation; import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.vector.Vector3d; import net.minecraft.world.World; import net.minecraftforge.api.distmarker.Dist; @@ -47,8 +46,7 @@ public class TurtleSpeaker extends AbstractTurtleUpgrade @Override public Vector3d getPosition() { - BlockPos pos = turtle.getPosition(); - return new Vector3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ); + return Vector3d.atCenterOf( turtle.getPosition() ); } @Override