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 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,29 +57,34 @@ public class WorldRenderDelegate {
|
||||||
matrices.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(roll));
|
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 -> {
|
int fireTicks = pony.getMaster().doesRenderOnFire() ? 1 : 0;
|
||||||
effect.update(pony, false);
|
|
||||||
|
|
||||||
Disguise ve = effect.getDisguise();
|
return ((Caster<?>)pony).getSpellOrEmpty(DisguiseSpell.class, true).map(effect -> {
|
||||||
Entity e = ve.getAppearance();
|
effect.update(pony, false);
|
||||||
|
|
||||||
if (e != null) {
|
Disguise ve = effect.getDisguise();
|
||||||
renderDisguise(dispatcher, ve, e, x, y, z, fireTicks, tickDelta, matrices, vertexConsumers, light);
|
Entity e = ve.getAppearance();
|
||||||
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);
|
if (e != null) {
|
||||||
return true;
|
renderDisguise(dispatcher, ve, e, x, y, z, fireTicks, tickDelta, matrices, vertexConsumers, light);
|
||||||
}
|
ve.getAttachments().forEach(ee -> {
|
||||||
return false;
|
Vec3d difference = ee.getPos().subtract(e.getPos());
|
||||||
}).orElse(false);
|
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();
|
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