use of com.lying.variousoddities.capabilities.Abilities in project VariousOddities by Lyinginbedmon.
the class VOBusClient method onLivingJump.
@SubscribeEvent
public static void onLivingJump(LivingUpdateEvent event) {
if (event.getEntityLiving() == mc.player) {
ClientPlayerEntity player = (ClientPlayerEntity) event.getEntityLiving();
LivingData data = LivingData.forEntity(event.getEntityLiving());
Abilities abilities = data.getAbilities();
Map<ResourceLocation, Ability> abilityMap = AbilityRegistry.getCreatureAbilities(player);
if (player.movementInput.jump && abilities.canBonusJump) {
if (AbilitySwim.isEntitySwimming(player)) {
if (abilityMap.containsKey(AbilitySwim.REGISTRY_NAME)) {
abilities.doWaterJump();
PacketHandler.sendToServer(new PacketBonusJump(false));
}
} else if (!player.isOnGround()) {
if (abilityMap.containsKey(AbilityFlight.REGISTRY_NAME) && abilityMap.get(AbilityFlight.REGISTRY_NAME).isActive()) {
abilities.doAirJump();
player.connection.sendPacket(new CEntityActionPacket(player, CEntityActionPacket.Action.START_FALL_FLYING));
PacketHandler.sendToServer(new PacketBonusJump());
}
}
}
}
}
use of com.lying.variousoddities.capabilities.Abilities in project VariousOddities by Lyinginbedmon.
the class AbilityStartingItem method onSpeciesSelected.
public void onSpeciesSelected(SpeciesEvent.SpeciesSelected event) {
PlayerEntity player = (PlayerEntity) event.getEntityLiving();
if (player.getEntityWorld().isRemote)
return;
Abilities abilities = LivingData.forEntity(player).getAbilities();
for (Ability ability : abilities.getEntityAbilities(player).values()) if (ability.getRegistryName().equals(REGISTRY_NAME))
addItemsFromAbility((AbilityStartingItem) ability, player);
}
use of com.lying.variousoddities.capabilities.Abilities in project VariousOddities by Lyinginbedmon.
the class GuiHandler method drawFavouritedAbilities.
private static void drawFavouritedAbilities(MatrixStack matrix, MainWindow window, float partialTicks, EnumCorner corner) {
profiler.startSection("abilities");
Map<ResourceLocation, Ability> abilityMap = AbilityRegistry.getCreatureAbilities(player);
Abilities abilities = LivingData.forEntity(player).getAbilities();
float posXStart = 5F;
float posYStart = 5F;
float posXInc = 3F;
float posYInc = 11F;
switch(corner) {
case TOP_LEFT:
posXStart = (Abilities.FAVOURITE_SLOTS * 3F);
break;
case BOTTOM_LEFT:
posXInc = -3F;
posYStart = (float) (window.getScaledHeight() - (Abilities.FAVOURITE_SLOTS * posYInc) - 5F);
break;
case BOTTOM_RIGHT:
posXStart = (float) (window.getScaledWidth() - (Abilities.FAVOURITE_SLOTS * 3F));
posYStart = (float) (window.getScaledHeight() - (Abilities.FAVOURITE_SLOTS * posYInc) - 5F);
break;
case TOP_RIGHT:
posXStart = (float) (window.getScaledWidth() - (Abilities.FAVOURITE_SLOTS * 3F) - ICON_SIZE);
posXInc = -3F;
break;
}
matrix.push();
float posX = posXStart;
float posY = posYStart;
int maxFav = 0;
for (int i = 0; i < Abilities.FAVOURITE_SLOTS; i++) {
ResourceLocation mapName = abilities.getFavourite(i);
if (mapName != null) {
maxFav = Math.max(maxFav, i);
ActivatedAbility ability = (ActivatedAbility) abilityMap.get(mapName);
if (ability != null)
drawAbility(ability, abilities.getCooldown(mapName), posX, posY, matrix, corner.textSide);
}
posX -= posXInc;
posY += posYInc;
}
List<Ability> activatedAbilities = Lists.newArrayList();
activatedAbilities.addAll(abilityMap.values());
activatedAbilities.removeIf(new Predicate<Ability>() {
public boolean apply(Ability input) {
return input.passive();
}
});
if (!activatedAbilities.isEmpty()) {
// Draw either as many slots as you can fill OR up to the highest index of slots in use
int slots = Math.max(maxFav, activatedAbilities.size());
posX = posXStart;
posY = posYStart;
for (int i = 0; i < Math.min(Abilities.FAVOURITE_SLOTS, slots); i++) {
drawAbilitySlot(matrix, posX, posY);
posX -= posXInc;
posY += posYInc;
}
}
matrix.pop();
profiler.endSection();
}
use of com.lying.variousoddities.capabilities.Abilities in project VariousOddities by Lyinginbedmon.
the class PacketSyncAbilities method handle.
public static void handle(PacketSyncAbilities msg, Supplier<NetworkEvent.Context> cxt) {
NetworkEvent.Context context = cxt.get();
if (context.getDirection().getReceptionSide().isClient()) {
PlayerEntity player = ((CommonProxy) VariousOddities.proxy).getPlayerEntity(context);
if (player != null) {
World world = player.getEntityWorld();
if (world != null) {
LivingEntity entity = null;
for (LivingEntity living : world.getEntitiesWithinAABB(LivingEntity.class, Minecraft.getInstance().player.getBoundingBox().grow(64D))) if (living.getUniqueID().equals(msg.uuid)) {
entity = living;
break;
}
if (entity != null) {
LivingData data = LivingData.forEntity(entity);
data.getAbilities().deserializeNBT(msg.abilitiesData);
}
}
}
} else {
ServerPlayerEntity sender = context.getSender();
if (sender != null) {
Abilities abilities = LivingData.forEntity(sender).getAbilities();
abilities.forceRecache();
CompoundNBT data = abilities.serializeNBT();
PacketHandler.sendToNearby(sender.getEntityWorld(), sender, new PacketSyncAbilities(sender.getUniqueID(), data));
}
}
context.setPacketHandled(true);
}
use of com.lying.variousoddities.capabilities.Abilities in project VariousOddities by Lyinginbedmon.
the class PlayerEntityMixin method startElytraFlying.
@Inject(method = "tryToStartFallFlying()Z", at = @At("HEAD"), cancellable = true)
public void startElytraFlying(final CallbackInfoReturnable<Boolean> ci) {
PlayerEntity player = (PlayerEntity) (Object) this;
Abilities abilities = LivingData.forEntity(player).getAbilities();
Map<ResourceLocation, Ability> abilityMap = AbilityRegistry.getCreatureAbilities(player);
if (abilityMap.containsKey(AbilityFlight.REGISTRY_NAME) && abilityMap.get(AbilityFlight.REGISTRY_NAME).isActive()) {
if (!player.isOnGround() && !player.isElytraFlying() && abilities.canBonusJump) {
player.startFallFlying();
ci.setReturnValue(true);
}
}
}
Aggregations