Added the ability for flying placers to carry other entities

This commit is contained in:
Sollace 2018-09-20 16:28:17 +02:00
parent f7c462ac7e
commit 495e170bbe
9 changed files with 144 additions and 23 deletions

View file

@ -69,20 +69,11 @@ public class Unicopia {
channel.send(new MsgRequestCapabilities(Minecraft.getMinecraft().player), Target.SERVER);
})
// client ------> server
.consume(MsgRequestCapabilities.class, (msg, channel) -> {
})
.consume(MsgRequestCapabilities.class)
// client <------ server
.consume(MsgPlayerCapabilities.class, (msg, channel) -> {
System.out.println("[CLIENT] Got capabilities for player I am "
+ Minecraft.getMinecraft().player.getGameProfile().getId());
})
.consume(MsgPlayerCapabilities.class)
// client ------> server
.consume(MsgPlayerAbility.class, (msg, channel) -> {
});
.consume(MsgPlayerAbility.class);
MAGIC_PARTICLE = Particles.instance().registerParticle(new EntityMagicFX.Factory());
RAIN_PARTICLE = Particles.instance().registerParticle(new EntityRaindropFX.Factory());
@ -125,9 +116,9 @@ public class Unicopia {
@SubscribeEvent
public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
if (event.phase == Phase.END) {
PlayerSpeciesList.instance()
.getPlayer(event.player)
.onUpdate(event.player);
PlayerSpeciesList.instance().getPlayer(event.player).onUpdate(event.player);
} else {
PlayerSpeciesList.instance().getPlayer(event.player).beforeUpdate(event.player);
}
}

View file

@ -57,9 +57,22 @@ public class MsgPlayerCapabilities implements IMessage, IMessageHandler<MsgPlaye
@Override
public void onPayload(MsgPlayerCapabilities message, IChannel channel) {
System.out.println("[CLIENT] Got capabilities for player id " + senderId + " I am "
+ Minecraft.getMinecraft().player.getGameProfile().getId());
IPlayer player = PlayerSpeciesList.instance().getPlayer(Minecraft.getMinecraft().player);
EntityPlayer self = Minecraft.getMinecraft().player;
UUID myid = self.getGameProfile().getId();
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) {
try (ByteArrayInputStream input = new ByteArrayInputStream(compoundTag)) {

View file

@ -32,6 +32,8 @@ public interface IPlayer extends ICaster<EntityPlayer>, IRaceContainer<EntityPla
void onFall(float distance, float damageMultiplier);
void beforeUpdate(EntityPlayer entity);
static EntityPlayer getPlayerEntity(UUID playerId) {
EntityPlayer player = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUUID(playerId);

View file

@ -14,12 +14,15 @@ import com.minelittlepony.unicopia.spell.IMagicEffect;
import com.minelittlepony.unicopia.spell.SpellRegistry;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.MobEffects;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.network.play.server.SPacketSetPassengers;
import net.minecraft.potion.PotionEffect;
import net.minecraft.stats.StatList;
@ -112,6 +115,22 @@ class PlayerCapabilities implements IPlayer, ICaster<EntityPlayer> {
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
public void onUpdate(EntityPlayer entity) {
powers.onUpdate(entity);

View file

@ -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) {
}
}

View file

@ -25,10 +25,6 @@ public class PowerMagic implements IPower<PowerMagic.Magic> {
@Override
public int getWarmupTime(IPlayer player) {
// if (player.hasEffect() && "shield".contentEquals(player.getEffect().getName())) {
// return 0;
// }
return 20;
}

View file

@ -13,8 +13,11 @@ import net.minecraft.block.BlockFence;
import net.minecraft.block.BlockLeaves;
import net.minecraft.block.BlockWall;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.SoundEvents;
import net.minecraft.network.play.server.SPacketSetPassengers;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.SoundCategory;
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);
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)));
IPower.takeFromPlayer(player, distance);

View file

@ -30,6 +30,7 @@ public class PowersRegistry {
registerPower(new PowerStomp());
registerPower(new PowerGrow());
registerPower(new PowerFeed());
registerPower(new PowerCarry());
}
public boolean hasRegisteredPower(int keyCode) {

View file

@ -103,6 +103,7 @@ unicopia.power.magic=Secondary Unicorn ability
unicopia.power.rain=Primary Pegasus ability
unicopia.power.thunder=Secondary Pegasus ability
unicopia.power.carry=Pick up & Drop riders
unicopia.power.feed=Primary Changeling ability
unicopia.power.disguise=Secondary Changeling ability