mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Added flying sounds, added a hud element to show flight experience
This commit is contained in:
parent
6830394870
commit
9c21467ebb
16 changed files with 237 additions and 10 deletions
15
src/main/java/com/minelittlepony/unicopia/USounds.java
Normal file
15
src/main/java/com/minelittlepony/unicopia/USounds.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
package com.minelittlepony.unicopia;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
|
||||
public class USounds {
|
||||
|
||||
public static final SoundEvent WING_FLAP = new SoundEvent(new ResourceLocation(Unicopia.MODID, "wing_flap"))
|
||||
.setRegistryName(Unicopia.MODID, "wing_flap");
|
||||
|
||||
static void init(IForgeRegistry<SoundEvent> registry) {
|
||||
registry.registerAll(WING_FLAP);
|
||||
}
|
||||
}
|
|
@ -7,8 +7,11 @@ import net.minecraft.item.EnumAction;
|
|||
import net.minecraft.item.Item;
|
||||
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.FOVUpdateEvent;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.event.entity.item.ItemTossEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerDropsEvent;
|
||||
|
@ -36,10 +39,12 @@ import com.minelittlepony.unicopia.client.particle.EntityMagicFX;
|
|||
import com.minelittlepony.unicopia.client.particle.EntityRaindropFX;
|
||||
import com.minelittlepony.unicopia.client.particle.Particles;
|
||||
import com.minelittlepony.unicopia.command.Commands;
|
||||
import com.minelittlepony.unicopia.hud.UHud;
|
||||
import com.minelittlepony.unicopia.input.Keyboard;
|
||||
import com.minelittlepony.unicopia.network.MsgPlayerAbility;
|
||||
import com.minelittlepony.unicopia.network.MsgPlayerCapabilities;
|
||||
import com.minelittlepony.unicopia.network.MsgRequestCapabilities;
|
||||
import com.minelittlepony.unicopia.player.IPlayer;
|
||||
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
|
||||
import com.minelittlepony.unicopia.power.PowersRegistry;
|
||||
import com.minelittlepony.pony.data.IPony;
|
||||
|
@ -86,9 +91,7 @@ public class Unicopia {
|
|||
|
||||
@EventHandler
|
||||
public void init(FMLInitializationEvent event) {
|
||||
channel = JumpingCastle.subscribeTo(MODID, () -> {
|
||||
channel.send(new MsgRequestCapabilities(Minecraft.getMinecraft().player, clientPlayerRace), Target.SERVER);
|
||||
})
|
||||
channel = JumpingCastle.subscribeTo(MODID, () -> {})
|
||||
.listenFor(MsgRequestCapabilities.class)
|
||||
.listenFor(MsgPlayerCapabilities.class)
|
||||
.listenFor(MsgPlayerAbility.class);
|
||||
|
@ -119,10 +122,15 @@ public class Unicopia {
|
|||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerRecipesStatic(RegistryEvent.Register<IRecipe> event) {
|
||||
public static void registerSounds(RegistryEvent.Register<IRecipe> event) {
|
||||
UItems.registerRecipes(event.getRegistry());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerRecipesStatic(RegistryEvent.Register<SoundEvent> event) {
|
||||
USounds.init(event.getRegistry());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerEntitiesStatic(RegistryEvent.Register<EntityEntry> event) {
|
||||
UEntities.init(event.getRegistry());
|
||||
|
@ -133,7 +141,7 @@ public class Unicopia {
|
|||
public static void onGameTick(TickEvent.ClientTickEvent event) {
|
||||
Race newRace = getclientPlayerRace();
|
||||
|
||||
if (newRace != clientPlayerRace) {
|
||||
if (newRace != clientPlayerRace && Minecraft.getMinecraft().player != null) {
|
||||
clientPlayerRace = newRace;
|
||||
|
||||
channel.send(new MsgRequestCapabilities(Minecraft.getMinecraft().player, clientPlayerRace), Target.SERVER);
|
||||
|
@ -200,6 +208,23 @@ public class Unicopia {
|
|||
Commands.init(event);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@SubscribeEvent
|
||||
public static void onRenderHud(RenderGameOverlayEvent.Post event) {
|
||||
if (event.getType() != ElementType.ALL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (UClient.isClientSide()) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
if (mc.player != null && mc.world != null) {
|
||||
IPlayer player = PlayerSpeciesList.instance().getPlayer(mc.player);
|
||||
|
||||
UHud.instance.renderHud(player, event.getResolution());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onPlayerRightClick(PlayerInteractEvent.RightClickItem event) {
|
||||
// Why won't you run!?
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
package com.minelittlepony.unicopia.hud;
|
||||
|
||||
import com.minelittlepony.unicopia.player.IPlayer;
|
||||
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
class FlightExperienceBar implements IHudElement {
|
||||
|
||||
static final ResourceLocation TEXTURE = new ResourceLocation("textures/gui/bars.png");
|
||||
|
||||
@Override
|
||||
public boolean shouldRender(IPlayer player) {
|
||||
return player.getPlayerSpecies().canFly()
|
||||
&& player.getGravity().isFlying();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderHud(UHud context) {
|
||||
float xp = context.player.getGravity().getFlightExperience();
|
||||
float length = context.player.getGravity().getFlightDuration();
|
||||
|
||||
context.mc.getTextureManager().bindTexture(TEXTURE);
|
||||
int x = (context.width - 184) / 2;
|
||||
int y = context.height - 29;
|
||||
|
||||
int xpFill = (int)Math.floor(xp * 184);
|
||||
int xpBuff = (int)Math.floor((184 - xpFill) * length);
|
||||
|
||||
Gui.drawModalRectWithCustomSizedTexture(x, y, 0, 0, 256, 5, 256, 256);
|
||||
Gui.drawModalRectWithCustomSizedTexture(x, y, 0, 5, xpFill, 5, 256, 256);
|
||||
|
||||
|
||||
Gui.drawModalRectWithCustomSizedTexture(x + xpFill, y, xpFill, 10, xpBuff, 5, 256, 256);
|
||||
|
||||
// context.fonts.drawStringWithShadow("Flight experience: " + context.player.getFlightExperience(), 0, 0, 0xFFFFFF);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package com.minelittlepony.unicopia.hud;
|
||||
|
||||
import com.minelittlepony.unicopia.player.IPlayer;
|
||||
|
||||
public interface IHudElement {
|
||||
void renderHud(UHud context);
|
||||
|
||||
boolean shouldRender(IPlayer player);
|
||||
}
|
63
src/main/java/com/minelittlepony/unicopia/hud/UHud.java
Normal file
63
src/main/java/com/minelittlepony/unicopia/hud/UHud.java
Normal file
|
@ -0,0 +1,63 @@
|
|||
package com.minelittlepony.unicopia.hud;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.minelittlepony.unicopia.player.IPlayer;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
|
||||
public class UHud extends Gui {
|
||||
|
||||
public static final UHud instance = new UHud();
|
||||
|
||||
private List<IHudElement> elements = new ArrayList<>();
|
||||
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
FontRenderer fonts = mc.fontRenderer;
|
||||
|
||||
IPlayer player;
|
||||
|
||||
int width;
|
||||
|
||||
int height;
|
||||
|
||||
private UHud() {
|
||||
elements.add(new FlightExperienceBar());
|
||||
}
|
||||
|
||||
public void renderHud(IPlayer player, ScaledResolution resolution) {
|
||||
this.width = resolution.getScaledWidth();
|
||||
this.height = resolution.getScaledHeight();
|
||||
this.player = player;
|
||||
|
||||
elements.forEach(this::renderElement);
|
||||
}
|
||||
|
||||
private void renderElement(IHudElement element) {
|
||||
if (!element.shouldRender(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.disableLighting();
|
||||
GlStateManager.color(1, 1, 1, 1);
|
||||
|
||||
element.renderHud(this);
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
|
||||
GL11.glPopAttrib();
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package com.minelittlepony.unicopia.player;
|
||||
|
||||
public interface IGravity {
|
||||
boolean isFlying();
|
||||
|
||||
float getFlightExperience();
|
||||
|
||||
float getFlightDuration();
|
||||
}
|
|
@ -15,6 +15,8 @@ public interface IPlayer extends ICaster<EntityPlayer>, IRaceContainer<EntityPla
|
|||
|
||||
IAbilityReceiver getAbilities();
|
||||
|
||||
IGravity getGravity();
|
||||
|
||||
float getExertion();
|
||||
|
||||
void setExertion(float exertion);
|
||||
|
|
|
@ -107,6 +107,11 @@ class PlayerCapabilities implements IPlayer, ICaster<EntityPlayer> {
|
|||
return powers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGravity getGravity() {
|
||||
return gravity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClientPlayer() {
|
||||
return UClient.isClientSide() &&
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.minelittlepony.unicopia.player;
|
||||
|
||||
import com.minelittlepony.unicopia.InbtSerialisable;
|
||||
import com.minelittlepony.unicopia.USounds;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.SoundType;
|
||||
|
@ -16,14 +17,14 @@ import net.minecraft.util.SoundEvent;
|
|||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
|
||||
class PlayerGravityDelegate implements IUpdatable<EntityPlayer>, InbtSerialisable {
|
||||
class PlayerGravityDelegate implements IUpdatable<EntityPlayer>, IGravity, InbtSerialisable {
|
||||
|
||||
private final IPlayer player;
|
||||
|
||||
private static final float MAXIMUM_FLIGHT_EXPERIENCE = 500;
|
||||
|
||||
private int ticksInAir = 0;
|
||||
private float flightExperience = 0;
|
||||
public int ticksInAir = 0;
|
||||
public float flightExperience = 0;
|
||||
|
||||
public boolean isFlying = false;
|
||||
|
||||
|
@ -53,8 +54,8 @@ class PlayerGravityDelegate implements IUpdatable<EntityPlayer>, InbtSerialisabl
|
|||
|
||||
entity.addExhaustion(exhaustion * (1 - flightExperience));
|
||||
|
||||
if (ticksInAir > 2000) {
|
||||
ticksInAir = 1;
|
||||
if (ticksInAir >= MAXIMUM_FLIGHT_EXPERIENCE) {
|
||||
ticksInAir = 0;
|
||||
addFlightExperience(entity);
|
||||
entity.playSound(SoundEvents.ENTITY_GUARDIAN_FLOP, 1, 1);
|
||||
}
|
||||
|
@ -64,8 +65,17 @@ class PlayerGravityDelegate implements IUpdatable<EntityPlayer>, InbtSerialisabl
|
|||
entity.motionX += - forward * MathHelper.sin(entity.rotationYaw * 0.017453292F);
|
||||
entity.motionY -= 0.05F - ((entity.motionX * entity.motionX) + (entity.motionZ + entity.motionZ)) / 100;
|
||||
entity.motionZ += forward * MathHelper.cos(entity.rotationYaw * 0.017453292F);
|
||||
|
||||
if (ticksInAir > 0 && ticksInAir % 12 == 0) {
|
||||
entity.playSound(USounds.WING_FLAP, 0.1F, 1);
|
||||
}
|
||||
} else {
|
||||
if (ticksInAir != 0) {
|
||||
entity.playSound(USounds.WING_FLAP, 0.04F, 1);
|
||||
}
|
||||
|
||||
ticksInAir = 0;
|
||||
flightExperience *= 0.9991342;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -144,4 +154,19 @@ class PlayerGravityDelegate implements IUpdatable<EntityPlayer>, InbtSerialisabl
|
|||
flightExperience = compound.getFloat("flightExperience");
|
||||
isFlying = compound.getBoolean("isFlying");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFlying() {
|
||||
return isFlying;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFlightExperience() {
|
||||
return flightExperience / MAXIMUM_FLIGHT_EXPERIENCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFlightDuration() {
|
||||
return ticksInAir / MAXIMUM_FLIGHT_EXPERIENCE;
|
||||
}
|
||||
}
|
||||
|
|
12
src/main/resources/assets/unicopia/sounds.json
Normal file
12
src/main/resources/assets/unicopia/sounds.json
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"wing_flap": {
|
||||
"category": "player",
|
||||
"subtitle": "unicopia.subtitle.flap_wings",
|
||||
"sounds": [
|
||||
"unicopia:wing/wing0",
|
||||
"unicopia:wing/wing1",
|
||||
"unicopia:wing/wing2",
|
||||
"unicopia:wing/wing3"
|
||||
]
|
||||
}
|
||||
}
|
BIN
src/main/resources/assets/unicopia/sounds/wing/dash1.ogg
Normal file
BIN
src/main/resources/assets/unicopia/sounds/wing/dash1.ogg
Normal file
Binary file not shown.
BIN
src/main/resources/assets/unicopia/sounds/wing/land1.ogg
Normal file
BIN
src/main/resources/assets/unicopia/sounds/wing/land1.ogg
Normal file
Binary file not shown.
BIN
src/main/resources/assets/unicopia/sounds/wing/wing0.ogg
Normal file
BIN
src/main/resources/assets/unicopia/sounds/wing/wing0.ogg
Normal file
Binary file not shown.
BIN
src/main/resources/assets/unicopia/sounds/wing/wing1.ogg
Normal file
BIN
src/main/resources/assets/unicopia/sounds/wing/wing1.ogg
Normal file
Binary file not shown.
BIN
src/main/resources/assets/unicopia/sounds/wing/wing2.ogg
Normal file
BIN
src/main/resources/assets/unicopia/sounds/wing/wing2.ogg
Normal file
Binary file not shown.
BIN
src/main/resources/assets/unicopia/sounds/wing/wing3.ogg
Normal file
BIN
src/main/resources/assets/unicopia/sounds/wing/wing3.ogg
Normal file
Binary file not shown.
Loading…
Reference in a new issue