mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-01 11:36:43 +01:00
Make the GravityDelegate perform true to its name
This commit is contained in:
parent
0ea59c1097
commit
34ea069542
10 changed files with 197 additions and 5 deletions
|
@ -5,6 +5,7 @@ import com.minelittlepony.unicopia.hud.UHud;
|
|||
import com.minelittlepony.unicopia.player.IPlayer;
|
||||
import com.minelittlepony.unicopia.player.IView;
|
||||
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiOptions;
|
||||
import net.minecraft.client.gui.GuiShareToLan;
|
||||
|
@ -29,6 +30,8 @@ class ClientHooks {
|
|||
@SubscribeEvent
|
||||
public static void postEntityRender(RenderLivingEvent.Post<?> event) {
|
||||
GlStateManager.enableAlpha();
|
||||
|
||||
UClient.instance().postRenderEntity(event.getEntity());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
|
|
@ -78,6 +78,10 @@ public class UClient {
|
|||
return new EntityFakeServerPlayer((WorldServer)observer.world, profile);
|
||||
}
|
||||
|
||||
public void postRenderEntity(Entity entity) {
|
||||
|
||||
}
|
||||
|
||||
public boolean renderEntity(Entity entity, float renderPartialTicks) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@ import com.minelittlepony.unicopia.gui.GuiScreenSettings;
|
|||
import com.minelittlepony.unicopia.init.UEntities;
|
||||
import com.minelittlepony.unicopia.init.UParticles;
|
||||
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.network.MsgRequestCapabilities;
|
||||
import com.minelittlepony.unicopia.player.IPlayer;
|
||||
|
@ -26,8 +28,10 @@ import com.mojang.authlib.GameProfile;
|
|||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.MovementInput;
|
||||
import net.minecraft.world.IInteractionObject;
|
||||
|
||||
import static com.minelittlepony.util.gui.ButtonGridLayout.*;
|
||||
|
@ -139,6 +143,20 @@ public class UnicopiaClient extends UClient {
|
|||
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
|
||||
public boolean renderEntity(Entity entity, float renderPartialTicks) {
|
||||
|
||||
|
@ -149,6 +167,13 @@ public class UnicopiaClient extends UClient {
|
|||
if (entity instanceof EntityPlayer) {
|
||||
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)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -186,5 +211,21 @@ public class UnicopiaClient extends UClient {
|
|||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,6 +9,7 @@ import net.minecraft.util.math.RayTraceResult;
|
|||
import net.minecraftforge.event.entity.ProjectileImpactEvent;
|
||||
import net.minecraftforge.event.entity.item.ItemTossEvent;
|
||||
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.PlayerEvent;
|
||||
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
|
||||
public static void onPlayerVisibilityCheck(PlayerEvent.Visibility event) {
|
||||
if (PlayerSpeciesList.instance().getPlayer(event.getEntityPlayer()).isInvisible()) {
|
||||
|
|
|
@ -6,4 +6,12 @@ public interface IGravity {
|
|||
float getFlightExperience();
|
||||
|
||||
float getFlightDuration();
|
||||
|
||||
void setGraviationConstant(float constant);
|
||||
|
||||
float getGravitationConstant();
|
||||
|
||||
default void clearGraviationConstant() {
|
||||
setGraviationConstant(Float.NaN);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,8 @@ class PlayerGravityDelegate implements IUpdatable, IGravity, InbtSerialisable, I
|
|||
|
||||
public boolean isFlying = false;
|
||||
|
||||
private float gravity = Float.NaN;
|
||||
|
||||
public PlayerGravityDelegate(IPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
@ -97,6 +99,15 @@ class PlayerGravityDelegate implements IUpdatable, IGravity, InbtSerialisable, I
|
|||
return player.getOwner().height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGraviationConstant(float constant) {
|
||||
gravity = constant;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getGravitationConstant() {
|
||||
return gravity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate() {
|
||||
|
@ -110,8 +121,33 @@ class PlayerGravityDelegate implements IUpdatable, IGravity, InbtSerialisable, I
|
|||
|
||||
isFlying = entity.capabilities.isFlying && !entity.capabilities.isCreativeMode;
|
||||
|
||||
MixinEntity.setSize(entity, entity.width, player.getInterpolator().interpolate("standingHeight", getTargetBodyHeight(player), 10));
|
||||
entity.eyeHeight = player.getInterpolator().interpolate("eyeHeight", getTargetEyeHeight(player), 10);
|
||||
if (!entity.capabilities.isFlying || !entity.capabilities.isCreativeMode) {
|
||||
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 (isFlying && !entity.isRiding()) {
|
||||
|
@ -271,6 +307,10 @@ class PlayerGravityDelegate implements IUpdatable, IGravity, InbtSerialisable, I
|
|||
compound.setInteger("flightDuration", ticksInAir);
|
||||
compound.setFloat("flightExperience", flightExperience);
|
||||
compound.setBoolean("isFlying", isFlying);
|
||||
|
||||
if (gravity != Float.NaN) {
|
||||
compound.setFloat("gravity", gravity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -278,6 +318,12 @@ class PlayerGravityDelegate implements IUpdatable, IGravity, InbtSerialisable, I
|
|||
ticksInAir = compound.getInteger("flightDuration");
|
||||
flightExperience = compound.getFloat("flightExperience");
|
||||
isFlying = compound.getBoolean("isFlying");
|
||||
|
||||
if (compound.hasKey("gravity")) {
|
||||
gravity = compound.getFloat("gravity");
|
||||
} else {
|
||||
gravity = Float.NaN;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,6 +21,10 @@ class PlayerView extends MotionCompositor implements IView {
|
|||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@ import net.minecraft.entity.player.EntityPlayer;
|
|||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumParticleTypes;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -127,8 +126,7 @@ public class SpellIce extends AbstractSpell.RangedAreaSpell implements IUseActio
|
|||
} else if (e.isBurning()) {
|
||||
e.extinguish();
|
||||
} else {
|
||||
DamageSource d = MagicalDamageSource.causePlayerDamage("cold", owner);
|
||||
e.attackEntityFrom(d, 2);
|
||||
e.attackEntityFrom(MagicalDamageSource.causePlayerDamage("cold", owner), 2);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue