diff --git a/src/main/java/com/minelittlepony/unicopia/Unicopia.java b/src/main/java/com/minelittlepony/unicopia/Unicopia.java index c83ce30f..b3bfd28e 100644 --- a/src/main/java/com/minelittlepony/unicopia/Unicopia.java +++ b/src/main/java/com/minelittlepony/unicopia/Unicopia.java @@ -3,6 +3,7 @@ package com.minelittlepony.unicopia; import net.minecraft.block.Block; import net.minecraft.block.BlockCrops; import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.EnumAction; import net.minecraft.item.Item; @@ -10,6 +11,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; import net.minecraft.util.SoundEvent; import net.minecraftforge.client.event.ColorHandlerEvent; +import net.minecraftforge.client.event.EntityViewRenderEvent; import net.minecraftforge.client.event.FOVUpdateEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; @@ -153,6 +155,17 @@ public class Unicopia { } } + @SideOnly(Side.CLIENT) + @SubscribeEvent + public static void setupPlayerCamera(EntityViewRenderEvent.CameraSetup event) { + + EntityPlayer player = Minecraft.getMinecraft().player; + + if (player != null) { + event.setRoll((float)PlayerSpeciesList.instance().getPlayer(player).getCamera().calculateRoll(player)); + } + } + @SubscribeEvent public static void onBlockHarvested(BlockEvent.HarvestDropsEvent event) { Block block = event.getState().getBlock(); diff --git a/src/main/java/com/minelittlepony/unicopia/advancements/AbstractTrigger.java b/src/main/java/com/minelittlepony/unicopia/advancements/AbstractTrigger.java new file mode 100644 index 00000000..5feaa4ee --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/advancements/AbstractTrigger.java @@ -0,0 +1,52 @@ +package com.minelittlepony.unicopia.advancements; + +import java.util.List; +import java.util.Map; + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; + +import net.minecraft.advancements.ICriterionTrigger; +import net.minecraft.advancements.PlayerAdvancements; +import net.minecraft.advancements.critereon.AbstractCriterionInstance; + +public abstract class AbstractTrigger, T extends AbstractCriterionInstance> implements ICriterionTrigger { + + protected final Map listeners = Maps.newHashMap(); + + @Override + public void addListener(PlayerAdvancements key, Listener listener) { + listeners.computeIfAbsent(key, this::createEntry).listeners.add(listener);; + } + + @Override + public void removeListener(PlayerAdvancements key, Listener listener) { + if (listeners.containsKey(key)) { + E entry = listeners.get(key); + + entry.listeners.remove(listener); + if (entry.listeners.isEmpty()) { + listeners.remove(key); + } + } + } + + @Override + public void removeAllListeners(PlayerAdvancements key) { + if (listeners.containsKey(key)) { + listeners.remove(key); + } + } + + protected abstract E createEntry(PlayerAdvancements advancement); + + protected static class Entry { + protected final PlayerAdvancements advancement; + + protected final List> listeners = Lists.newArrayList(); + + Entry(PlayerAdvancements key) { + advancement = key; + } + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/advancements/BOHDeathTrigger.java b/src/main/java/com/minelittlepony/unicopia/advancements/BOHDeathTrigger.java index ec48a5bf..7a6a3e4b 100644 --- a/src/main/java/com/minelittlepony/unicopia/advancements/BOHDeathTrigger.java +++ b/src/main/java/com/minelittlepony/unicopia/advancements/BOHDeathTrigger.java @@ -1,15 +1,10 @@ package com.minelittlepony.unicopia.advancements; -import java.util.List; -import java.util.Map; import java.util.Optional; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonObject; -import net.minecraft.advancements.ICriterionTrigger; import net.minecraft.advancements.PlayerAdvancements; import net.minecraft.advancements.critereon.AbstractCriterionInstance; import net.minecraft.entity.player.EntityPlayerMP; @@ -19,46 +14,25 @@ import net.minecraft.world.WorldServer; /** * Advantement trigger for the book of holding. It's an achievement to die so spectacularly! :D */ -public class BOHDeathTrigger implements ICriterionTrigger { +public class BOHDeathTrigger extends AbstractTrigger { private static final ResourceLocation ID = new ResourceLocation("unicopia", "death_by_bag_of_holding"); - private final Map listeners = Maps.newHashMap(); - @Override public ResourceLocation getId() { return ID; } - @Override - public void addListener(PlayerAdvancements key, Listener listener) { - listeners.computeIfAbsent(key, Entry::new).listeners.add(listener);; - } - - @Override - public void removeListener(PlayerAdvancements key, Listener listener) { - if (listeners.containsKey(key)) { - Entry entry = listeners.get(key); - - entry.listeners.remove(listener); - if (entry.listeners.isEmpty()) { - listeners.remove(key); - } - } - } - - @Override - public void removeAllListeners(PlayerAdvancements key) { - if (listeners.containsKey(key)) { - listeners.remove(key); - } - } - @Override public Instance deserializeInstance(JsonObject json, JsonDeserializationContext context) { return new Instance(AdvancementPredicate.deserialize(json.get("advancement"))); } + @Override + protected Entry createEntry(PlayerAdvancements advancement) { + return new Entry(advancement); + } + public void trigger(EntityPlayerMP player) { PlayerAdvancements key = player.getAdvancements(); @@ -69,12 +43,12 @@ public class BOHDeathTrigger implements ICriterionTrigger> listeners = Lists.newArrayList(); + static class Entry extends AbstractTrigger.Entry { Entry(PlayerAdvancements key) { - advancement = key; + super(key); } public void trigger(WorldServer world, PlayerAdvancements playerAdvancements) { @@ -98,4 +69,5 @@ public class BOHDeathTrigger implements ICriterionTrigger winner.grantCriterion(advancement));; } } + } diff --git a/src/main/java/com/minelittlepony/unicopia/network/MsgRequestCapabilities.java b/src/main/java/com/minelittlepony/unicopia/network/MsgRequestCapabilities.java index 56732e28..792f873b 100644 --- a/src/main/java/com/minelittlepony/unicopia/network/MsgRequestCapabilities.java +++ b/src/main/java/com/minelittlepony/unicopia/network/MsgRequestCapabilities.java @@ -30,7 +30,9 @@ public class MsgRequestCapabilities implements IMessage, IMessageHandler, IRaceContainer { private final PlayerAttributes attributes = new PlayerAttributes(); + private final PlayerView view = new PlayerView(this); + private final EffectSync effectDelegate = new EffectSync<>(this, EFFECT); + private final IInterpolator interpolator = new BasicEasingInterpolator(); + private float nextStepDistance = 1; private EntityPlayer entity; @@ -112,6 +118,16 @@ class PlayerCapabilities implements IPlayer, ICaster { return gravity; } + @Override + public IView getCamera() { + return view; + } + + @Override + public IInterpolator getInterpolator() { + return interpolator; + } + @Override public boolean isClientPlayer() { return UClient.isClientSide() && diff --git a/src/main/java/com/minelittlepony/unicopia/player/PlayerGravityDelegate.java b/src/main/java/com/minelittlepony/unicopia/player/PlayerGravityDelegate.java index 64b07a0b..c4cccce3 100644 --- a/src/main/java/com/minelittlepony/unicopia/player/PlayerGravityDelegate.java +++ b/src/main/java/com/minelittlepony/unicopia/player/PlayerGravityDelegate.java @@ -48,10 +48,11 @@ class PlayerGravityDelegate implements IUpdatable, IGravity, InbtS boolean rainboom = Math.sqrt(getHorizontalMotion(entity)) > 0.4F; if (isFlying && rainboom) { - MixinEntity.setSize(entity, entity.width, 0.5F); - entity.eyeHeight = entity.height / 2; + MixinEntity.setSize(entity, entity.width, player.getInterpolator().interpolate("standingHeight", 0.5F, 10)); + entity.eyeHeight = player.getInterpolator().interpolate("eyeHeight", entity.height / 2, 10); } else { - entity.eyeHeight = entity.getDefaultEyeHeight(); + MixinEntity.setSize(entity, entity.width, player.getInterpolator().interpolate("standingHeight", entity.height, 10)); + entity.eyeHeight = player.getInterpolator().interpolate("eyeHeight", entity.getDefaultEyeHeight(), 10); } if (!entity.capabilities.isCreativeMode && !entity.isElytraFlying()) { diff --git a/src/main/java/com/minelittlepony/unicopia/player/PlayerView.java b/src/main/java/com/minelittlepony/unicopia/player/PlayerView.java new file mode 100644 index 00000000..9263c33e --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/player/PlayerView.java @@ -0,0 +1,38 @@ +package com.minelittlepony.unicopia.player; + +import com.minelittlepony.transform.MotionCompositor; + +import net.minecraft.entity.player.EntityPlayer; + +class PlayerView extends MotionCompositor implements IView { + + private final IPlayer player; + + private double baseRoll = 0; + + public PlayerView(IPlayer player) { + this.player = player; + } + + @Override + public double calculateRoll(EntityPlayer entity) { + + double roll = baseRoll; + + if (player.getGravity().isFlying()) { + roll -= super.calculateRoll(entity, entity.motionX, entity.motionY, entity.motionZ); + } + + return player.getInterpolator().interpolate("roll", (float)roll, 100); + } + + @Override + public double getBaseRoll() { + return baseRoll; + } + + @Override + public void setBaseRoll(double roll) { + baseRoll = roll; + } +}