Skip to content

Commit 06a4280

Browse files
committed
Fix item cannon trajectory
Based on changes by @ekedaigle
1 parent 5b08846 commit 06a4280

File tree

2 files changed

+13
-61
lines changed

2 files changed

+13
-61
lines changed
Lines changed: 6 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
package openblocks.common.entity;
22

33
import javax.annotation.Nonnull;
4-
import net.minecraft.block.material.Material;
5-
import net.minecraft.block.state.IBlockState;
6-
import net.minecraft.entity.MoverType;
74
import net.minecraft.entity.item.EntityItem;
8-
import net.minecraft.init.SoundEvents;
95
import net.minecraft.item.ItemStack;
106
import net.minecraft.util.datafix.DataFixer;
117
import net.minecraft.util.datafix.FixTypes;
128
import net.minecraft.util.datafix.walkers.ItemStackData;
13-
import net.minecraft.util.math.BlockPos;
14-
import net.minecraft.util.math.MathHelper;
159
import net.minecraft.world.World;
1610

1711
/**
@@ -39,64 +33,16 @@ public static void registerFixes(DataFixer fixer) {
3933

4034
@Override
4135
public void onUpdate() {
42-
final double x = posX;
43-
final double y = posY;
44-
final double z = posZ;
45-
46-
final double vx = motionX;
47-
final double vy = motionY;
48-
final double vz = motionZ;
49-
5036
// let vanilla run
5137
super.onUpdate();
52-
if (!isDead) return;
53-
// and then overwrite position calculations
54-
55-
this.posX = x;
56-
this.posY = y;
57-
this.posZ = z;
58-
59-
this.motionX = vx;
60-
this.motionY = vy;
61-
this.motionZ = vz;
62-
63-
this.prevPosX = this.posX;
64-
this.prevPosY = this.posY;
65-
this.prevPosZ = this.posZ;
66-
this.motionY -= 0.03999999910593033D;
67-
68-
move(MoverType.SELF, this.motionX, this.motionY, this.motionZ);
69-
70-
boolean hasMoved = (int)this.prevPosX != (int)this.posX || (int)this.prevPosY != (int)this.posY || (int)this.prevPosZ != (int)this.posZ;
7138

72-
if (hasMoved || this.ticksExisted % 25 == 0) {
73-
if (this.world.getBlockState(new BlockPos(this)).getMaterial() == Material.LAVA) {
74-
this.motionY = 0.20000000298023224D;
75-
this.motionX = (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F;
76-
this.motionZ = (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F;
77-
playSound(SoundEvents.ENTITY_GENERIC_BURN, 0.4F, 2.0F + this.rand.nextFloat() * 0.4F);
78-
}
39+
// Remove the air drag that EntityItem.onUpdate adds to our velocity
40+
if (!this.onGround) {
41+
double f = 0.98F;
42+
this.motionX = this.motionX / f;
43+
this.motionY = this.motionY / f;
44+
this.motionZ = this.motionZ / f;
7945
}
80-
81-
// Zero Air Friction
82-
float f = 1F;
83-
84-
// Keep ground friction
85-
if (this.onGround) {
86-
BlockPos underPos = new BlockPos(MathHelper.floor(this.posX), MathHelper.floor(getEntityBoundingBox().minY) - 1, MathHelper.floor(this.posZ));
87-
IBlockState underState = this.world.getBlockState(underPos);
88-
f = underState.getBlock().getSlipperiness(underState, this.world, underPos, this) * 0.98F;
89-
}
90-
91-
this.motionX *= f;
92-
// Y would there be Y resistance :D
93-
// ^ not my pun, I'm just porting :P, ~B
94-
// motionY *= 0.98;
95-
this.motionZ *= f;
96-
97-
if (this.onGround) this.motionY *= -0.5D;
98-
99-
handleWaterMovement();
10046
}
10147

10248
}

src/main/java/openblocks/common/tileentity/TileEntityCannon.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,14 @@ private void fireStack(@Nonnull ItemStack stack) {
127127
final ITriggerable rpc = createServerRpcProxy(ITriggerable.class);
128128
rpc.trigger();
129129

130+
double yawR = Math.toRadians(currentYaw);
131+
double pitchR = Math.toRadians(currentPitch);
132+
double x = pos.getX() + 0.5D - Math.sin(yawR) * Math.cos(pitchR) * 0.1D;
133+
double y = pos.getY() + 0.1D + Math.sin(pitchR) * 0.1D;
134+
double z = pos.getZ() + 0.5D + Math.cos(yawR) * Math.cos(pitchR) * 0.1D;
135+
130136
// projectileOrigin is not used here, it's used for the calculations below.
131-
EntityItem item = new EntityItemProjectile(world, pos.getX() + 0.5, pos.getY(), pos.getZ(), stack);
137+
EntityItem item = new EntityItemProjectile(world, x, y, z, stack);
132138
item.setDefaultPickupDelay();
133139

134140
// Now that we generate vectors instead of eular angles, this should be revised.

0 commit comments

Comments
 (0)