mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 21:38:00 +01:00
Improve gravity handling when applied to non-player entities
This commit is contained in:
parent
5a24a6162e
commit
3ac781d4f8
4 changed files with 50 additions and 27 deletions
|
@ -2,7 +2,9 @@ package com.minelittlepony.unicopia.client.render;
|
|||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.minelittlepony.unicopia.ability.magic.Caster;
|
||||
import com.minelittlepony.unicopia.ability.magic.spell.DisguiseSpell;
|
||||
import com.minelittlepony.unicopia.entity.Living;
|
||||
import com.minelittlepony.unicopia.entity.behaviour.Disguise;
|
||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
|
||||
|
@ -30,7 +32,7 @@ import net.minecraft.util.math.Vec3d;
|
|||
public class WorldRenderDelegate {
|
||||
public static final WorldRenderDelegate INSTANCE = new WorldRenderDelegate();
|
||||
|
||||
public boolean onEntityRender(EntityRenderDispatcher dispatcher, Pony pony,
|
||||
public boolean onEntityRender(EntityRenderDispatcher dispatcher, Living<?> pony,
|
||||
double x, double y, double z, float yaw,
|
||||
float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light) {
|
||||
|
||||
|
@ -42,7 +44,7 @@ public class WorldRenderDelegate {
|
|||
|
||||
float roll = negative ? 180 : 0;
|
||||
|
||||
roll = pony.getInterpolator().interpolate("g_roll", roll, 15);
|
||||
roll = pony instanceof Pony ? ((Pony)pony).getInterpolator().interpolate("g_roll", roll, 15) : roll;
|
||||
|
||||
if (negative) {
|
||||
matrices.translate(x, y, z);
|
||||
|
@ -55,29 +57,34 @@ public class WorldRenderDelegate {
|
|||
matrices.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(roll));
|
||||
}
|
||||
|
||||
int fireTicks = pony.getMaster().doesRenderOnFire() ? 1 : 0;
|
||||
if (pony instanceof Caster<?>) {
|
||||
|
||||
return pony.getSpellOrEmpty(DisguiseSpell.class, true).map(effect -> {
|
||||
effect.update(pony, false);
|
||||
int fireTicks = pony.getMaster().doesRenderOnFire() ? 1 : 0;
|
||||
|
||||
Disguise ve = effect.getDisguise();
|
||||
Entity e = ve.getAppearance();
|
||||
return ((Caster<?>)pony).getSpellOrEmpty(DisguiseSpell.class, true).map(effect -> {
|
||||
effect.update(pony, false);
|
||||
|
||||
if (e != null) {
|
||||
renderDisguise(dispatcher, ve, e, x, y, z, fireTicks, tickDelta, matrices, vertexConsumers, light);
|
||||
ve.getAttachments().forEach(ee -> {
|
||||
Vec3d difference = ee.getPos().subtract(e.getPos());
|
||||
renderDisguise(dispatcher, ve, ee, x + difference.x, y + difference.y, z + difference.z, fireTicks, tickDelta, matrices, vertexConsumers, light);
|
||||
});
|
||||
Disguise ve = effect.getDisguise();
|
||||
Entity e = ve.getAppearance();
|
||||
|
||||
afterEntityRender(pony, matrices);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}).orElse(false);
|
||||
if (e != null) {
|
||||
renderDisguise(dispatcher, ve, e, x, y, z, fireTicks, tickDelta, matrices, vertexConsumers, light);
|
||||
ve.getAttachments().forEach(ee -> {
|
||||
Vec3d difference = ee.getPos().subtract(e.getPos());
|
||||
renderDisguise(dispatcher, ve, ee, x + difference.x, y + difference.y, z + difference.z, fireTicks, tickDelta, matrices, vertexConsumers, light);
|
||||
});
|
||||
|
||||
afterEntityRender(pony, matrices);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}).orElse(false);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void afterEntityRender(Pony pony, MatrixStack matrices) {
|
||||
public void afterEntityRender(Living<?> pony, MatrixStack matrices) {
|
||||
|
||||
matrices.pop();
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.minelittlepony.unicopia.item.enchantment.UEnchantments;
|
|||
import com.minelittlepony.unicopia.util.VecHelper;
|
||||
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
import net.minecraft.entity.MovementType;
|
||||
import net.minecraft.entity.data.DataTracker;
|
||||
|
@ -20,6 +21,7 @@ import net.minecraft.nbt.CompoundTag;
|
|||
import net.minecraft.particle.ParticleEffect;
|
||||
import net.minecraft.particle.ParticleTypes;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
public class ItemImpl implements Equine<ItemEntity>, Owned<ItemEntity> {
|
||||
|
@ -90,6 +92,21 @@ public class ItemImpl implements Equine<ItemEntity>, Owned<ItemEntity> {
|
|||
}
|
||||
}
|
||||
|
||||
if (physics.isGravityNegative()) {
|
||||
owner.setNoGravity(true);
|
||||
owner.setOnGround(owner.verticalCollision);
|
||||
|
||||
float g = 0.98f;
|
||||
if (owner.isOnGround()) {
|
||||
g *= owner.world.getBlockState(owner.getBlockPos().up()).getBlock().getSlipperiness();
|
||||
}
|
||||
|
||||
owner.setVelocity(owner.getVelocity()
|
||||
.add(0, physics.calcGravity(-0.04D), 0)
|
||||
.multiply(g, 1, g));
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -78,6 +78,7 @@ abstract class MixinPlayerEntity extends LivingEntity implements PonyContainer<P
|
|||
private void onDropItem(ItemStack itemStack_1, boolean scatter, boolean retainOwnership, CallbackInfoReturnable<ItemEntity> info) {
|
||||
PonyContainer.of(info.getReturnValue()).ifPresent(container -> {
|
||||
container.get().setSpecies(get().getSpecies());
|
||||
container.get().getPhysics().setBaseGravityModifier(get().getPhysics().getGravityModifier());
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -6,13 +6,13 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
|||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import com.minelittlepony.unicopia.client.render.WorldRenderDelegate;
|
||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
import com.minelittlepony.unicopia.entity.Equine;
|
||||
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.entity.EntityRenderDispatcher;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
|
||||
@Mixin(EntityRenderDispatcher.class)
|
||||
abstract class MixinEntityRenderDispatcher {
|
||||
|
@ -21,21 +21,19 @@ abstract class MixinEntityRenderDispatcher {
|
|||
|
||||
@Inject(method = RENDER, at = @At("HEAD"), cancellable = true)
|
||||
private <E extends Entity> void beforeRender(E entity, double x, double y, double z, float yaw, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo info) {
|
||||
if (!(entity instanceof PlayerEntity)) {
|
||||
if (!(entity instanceof LivingEntity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (WorldRenderDelegate.INSTANCE.onEntityRender((EntityRenderDispatcher)(Object)this, Pony.of((PlayerEntity)entity), x, y, z, yaw, tickDelta, matrices, vertexConsumers, light)) {
|
||||
if (WorldRenderDelegate.INSTANCE.onEntityRender((EntityRenderDispatcher)(Object)this, Equine.of(entity), x, y, z, yaw, tickDelta, matrices, vertexConsumers, light)) {
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = RENDER, at = @At("RETURN"))
|
||||
private <E extends Entity> void afterRender(E entity, double x, double y, double z, float yaw, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo info) {
|
||||
if (!(entity instanceof PlayerEntity)) {
|
||||
if (!(entity instanceof LivingEntity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
WorldRenderDelegate.INSTANCE.afterEntityRender(Pony.of((PlayerEntity)entity), matrices);
|
||||
WorldRenderDelegate.INSTANCE.afterEntityRender(Equine.of(entity), matrices);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue