Make the GravityDelegate perform true to its name

This commit is contained in:
Sollace 2019-02-27 22:15:04 +02:00
parent 0ea59c1097
commit 34ea069542
10 changed files with 197 additions and 5 deletions

View file

@ -5,6 +5,7 @@ import com.minelittlepony.unicopia.hud.UHud;
import com.minelittlepony.unicopia.player.IPlayer; import com.minelittlepony.unicopia.player.IPlayer;
import com.minelittlepony.unicopia.player.IView; import com.minelittlepony.unicopia.player.IView;
import com.minelittlepony.unicopia.player.PlayerSpeciesList; import com.minelittlepony.unicopia.player.PlayerSpeciesList;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiOptions; import net.minecraft.client.gui.GuiOptions;
import net.minecraft.client.gui.GuiShareToLan; import net.minecraft.client.gui.GuiShareToLan;
@ -29,6 +30,8 @@ class ClientHooks {
@SubscribeEvent @SubscribeEvent
public static void postEntityRender(RenderLivingEvent.Post<?> event) { public static void postEntityRender(RenderLivingEvent.Post<?> event) {
GlStateManager.enableAlpha(); GlStateManager.enableAlpha();
UClient.instance().postRenderEntity(event.getEntity());
} }
@SubscribeEvent @SubscribeEvent

View file

@ -78,6 +78,10 @@ public class UClient {
return new EntityFakeServerPlayer((WorldServer)observer.world, profile); return new EntityFakeServerPlayer((WorldServer)observer.world, profile);
} }
public void postRenderEntity(Entity entity) {
}
public boolean renderEntity(Entity entity, float renderPartialTicks) { public boolean renderEntity(Entity entity, float renderPartialTicks) {
return false; return false;
} }

View file

@ -14,6 +14,8 @@ import com.minelittlepony.unicopia.gui.GuiScreenSettings;
import com.minelittlepony.unicopia.init.UEntities; import com.minelittlepony.unicopia.init.UEntities;
import com.minelittlepony.unicopia.init.UParticles; import com.minelittlepony.unicopia.init.UParticles;
import com.minelittlepony.unicopia.input.Keyboard; import com.minelittlepony.unicopia.input.Keyboard;
import com.minelittlepony.unicopia.input.MouseControl;
import com.minelittlepony.unicopia.input.MovementControl;
import com.minelittlepony.unicopia.inventory.gui.GuiOfHolding; import com.minelittlepony.unicopia.inventory.gui.GuiOfHolding;
import com.minelittlepony.unicopia.network.MsgRequestCapabilities; import com.minelittlepony.unicopia.network.MsgRequestCapabilities;
import com.minelittlepony.unicopia.player.IPlayer; import com.minelittlepony.unicopia.player.IPlayer;
@ -26,8 +28,10 @@ import com.mojang.authlib.GameProfile;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.MovementInput;
import net.minecraft.world.IInteractionObject; import net.minecraft.world.IInteractionObject;
import static com.minelittlepony.util.gui.ButtonGridLayout.*; import static com.minelittlepony.util.gui.ButtonGridLayout.*;
@ -139,6 +143,20 @@ public class UnicopiaClient extends UClient {
return Minecraft.getMinecraft().gameSettings.thirdPersonView; return Minecraft.getMinecraft().gameSettings.thirdPersonView;
} }
@Override
public void postRenderEntity(Entity entity) {
if (entity instanceof EntityPlayer) {
IPlayer iplayer = PlayerSpeciesList.instance().getPlayer((EntityPlayer)entity);
if (iplayer.getGravity().getGravitationConstant() < 0) {
GlStateManager.translate(0, entity.height, 0);
GlStateManager.scale(1, -1, 1);
entity.prevRotationPitch *= -1;
entity.rotationPitch *= -1;
}
}
}
@Override @Override
public boolean renderEntity(Entity entity, float renderPartialTicks) { public boolean renderEntity(Entity entity, float renderPartialTicks) {
@ -149,6 +167,13 @@ public class UnicopiaClient extends UClient {
if (entity instanceof EntityPlayer) { if (entity instanceof EntityPlayer) {
IPlayer iplayer = PlayerSpeciesList.instance().getPlayer((EntityPlayer)entity); IPlayer iplayer = PlayerSpeciesList.instance().getPlayer((EntityPlayer)entity);
if (iplayer.getGravity().getGravitationConstant() < 0) {
GlStateManager.scale(1, -1, 1);
GlStateManager.translate(0, -entity.height, 0);
entity.prevRotationPitch *= -1;
entity.rotationPitch *= -1;
}
if (DisguiseRenderer.instance().renderDisguiseToGui(iplayer)) { if (DisguiseRenderer.instance().renderDisguiseToGui(iplayer)) {
return true; return true;
} }
@ -186,5 +211,21 @@ public class UnicopiaClient extends UClient {
} }
Keyboard.getKeyHandler().onKeyInput(); Keyboard.getKeyHandler().onKeyInput();
if (player instanceof EntityPlayerSP) {
EntityPlayerSP sp = (EntityPlayerSP)player;
MovementInput movement = sp.movementInput;
if (!(movement instanceof MovementControl)) {
sp.movementInput = new MovementControl(movement);
}
}
Minecraft mc = Minecraft.getMinecraft();
if (!(mc.mouseHelper instanceof MouseControl)) {
mc.mouseHelper = new MouseControl();
}
} }
} }

View file

@ -0,0 +1,16 @@
package com.minelittlepony.unicopia.input;
import com.minelittlepony.unicopia.UClient;
import net.minecraft.util.MouseHelper;
public class MouseControl extends MouseHelper {
public void mouseXYChange() {
super.mouseXYChange();
if (UClient.instance().getIPlayer().getGravity().getGravitationConstant() < 0) {
deltaX = -deltaX;
deltaY = -deltaY;
}
}
}

View file

@ -0,0 +1,62 @@
package com.minelittlepony.unicopia.input;
import com.minelittlepony.unicopia.UClient;
import com.minelittlepony.unicopia.forgebullshit.FUF;
import com.minelittlepony.unicopia.player.IPlayer;
import net.minecraft.client.Minecraft;
import net.minecraft.util.MovementInput;
import net.minecraft.util.MovementInputFromOptions;
@FUF(reason = "Back to the ancient art of proxy classes...")
public class MovementControl extends MovementInputFromOptions {
static boolean recurseCheck;
private MovementInput wrappedInstance;
public MovementControl(MovementInput inherited) {
super(Minecraft.getMinecraft().gameSettings);
wrappedInstance = inherited;
}
@Override
public void updatePlayerMoveState() {
// Other mods might wrap us, in which case let's just pretend to be the vanilla one.
// We'll replace them at the top level and let go of the inner to prevent the chain from growing.
if (recurseCheck) {
wrappedInstance = null;
super.updatePlayerMoveState();
}
recurseCheck = true;
wrappedInstance.updatePlayerMoveState();
recurseCheck = false;
this.moveStrafe = wrappedInstance.moveStrafe;
this.moveForward = wrappedInstance.moveForward;
this.forwardKeyDown = wrappedInstance.forwardKeyDown;
this.backKeyDown = wrappedInstance.backKeyDown;
this.leftKeyDown = wrappedInstance.leftKeyDown;
this.rightKeyDown = wrappedInstance.rightKeyDown;
this.jump = wrappedInstance.jump;
this.sneak = wrappedInstance.sneak;
IPlayer player = UClient.instance().getIPlayer();
if (player.getGravity().getGravitationConstant() < 0) {
boolean tmp = leftKeyDown;
leftKeyDown = rightKeyDown;
rightKeyDown = tmp;
moveStrafe = -moveStrafe;
if (player.getOwner().capabilities.isCreativeMode && player.getOwner().capabilities.isFlying) {
tmp = jump;
jump = sneak;
sneak = tmp;
}
}
}
}

View file

