From aa79973468e0a38b1d78be9777a703b99f4a6c9a Mon Sep 17 00:00:00 2001 From: Eric Kern Date: Sat, 5 Sep 2020 15:27:17 -0400 Subject: [PATCH 1/3] Changed where ItemCannon spawns fired item --- .../openblocks/common/tileentity/TileEntityCannon.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/openblocks/common/tileentity/TileEntityCannon.java b/src/main/java/openblocks/common/tileentity/TileEntityCannon.java index 6c3d4f551..8555de99e 100644 --- a/src/main/java/openblocks/common/tileentity/TileEntityCannon.java +++ b/src/main/java/openblocks/common/tileentity/TileEntityCannon.java @@ -127,8 +127,15 @@ private void fireStack(@Nonnull ItemStack stack) { final ITriggerable rpc = createServerRpcProxy(ITriggerable.class); rpc.trigger(); + // spawn the item approximately at the end of the barrel + double yawr = Math.toRadians(currentYaw); + double pitchr = Math.toRadians(currentPitch); + double x = pos.getX() + 0.5 - Math.sin(yawr) * Math.cos(pitchr); + double y = pos.getY() + 0.3 + Math.sin(pitchr); + double z = pos.getZ() + 0.5 + Math.cos(yawr) * Math.cos(pitchr); + // projectileOrigin is not used here, it's used for the calculations below. - EntityItem item = new EntityItemProjectile(world, pos.getX() + 0.5, pos.getY(), pos.getZ(), stack); + EntityItem item = new EntityItemProjectile(world, x, y, z, stack); item.setDefaultPickupDelay(); // Now that we generate vectors instead of eular angles, this should be revised. From 7381d5119c4b26f47245353bfcad2c6a7c65a16a Mon Sep 17 00:00:00 2001 From: Eric Kern Date: Sat, 5 Sep 2020 18:13:11 -0400 Subject: [PATCH 2/3] Fixed ItemCannon bug where air resistance was effecting projectiles --- .../common/entity/EntityItemProjectile.java | 65 +++---------------- .../common/tileentity/TileEntityCannon.java | 8 ++- 2 files changed, 15 insertions(+), 58 deletions(-) diff --git a/src/main/java/openblocks/common/entity/EntityItemProjectile.java b/src/main/java/openblocks/common/entity/EntityItemProjectile.java index c5f8f0208..e025c8db4 100644 --- a/src/main/java/openblocks/common/entity/EntityItemProjectile.java +++ b/src/main/java/openblocks/common/entity/EntityItemProjectile.java @@ -37,66 +37,21 @@ public static void registerFixes(DataFixer fixer) { fixer.registerWalker(FixTypes.ENTITY, new ItemStackData(EntityItemProjectile.class, "Item")); } + private boolean firstUpdate = true; + @Override public void onUpdate() { - final double x = posX; - final double y = posY; - final double z = posZ; - - final double vx = motionX; - final double vy = motionY; - final double vz = motionZ; + // Remove the air drag that EntityItem.onUpdate adds to our velocity + if (!firstUpdate && !this.onGround) { + float f = 0.98F; + this.motionX = this.motionX / f; + this.motionY = this.motionY / f; + this.motionZ = this.motionZ / f; + } + firstUpdate = false; // let vanilla run super.onUpdate(); - if (!isDead) return; - // and then overwrite position calculations - - this.posX = x; - this.posY = y; - this.posZ = z; - - this.motionX = vx; - this.motionY = vy; - this.motionZ = vz; - - this.prevPosX = this.posX; - this.prevPosY = this.posY; - this.prevPosZ = this.posZ; - this.motionY -= 0.03999999910593033D; - - move(MoverType.SELF, this.motionX, this.motionY, this.motionZ); - - boolean hasMoved = (int)this.prevPosX != (int)this.posX || (int)this.prevPosY != (int)this.posY || (int)this.prevPosZ != (int)this.posZ; - - if (hasMoved || this.ticksExisted % 25 == 0) { - if (this.world.getBlockState(new BlockPos(this)).getMaterial() == Material.LAVA) { - this.motionY = 0.20000000298023224D; - this.motionX = (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F; - this.motionZ = (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F; - playSound(SoundEvents.ENTITY_GENERIC_BURN, 0.4F, 2.0F + this.rand.nextFloat() * 0.4F); - } - } - - // Zero Air Friction - float f = 1F; - - // Keep ground friction - if (this.onGround) { - BlockPos underPos = new BlockPos(MathHelper.floor(this.posX), MathHelper.floor(getEntityBoundingBox().minY) - 1, MathHelper.floor(this.posZ)); - IBlockState underState = this.world.getBlockState(underPos); - f = underState.getBlock().getSlipperiness(underState, this.world, underPos, this) * 0.98F; - } - - this.motionX *= f; - // Y would there be Y resistance :D - // ^ not my pun, I'm just porting :P, ~B - // motionY *= 0.98; - this.motionZ *= f; - - if (this.onGround) this.motionY *= -0.5D; - - handleWaterMovement(); } } diff --git a/src/main/java/openblocks/common/tileentity/TileEntityCannon.java b/src/main/java/openblocks/common/tileentity/TileEntityCannon.java index 8555de99e..67678b1df 100644 --- a/src/main/java/openblocks/common/tileentity/TileEntityCannon.java +++ b/src/main/java/openblocks/common/tileentity/TileEntityCannon.java @@ -130,9 +130,11 @@ private void fireStack(@Nonnull ItemStack stack) { // spawn the item approximately at the end of the barrel double yawr = Math.toRadians(currentYaw); double pitchr = Math.toRadians(currentPitch); - double x = pos.getX() + 0.5 - Math.sin(yawr) * Math.cos(pitchr); - double y = pos.getY() + 0.3 + Math.sin(pitchr); - double z = pos.getZ() + 0.5 + Math.cos(yawr) * Math.cos(pitchr); + double barrel_length = 0.5; + double barrel_base_height = 0.3; + double x = pos.getX() + 0.5 - Math.sin(yawr) * Math.cos(pitchr) * barrel_length; + double y = pos.getY() + barrel_base_height + Math.sin(pitchr) * barrel_length; + double z = pos.getZ() + 0.5 + Math.cos(yawr) * Math.cos(pitchr) * barrel_length; // projectileOrigin is not used here, it's used for the calculations below. EntityItem item = new EntityItemProjectile(world, x, y, z, stack); From c1954387fccde7fdf092adcfae3b46c68f24fe10 Mon Sep 17 00:00:00 2001 From: Eric Kern Date: Sat, 12 Sep 2020 10:56:29 -0400 Subject: [PATCH 3/3] Cleaned up ItemCannon code a bit --- .../common/entity/EntityItemProjectile.java | 15 ++++++--------- .../common/tileentity/TileEntityCannon.java | 10 +++++----- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/main/java/openblocks/common/entity/EntityItemProjectile.java b/src/main/java/openblocks/common/entity/EntityItemProjectile.java index e025c8db4..369bb27df 100644 --- a/src/main/java/openblocks/common/entity/EntityItemProjectile.java +++ b/src/main/java/openblocks/common/entity/EntityItemProjectile.java @@ -37,21 +37,18 @@ public static void registerFixes(DataFixer fixer) { fixer.registerWalker(FixTypes.ENTITY, new ItemStackData(EntityItemProjectile.class, "Item")); } - private boolean firstUpdate = true; - @Override public void onUpdate() { + // let vanilla run + super.onUpdate(); + // Remove the air drag that EntityItem.onUpdate adds to our velocity - if (!firstUpdate && !this.onGround) { - float f = 0.98F; + if (!this.onGround) { + double f = 0.98F; this.motionX = this.motionX / f; this.motionY = this.motionY / f; this.motionZ = this.motionZ / f; } - firstUpdate = false; - - // let vanilla run - super.onUpdate(); } -} +} \ No newline at end of file diff --git a/src/main/java/openblocks/common/tileentity/TileEntityCannon.java b/src/main/java/openblocks/common/tileentity/TileEntityCannon.java index 67678b1df..b11411af7 100644 --- a/src/main/java/openblocks/common/tileentity/TileEntityCannon.java +++ b/src/main/java/openblocks/common/tileentity/TileEntityCannon.java @@ -130,11 +130,11 @@ private void fireStack(@Nonnull ItemStack stack) { // spawn the item approximately at the end of the barrel double yawr = Math.toRadians(currentYaw); double pitchr = Math.toRadians(currentPitch); - double barrel_length = 0.5; - double barrel_base_height = 0.3; - double x = pos.getX() + 0.5 - Math.sin(yawr) * Math.cos(pitchr) * barrel_length; - double y = pos.getY() + barrel_base_height + Math.sin(pitchr) * barrel_length; - double z = pos.getZ() + 0.5 + Math.cos(yawr) * Math.cos(pitchr) * barrel_length; + double barrelLength = 0.5; + double barrelBaseHeight = 0.3; + double x = pos.getX() + 0.5 - Math.sin(yawr) * Math.cos(pitchr) * barrelLength; + double y = pos.getY() + barrelBaseHeight + Math.sin(pitchr) * barrelLength; + double z = pos.getZ() + 0.5 + Math.cos(yawr) * Math.cos(pitchr) * barrelLength; // projectileOrigin is not used here, it's used for the calculations below. EntityItem item = new EntityItemProjectile(world, x, y, z, stack);