mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-30 16:28:00 +01:00
Added the ability for flying placers to carry other entities
This commit is contained in:
parent
f7c462ac7e
commit
495e170bbe
9 changed files with 144 additions and 23 deletions
|
@ -69,20 +69,11 @@ public class Unicopia {
|
||||||
channel.send(new MsgRequestCapabilities(Minecraft.getMinecraft().player), Target.SERVER);
|
channel.send(new MsgRequestCapabilities(Minecraft.getMinecraft().player), Target.SERVER);
|
||||||
})
|
})
|
||||||
// client ------> server
|
// client ------> server
|
||||||
.consume(MsgRequestCapabilities.class, (msg, channel) -> {
|
.consume(MsgRequestCapabilities.class)
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
// client <------ server
|
// client <------ server
|
||||||
.consume(MsgPlayerCapabilities.class, (msg, channel) -> {
|
.consume(MsgPlayerCapabilities.class)
|
||||||
System.out.println("[CLIENT] Got capabilities for player I am "
|
|
||||||
+ Minecraft.getMinecraft().player.getGameProfile().getId());
|
|
||||||
})
|
|
||||||
|
|
||||||
// client ------> server
|
// client ------> server
|
||||||
.consume(MsgPlayerAbility.class, (msg, channel) -> {
|
.consume(MsgPlayerAbility.class);
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
MAGIC_PARTICLE = Particles.instance().registerParticle(new EntityMagicFX.Factory());
|
MAGIC_PARTICLE = Particles.instance().registerParticle(new EntityMagicFX.Factory());
|
||||||
RAIN_PARTICLE = Particles.instance().registerParticle(new EntityRaindropFX.Factory());
|
RAIN_PARTICLE = Particles.instance().registerParticle(new EntityRaindropFX.Factory());
|
||||||
|
@ -125,9 +116,9 @@ public class Unicopia {
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
|
public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
|
||||||
if (event.phase == Phase.END) {
|
if (event.phase == Phase.END) {
|
||||||
PlayerSpeciesList.instance()
|
PlayerSpeciesList.instance().getPlayer(event.player).onUpdate(event.player);
|
||||||
.getPlayer(event.player)
|
} else {
|
||||||
.onUpdate(event.player);
|
PlayerSpeciesList.instance().getPlayer(event.player).beforeUpdate(event.player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,9 +57,22 @@ public class MsgPlayerCapabilities implements IMessage, IMessageHandler<MsgPlaye
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPayload(MsgPlayerCapabilities message, IChannel channel) {
|
public void onPayload(MsgPlayerCapabilities message, IChannel channel) {
|
||||||
System.out.println("[CLIENT] Got capabilities for player id " + senderId + " I am "
|
EntityPlayer self = Minecraft.getMinecraft().player;
|
||||||
+ Minecraft.getMinecraft().player.getGameProfile().getId());
|
UUID myid = self.getGameProfile().getId();
|
||||||
IPlayer player = PlayerSpeciesList.instance().getPlayer(Minecraft.getMinecraft().player);
|
|
||||||
|
IPlayer player;
|
||||||
|
if (senderId.equals(myid)) {
|
||||||
|
player = PlayerSpeciesList.instance().getPlayer(self);
|
||||||
|
} else {
|
||||||
|
EntityPlayer found = Minecraft.getMinecraft().world.getPlayerEntityByUUID(senderId);
|
||||||
|
|
||||||
|
if (found == null) {
|
||||||
|
System.out.println("Player with id " + senderId + " was not found!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
player = PlayerSpeciesList.instance().getPlayer(found);
|
||||||
|
}
|
||||||
|
|
||||||
if (compoundTag.length > 0) {
|
if (compoundTag.length > 0) {
|
||||||
try (ByteArrayInputStream input = new ByteArrayInputStream(compoundTag)) {
|
try (ByteArrayInputStream input = new ByteArrayInputStream(compoundTag)) {
|
||||||
|
|
|
@ -32,6 +32,8 @@ public interface IPlayer extends ICaster<EntityPlayer>, IRaceContainer<EntityPla
|
||||||
|
|
||||||
void onFall(float distance, float damageMultiplier);
|
void onFall(float distance, float damageMultiplier);
|
||||||
|
|
||||||
|
void beforeUpdate(EntityPlayer entity);
|
||||||
|
|
||||||
static EntityPlayer getPlayerEntity(UUID playerId) {
|
static EntityPlayer getPlayerEntity(UUID playerId) {
|
||||||
EntityPlayer player = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUUID(playerId);
|
EntityPlayer player = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUUID(playerId);
|
||||||
|
|
||||||
|
|
|
@ -14,12 +14,15 @@ import com.minelittlepony.unicopia.spell.IMagicEffect;
|
||||||
import com.minelittlepony.unicopia.spell.SpellRegistry;
|
import com.minelittlepony.unicopia.spell.SpellRegistry;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
import net.minecraft.init.MobEffects;
|
import net.minecraft.init.MobEffects;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.network.datasync.DataParameter;
|
import net.minecraft.network.datasync.DataParameter;
|
||||||
import net.minecraft.network.datasync.DataSerializers;
|
import net.minecraft.network.datasync.DataSerializers;
|
||||||
import net.minecraft.network.datasync.EntityDataManager;
|
import net.minecraft.network.datasync.EntityDataManager;
|
||||||
|
import net.minecraft.network.play.server.SPacketSetPassengers;
|
||||||
import net.minecraft.potion.PotionEffect;
|
import net.minecraft.potion.PotionEffect;
|
||||||
import net.minecraft.stats.StatList;
|
import net.minecraft.stats.StatList;
|
||||||
|
|
||||||
|
@ -112,6 +115,22 @@ class PlayerCapabilities implements IPlayer, ICaster<EntityPlayer> {
|
||||||
Minecraft.getMinecraft().player.getGameProfile().getId().equals(getOwner().getGameProfile().getId());
|
Minecraft.getMinecraft().player.getGameProfile().getId().equals(getOwner().getGameProfile().getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void beforeUpdate(EntityPlayer entity) {
|
||||||
|
if (entity.world.isRemote) {
|
||||||
|
if (entity.isRiding() && entity.isSneaking()) {
|
||||||
|
|
||||||
|
Entity ridee = entity.getRidingEntity();
|
||||||
|
|
||||||
|
entity.dismountRidingEntity();
|
||||||
|
|
||||||
|
if (ridee instanceof EntityPlayerMP) {
|
||||||
|
((EntityPlayerMP)ridee).getServerWorld().getEntityTracker().sendToTrackingAndSelf(ridee, new SPacketSetPassengers(ridee));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdate(EntityPlayer entity) {
|
public void onUpdate(EntityPlayer entity) {
|
||||||
powers.onUpdate(entity);
|
powers.onUpdate(entity);
|
||||||
|
|
|
@ -0,0 +1,86 @@
|
||||||
|
package com.minelittlepony.unicopia.power;
|
||||||
|
|
||||||
|
import org.lwjgl.input.Keyboard;
|
||||||
|
|
||||||
|
import com.minelittlepony.unicopia.Race;
|
||||||
|
import com.minelittlepony.unicopia.player.IPlayer;
|
||||||
|
import com.minelittlepony.unicopia.power.data.Hit;
|
||||||
|
import com.minelittlepony.util.vector.VecHelper;
|
||||||
|
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
|
import net.minecraft.network.play.server.SPacketSetPassengers;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
public class PowerCarry implements IPower<Hit> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getKeyName() {
|
||||||
|
return "unicopia.power.carry";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getKeyCode() {
|
||||||
|
return Keyboard.KEY_K;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getWarmupTime(IPlayer player) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCooldownTime(IPlayer player) {
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canUse(Race playerSpecies) {
|
||||||
|
return playerSpecies.canFly();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Hit tryActivate(EntityPlayer player, World w) {
|
||||||
|
return new Hit();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected EntityLivingBase findRider(EntityPlayer player, World w) {
|
||||||
|
Entity hit = VecHelper.getLookedAtEntity(player, 10);
|
||||||
|
|
||||||
|
if (hit instanceof EntityLivingBase && !player.isRidingOrBeingRiddenBy(hit)) {
|
||||||
|
return (EntityLivingBase)hit;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<Hit> getPackageType() {
|
||||||
|
return Hit.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(EntityPlayer player, Hit data) {
|
||||||
|
EntityLivingBase rider = findRider(player, player.world);
|
||||||
|
|
||||||
|
if (rider != null) {
|
||||||
|
rider.startRiding(player, true);
|
||||||
|
} else {
|
||||||
|
player.removePassengers();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player instanceof EntityPlayerMP) {
|
||||||
|
((EntityPlayerMP)player).getServerWorld().getEntityTracker().sendToTrackingAndSelf(player, new SPacketSetPassengers(player));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void preApply(IPlayer player) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postApply(IPlayer player) {
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,10 +25,6 @@ public class PowerMagic implements IPower<PowerMagic.Magic> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getWarmupTime(IPlayer player) {
|
public int getWarmupTime(IPlayer player) {
|
||||||
// if (player.hasEffect() && "shield".contentEquals(player.getEffect().getName())) {
|
|
||||||
// return 0;
|
|
||||||
// }
|
|
||||||
|
|
||||||
return 20;
|
return 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,11 @@ import net.minecraft.block.BlockFence;
|
||||||
import net.minecraft.block.BlockLeaves;
|
import net.minecraft.block.BlockLeaves;
|
||||||
import net.minecraft.block.BlockWall;
|
import net.minecraft.block.BlockWall;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
import net.minecraft.init.SoundEvents;
|
import net.minecraft.init.SoundEvents;
|
||||||
|
import net.minecraft.network.play.server.SPacketSetPassengers;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.SoundCategory;
|
import net.minecraft.util.SoundCategory;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
@ -110,7 +113,16 @@ public class PowerTeleport implements IPower<Location> {
|
||||||
player.world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 1, 1);
|
player.world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 1, 1);
|
||||||
|
|
||||||
double distance = player.getDistance(data.x, data.y, data.z) / 10;
|
double distance = player.getDistance(data.x, data.y, data.z) / 10;
|
||||||
player.dismountRidingEntity();
|
|
||||||
|
if (player.isRiding()) {
|
||||||
|
Entity mount = player.getRidingEntity();
|
||||||
|
|
||||||
|
player.dismountRidingEntity();
|
||||||
|
|
||||||
|
if (mount instanceof EntityPlayerMP) {
|
||||||
|
((EntityPlayerMP)player).getServerWorld().getEntityTracker().sendToTrackingAndSelf(player, new SPacketSetPassengers(mount));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
player.setPositionAndUpdate(data.x + (player.posX - Math.floor(player.posX)), data.y, data.z + (player.posZ - Math.floor(player.posZ)));
|
player.setPositionAndUpdate(data.x + (player.posX - Math.floor(player.posX)), data.y, data.z + (player.posZ - Math.floor(player.posZ)));
|
||||||
IPower.takeFromPlayer(player, distance);
|
IPower.takeFromPlayer(player, distance);
|
||||||
|
|
|
@ -30,6 +30,7 @@ public class PowersRegistry {
|
||||||
registerPower(new PowerStomp());
|
registerPower(new PowerStomp());
|
||||||
registerPower(new PowerGrow());
|
registerPower(new PowerGrow());
|
||||||
registerPower(new PowerFeed());
|
registerPower(new PowerFeed());
|
||||||
|
registerPower(new PowerCarry());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasRegisteredPower(int keyCode) {
|
public boolean hasRegisteredPower(int keyCode) {
|
||||||
|
|
|
@ -103,6 +103,7 @@ unicopia.power.magic=Secondary Unicorn ability
|
||||||
|
|
||||||
unicopia.power.rain=Primary Pegasus ability
|
unicopia.power.rain=Primary Pegasus ability
|
||||||
unicopia.power.thunder=Secondary Pegasus ability
|
unicopia.power.thunder=Secondary Pegasus ability
|
||||||
|
unicopia.power.carry=Pick up & Drop riders
|
||||||
|
|
||||||
unicopia.power.feed=Primary Changeling ability
|
unicopia.power.feed=Primary Changeling ability
|
||||||
unicopia.power.disguise=Secondary Changeling ability
|
unicopia.power.disguise=Secondary Changeling ability
|
||||||
|
|
Loading…
Reference in a new issue