From daaac300b84504faa77be43a1e16f6ea17372e27 Mon Sep 17 00:00:00 2001 From: Sebastian Hartte Date: Sat, 20 Jun 2020 01:33:33 +0200 Subject: [PATCH] Fix Matter Cannon Range (to 1.7.10 range) --- .../items/tools/powered/ToolMatterCannon.java | 29 +++++++++++-------- src/main/java/appeng/util/Platform.java | 7 +++-- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/main/java/appeng/items/tools/powered/ToolMatterCannon.java b/src/main/java/appeng/items/tools/powered/ToolMatterCannon.java index 15b3b44e5..eee8e0618 100644 --- a/src/main/java/appeng/items/tools/powered/ToolMatterCannon.java +++ b/src/main/java/appeng/items/tools/powered/ToolMatterCannon.java @@ -83,6 +83,11 @@ import appeng.util.Platform; public class ToolMatterCannon extends AEBasePoweredItem implements IStorageCell { + /** + * AE energy units consumer per shot fired. + */ + private static final int ENERGY_PER_SHOT = 1600; + public ToolMatterCannon(Item.Properties props) { super(AEConfig.instance().getMatterCannonBattery(), props); } @@ -101,7 +106,7 @@ public class ToolMatterCannon extends AEBasePoweredItem implements IStorageCell< @Override public ActionResult onItemRightClick(final World w, final PlayerEntity p, final @Nullable Hand hand) { - if (this.getAECurrentPower(p.getHeldItem(hand)) > 1600) { + if (this.getAECurrentPower(p.getHeldItem(hand)) > ENERGY_PER_SHOT) { int shots = 1; final CellUpgrades cu = (CellUpgrades) this.getUpgradesInventory(p.getHeldItem(hand)); @@ -119,7 +124,7 @@ public class ToolMatterCannon extends AEBasePoweredItem implements IStorageCell< shots = Math.min(shots, (int) req.getStackSize()); for (int sh = 0; sh < shots; sh++) { IAEItemStack aeAmmo = req.copy(); - this.extractAEPower(p.getHeldItem(hand), 1600, Actionable.MODULATE); + this.extractAEPower(p.getHeldItem(hand), ENERGY_PER_SHOT, Actionable.MODULATE); if (Platform.isClient()) { return new ActionResult<>(ActionResultType.SUCCESS, p.getHeldItem(hand)); @@ -127,7 +132,7 @@ public class ToolMatterCannon extends AEBasePoweredItem implements IStorageCell< aeAmmo.setStackSize(1); final ItemStack ammo = aeAmmo.createItemStack(); - if (ammo == null) { + if (ammo.isEmpty()) { return new ActionResult<>(ActionResultType.SUCCESS, p.getHeldItem(hand)); } @@ -136,26 +141,26 @@ public class ToolMatterCannon extends AEBasePoweredItem implements IStorageCell< return new ActionResult<>(ActionResultType.SUCCESS, p.getHeldItem(hand)); } - final LookDirection dir = Platform.getPlayerRay(p); + final LookDirection dir = Platform.getPlayerRay(p, 32); - final Vec3d Vec3d = dir.getA(); - final Vec3d Vec3d1 = dir.getB(); - final Vec3d direction = Vec3d1.subtract(Vec3d); + final Vec3d rayFrom = dir.getA(); + final Vec3d rayTo = dir.getB(); + final Vec3d direction = rayTo.subtract(rayFrom); direction.normalize(); - final double d0 = Vec3d.x; - final double d1 = Vec3d.y; - final double d2 = Vec3d.z; + final double d0 = rayFrom.x; + final double d1 = rayFrom.y; + final double d2 = rayFrom.z; final float penetration = AEApi.instance().registries().matterCannon().getPenetration(ammo); // 196.96655f; if (penetration <= 0) { final ItemStack type = aeAmmo.asItemStackRepresentation(); if (type.getItem() instanceof ItemPaintBall) { - this.shootPaintBalls(type, w, p, Vec3d, Vec3d1, direction, d0, d1, d2); + this.shootPaintBalls(type, w, p, rayFrom, rayTo, direction, d0, d1, d2); } return new ActionResult<>(ActionResultType.SUCCESS, p.getHeldItem(hand)); } else { - this.standardAmmo(penetration, w, p, Vec3d, Vec3d1, direction, d0, d1, d2); + this.standardAmmo(penetration, w, p, rayFrom, rayTo, direction, d0, d1, d2); } } } else { diff --git a/src/main/java/appeng/util/Platform.java b/src/main/java/appeng/util/Platform.java index 068ad0c57..2dfcf3843 100644 --- a/src/main/java/appeng/util/Platform.java +++ b/src/main/java/appeng/util/Platform.java @@ -797,6 +797,11 @@ public class Platform { // } public static LookDirection getPlayerRay(final PlayerEntity playerIn) { + double reachDistance = playerIn.getAttribute(PlayerEntity.REACH_DISTANCE).getValue(); + return getPlayerRay(playerIn, reachDistance); + } + + public static LookDirection getPlayerRay(final PlayerEntity playerIn, double reachDistance) { final double x = playerIn.prevPosX + (playerIn.getPosX() - playerIn.prevPosX); final double y = playerIn.prevPosY + (playerIn.getPosY() - playerIn.prevPosY) + playerIn.getEyeHeight(); final double z = playerIn.prevPosZ + (playerIn.getPosZ() - playerIn.prevPosZ); @@ -812,8 +817,6 @@ public class Platform { final float eyeRayX = yawRayX * pitchMultiplier; final float eyeRayZ = yawRayZ * pitchMultiplier; - double reachDistance = playerIn.getAttribute(PlayerEntity.REACH_DISTANCE).getValue(); - final Vec3d from = new Vec3d(x, y, z); final Vec3d to = from.add(eyeRayX * reachDistance, eyeRayY * reachDistance, eyeRayZ * reachDistance);