@ -9,6 +9,7 @@ import net.minecraft.util.math.RayTraceResult;
import net.minecraftforge.event.entity.ProjectileImpactEvent; import net.minecraftforge.event.entity.ProjectileImpactEvent;
import net.minecraftforge.event.entity.item.ItemTossEvent; import net.minecraftforge.event.entity.item.ItemTossEvent;
import net.minecraftforge.event.entity.living.LivingEntityUseItemEvent; import net.minecraftforge.event.entity.living.LivingEntityUseItemEvent;
import net.minecraftforge.event.entity.living.LivingEvent.LivingJumpEvent;
import net.minecraftforge.event.entity.player.PlayerDropsEvent; import net.minecraftforge.event.entity.player.PlayerDropsEvent;
import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.entity.player.PlayerFlyableFallEvent; import net.minecraftforge.event.entity.player.PlayerFlyableFallEvent;
@ -29,6 +30,15 @@ class Hooks {
} }
} }
@SubscribeEvent
public static void onPlayerJump(LivingJumpEvent event) {
if (event.getEntityLiving() instanceof EntityPlayer) {
if (PlayerSpeciesList.instance().getPlayer((EntityPlayer)event.getEntityLiving()).getGravity().getGravitationConstant() < 0) {
event.getEntityLiving().motionY = -event.getEntityLiving().motionY;
}
}
}
@SubscribeEvent @SubscribeEvent
public static void onPlayerVisibilityCheck(PlayerEvent.Visibility event) { public static void onPlayerVisibilityCheck(PlayerEvent.Visibility event) {
if (PlayerSpeciesList.instance().getPlayer(event.getEntityPlayer()).isInvisible()) { if (PlayerSpeciesList.instance().getPlayer(event.getEntityPlayer()).isInvisible()) {

View file

@ -6,4 +6,12 @@ public interface IGravity {
float getFlightExperience(); float getFlightExperience();
float getFlightDuration(); float getFlightDuration();
void setGraviationConstant(float constant);
float getGravitationConstant();
default void clearGraviationConstant() {
setGraviationConstant(Float.NaN);
}
} }

View file

@ -33,6 +33,8 @@ class PlayerGravityDelegate implements IUpdatable, IGravity, InbtSerialisable, I
public boolean isFlying = false; public boolean isFlying = false;
private float gravity = Float.NaN;
public PlayerGravityDelegate(IPlayer player) { public PlayerGravityDelegate(IPlayer player) {
this.player = player; this.player = player;
} }
@ -97,6 +99,15 @@ class PlayerGravityDelegate implements IUpdatable, IGravity, InbtSerialisable, I
return player.getOwner().height; return player.getOwner().height;
} }
@Override
public void setGraviationConstant(float constant) {
gravity = constant;
}
@Override
public float getGravitationConstant() {
return gravity;
}
@Override @Override
public void onUpdate() { public void onUpdate() {
@ -110,8 +121,33 @@ class PlayerGravityDelegate implements IUpdatable, IGravity, InbtSerialisable, I
isFlying = entity.capabilities.isFlying && !entity.capabilities.isCreativeMode; isFlying = entity.capabilities.isFlying && !entity.capabilities.isCreativeMode;
MixinEntity.setSize(entity, entity.width, player.getInterpolator().interpolate("standingHeight", getTargetBodyHeight(player), 10)); if (!entity.capabilities.isFlying || !entity.capabilities.isCreativeMode) {
entity.eyeHeight = player.getInterpolator().interpolate("eyeHeight", getTargetEyeHeight(player), 10); gravity = -0.08F;
if (gravity != Float.NaN) {
entity.motionY += 0.08;
entity.motionY -= gravity;
entity.onGround = !entity.world.isAirBlock(new BlockPos(entity.posX, entity.posY + entity.height + 0.5F, entity.posZ));
}
}
float bodyHeight = getTargetBodyHeight(player);
MixinEntity.setSize(entity, entity.width, player.getInterpolator().interpolate("standingHeight", bodyHeight, 10));
float eyeHeight = getTargetEyeHeight(player);
if (gravity < 0) {
eyeHeight = bodyHeight - eyeHeight;
}
entity.eyeHeight = player.getInterpolator().interpolate("eyeHeight", eyeHeight, 10);
if (gravity < 0) {
if (entity.isSneaking()) {
entity.eyeHeight += 0.2F;
}
}
if (!entity.capabilities.isCreativeMode && !entity.isElytraFlying()) { if (!entity.capabilities.isCreativeMode && !entity.isElytraFlying()) {
if (isFlying && !entity.isRiding()) { if (isFlying && !entity.isRiding()) {
@ -271,6 +307,10 @@ class PlayerGravityDelegate implements IUpdatable, IGravity, InbtSerialisable, I
compound.setInteger("flightDuration", ticksInAir); compound.setInteger("flightDuration", ticksInAir);
compound.setFloat("flightExperience", flightExperience); compound.setFloat("flightExperience", flightExperience);
compound.setBoolean("isFlying", isFlying); compound.setBoolean("isFlying", isFlying);
if (gravity != Float.NaN) {
compound.setFloat("gravity", gravity);
}
} }
@Override @Override
@ -278,6 +318,12 @@ class PlayerGravityDelegate implements IUpdatable, IGravity, InbtSerialisable, I
ticksInAir = compound.getInteger("flightDuration"); ticksInAir = compound.getInteger("flightDuration");
flightExperience = compound.getFloat("flightExperience"); flightExperience = compound.getFloat("flightExperience");
isFlying = compound.getBoolean("isFlying"); isFlying = compound.getBoolean("isFlying");
if (compound.hasKey("gravity")) {
gravity = compound.getFloat("gravity");
} else {
gravity = Float.NaN;
}
} }
@Override @Override

View file

@ -21,6 +21,10 @@ class PlayerView extends MotionCompositor implements IView {
roll -= super.calculateRoll(player.getOwner(), player.getOwner().motionX, player.getOwner().motionY, player.getOwner().motionZ); roll -= super.calculateRoll(player.getOwner(), player.getOwner().motionX, player.getOwner().motionY, player.getOwner().motionZ);
} }
if (player.getGravity().getGravitationConstant() < 0) {
roll += 180;
}
return (float)player.getInterpolator().interpolate("roll", (float)roll, 100); return (float)player.getInterpolator().interpolate("roll", (float)roll, 100);
} }

View file

@ -23,7 +23,6 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.EnumParticleTypes;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -127,8 +126,7 @@ public class SpellIce extends AbstractSpell.RangedAreaSpell implements IUseActio
} else if (e.isBurning()) { } else if (e.isBurning()) {
e.extinguish(); e.extinguish();
} else { } else {
DamageSource d = MagicalDamageSource.causePlayerDamage("cold", owner); e.attackEntityFrom(MagicalDamageSource.causePlayerDamage("cold", owner), 2);
e.attackEntityFrom(d, 2);
} }
return true; return true;