Unicopia/src/main/java/com/minelittlepony/unicopia/entity/ItemPhysics.java

47 lines
1.4 KiB
Java
Raw Normal View History

package com.minelittlepony.unicopia.entity;
2024-05-20 21:56:44 +02:00
import com.minelittlepony.unicopia.network.track.DataTracker;
import net.minecraft.entity.ItemEntity;
class ItemPhysics extends EntityPhysics<ItemEntity> {
2024-05-20 21:56:44 +02:00
public ItemPhysics(ItemEntity entity, DataTracker tracker) {
super(entity, tracker);
}
@Override
public void tick() {
super.tick();
if (isGravityNegative() && !entity.getStack().isEmpty()) {
entity.setNoGravity(true);
entity.addVelocity(
0,
0.04
+ calcGravity(-0.04D), // apply our own
0
);
if (!entity.isOnGround()
2021-08-04 15:38:03 +02:00
|| entity.getVelocity().horizontalLengthSquared() > 9.999999747378752E-6D) {
float above = 0.98f;
if (entity.verticalCollision) {
2023-06-03 13:40:54 +02:00
above *= entity.getWorld().getBlockState(entity.getBlockPos().up()).getBlock().getSlipperiness();
//above /= 9;
}
entity.setVelocity(entity.getVelocity().multiply(above, 1, above));
}
}
}
@Override
protected void onGravitychanged() {
2023-06-03 13:40:54 +02:00
if (!entity.getWorld().isClient) {
float gravity = getBaseGravityModifier();
setBaseGravityModifier(gravity == 0 ? 1 : gravity * 2);
setBaseGravityModifier(gravity);
}
}
}