Muffins now float in water, as they should

This commit is contained in:
Sollace 2022-04-01 00:39:08 +02:00
parent 448df32720
commit a878fd0d6c

View file

@ -13,6 +13,7 @@ import net.minecraft.entity.MovementType;
import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.data.DataTracker;
import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedData;
import net.minecraft.entity.data.TrackedDataHandlerRegistry; import net.minecraft.entity.data.TrackedDataHandlerRegistry;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.PersistentProjectileEntity; import net.minecraft.entity.projectile.PersistentProjectileEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
@ -32,6 +33,8 @@ public class PhysicsBodyProjectileEntity extends PersistentProjectileEntity impl
private static final TrackedData<ItemStack> ITEM = DataTracker.registerData(PhysicsBodyProjectileEntity.class, TrackedDataHandlerRegistry.ITEM_STACK); private static final TrackedData<ItemStack> ITEM = DataTracker.registerData(PhysicsBodyProjectileEntity.class, TrackedDataHandlerRegistry.ITEM_STACK);
private static final TrackedData<Boolean> BOUNCY = DataTracker.registerData(PhysicsBodyProjectileEntity.class, TrackedDataHandlerRegistry.BOOLEAN); private static final TrackedData<Boolean> BOUNCY = DataTracker.registerData(PhysicsBodyProjectileEntity.class, TrackedDataHandlerRegistry.BOOLEAN);
private int inWaterTime;
public PhysicsBodyProjectileEntity(EntityType<PhysicsBodyProjectileEntity> type, World world) { public PhysicsBodyProjectileEntity(EntityType<PhysicsBodyProjectileEntity> type, World world) {
super(type, world); super(type, world);
} }
@ -85,6 +88,28 @@ public class PhysicsBodyProjectileEntity extends PersistentProjectileEntity impl
setVelocity(vel.multiply(0.3)); setVelocity(vel.multiply(0.3));
addVelocity(0, -0.025, 0); addVelocity(0, -0.025, 0);
} }
if (isBouncy() && isInsideWaterOrBubbleColumn()) {
setVelocity(getVelocity().multiply(0.3).add(0, 0.05125, 0));
inWaterTime++;
} else {
inWaterTime = 0;
}
}
@Override
public void onPlayerCollision(PlayerEntity player) {
if (world.isClient || isNoClip() || shake > 0) {
return;
}
if (inWaterTime <= 0) {
super.onPlayerCollision(player);
} else if (tryPickup(player)) {
player.sendPickup(this, 1);
discard();
}
} }
@Override @Override