mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +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 javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.minelittlepony.unicopia.ability.magic.Caster;
|
||||||
import com.minelittlepony.unicopia.ability.magic.spell.DisguiseSpell;
|
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.behaviour.Disguise;
|
||||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||||
|
|
||||||
|
@ -30,7 +32,7 @@ import net.minecraft.util.math.Vec3d;
|
||||||
public class WorldRenderDelegate {
|
public class WorldRenderDelegate {
|
||||||
public static final WorldRenderDelegate INSTANCE = new 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,
|
double x, double y, double z, float yaw,
|
||||||
float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light) {
|
float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light) {
|
||||||
|
|
||||||
|
@ -42,7 +44,7 @@ public class WorldRenderDelegate {
|
||||||
|
|
||||||
float roll = negative ? 180 : 0;
|
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) {
|
if (negative) {
|
||||||
matrices.translate(x, y, z);
|
matrices.translate(x, y, z);
|
||||||
|
@ -55,9 +57,11 @@ public class WorldRenderDelegate {
|
||||||
matrices.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(roll));
|
matrices.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(roll));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pony instanceof Caster<?>) {
|
||||||
|
|
||||||
int fireTicks = pony.getMaster().doesRenderOnFire() ? 1 : 0;
|
int fireTicks = pony.getMaster().doesRenderOnFire() ? 1 : 0;
|
||||||
|
|
||||||
return pony.getSpellOrEmpty(DisguiseSpell.class, true).map(effect -> {
|
return ((Caster<?>)pony).getSpellOrEmpty(DisguiseSpell.class, true).map(effect -> {
|
||||||
effect.update(pony, false);
|
effect.update(pony, false);
|
||||||
|
|
||||||
Disguise ve = effect.getDisguise();
|
Disguise ve = effect.getDisguise();
|
||||||
|
@ -77,7 +81,10 @@ public class WorldRenderDelegate {
|
||||||
}).orElse(false);
|
}).orElse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void afterEntityRender(Pony pony, MatrixStack matrices) {
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void afterEntityRender(Living<?> pony, MatrixStack matrices) {
|
||||||
|
|
||||||
matrices.pop();
|
matrices.pop();
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import com.minelittlepony.unicopia.item.enchantment.UEnchantments;
|
||||||
import com.minelittlepony.unicopia.util.VecHelper;
|
import com.minelittlepony.unicopia.util.VecHelper;
|
||||||
|
|
||||||
import net.minecraft.enchantment.EnchantmentHelper;
|
import net.minecraft.enchantment.EnchantmentHelper;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.ItemEntity;
|
import net.minecraft.entity.ItemEntity;
|
||||||
import net.minecraft.entity.MovementType;
|
import net.minecraft.entity.MovementType;
|
||||||
import net.minecraft.entity.data.DataTracker;
|
import net.minecraft.entity.data.DataTracker;
|
||||||
|
@ -20,6 +21,7 @@ import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.particle.ParticleEffect;
|
import net.minecraft.particle.ParticleEffect;
|
||||||
import net.minecraft.particle.ParticleTypes;
|
import net.minecraft.particle.ParticleTypes;
|
||||||
import net.minecraft.util.ActionResult;
|
import net.minecraft.util.ActionResult;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
|
||||||
public class ItemImpl implements Equine<ItemEntity>, Owned<ItemEntity> {
|
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;
|
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) {
|
private void onDropItem(ItemStack itemStack_1, boolean scatter, boolean retainOwnership, CallbackInfoReturnable<ItemEntity> info) {
|
||||||
PonyContainer.of(info.getReturnValue()).ifPresent(container -> {
|
PonyContainer.of(info.getReturnValue()).ifPresent(container -> {
|
||||||
container.get().setSpecies(get().getSpecies());
|
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 org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.client.render.WorldRenderDelegate;
|
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.VertexConsumerProvider;
|
||||||
import net.minecraft.client.render.entity.EntityRenderDispatcher;
|
import net.minecraft.client.render.entity.EntityRenderDispatcher;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
|
|
||||||
@Mixin(EntityRenderDispatcher.class)
|
@Mixin(EntityRenderDispatcher.class)
|
||||||
abstract class MixinEntityRenderDispatcher {
|
abstract class MixinEntityRenderDispatcher {
|
||||||
|
@ -21,21 +21,19 @@ abstract class MixinEntityRenderDispatcher {
|
||||||
|
|
||||||
@Inject(method = RENDER, at = @At("HEAD"), cancellable = true)
|
@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) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
if (WorldRenderDelegate.INSTANCE.onEntityRender((EntityRenderDispatcher)(Object)this, Equine.of(entity), x, y, z, yaw, tickDelta, matrices, vertexConsumers, light)) {
|
||||||
if (WorldRenderDelegate.INSTANCE.onEntityRender((EntityRenderDispatcher)(Object)this, Pony.of((PlayerEntity)entity), x, y, z, yaw, tickDelta, matrices, vertexConsumers, light)) {
|
|
||||||
info.cancel();
|
info.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = RENDER, at = @At("RETURN"))
|
@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) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
WorldRenderDelegate.INSTANCE.afterEntityRender(Equine.of(entity), matrices);
|
||||||
WorldRenderDelegate.INSTANCE.afterEntityRender(Pony.of((PlayerEntity)entity), matrices);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue