Search in sources :

Example 1 with LivingArmourUpgradeElytra

use of WayofTime.bloodmagic.livingArmour.upgrade.LivingArmourUpgradeElytra in project BloodMagic by WayofTime.

the class ItemLivingArmour method onArmorTick.

@Override
public void onArmorTick(World world, EntityPlayer player, ItemStack stack) {
    super.onArmorTick(world, player, stack);
    if (world.isRemote && this == RegistrarBloodMagicItems.LIVING_ARMOUR_CHEST) {
        if (// Sanity check
        player instanceof EntityPlayerSP) {
            EntityPlayerSP spPlayer = (EntityPlayerSP) player;
            if (FLAGS == null) {
                try {
                    FLAGS = (DataParameter<Byte>) _FLAGS.get(null);
                } catch (IllegalArgumentException | IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
            if (FLAGS != null) {
                if (LivingArmour.hasFullSet(player)) {
                    ItemStack chestStack = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
                    LivingArmourUpgrade upgrade = ItemLivingArmour.getUpgradeFromNBT(BloodMagic.MODID + ".upgrade.elytra", chestStack);
                    if (upgrade instanceof LivingArmourUpgradeElytra) {
                        if (spPlayer.movementInput.jump && !spPlayer.onGround && spPlayer.motionY < 0.0D && !spPlayer.capabilities.isFlying) {
                            if (spPlayer.motionY > -0.5D) {
                                BloodMagicPacketHandler.INSTANCE.sendToServer(new PlayerFallDistancePacketProcessor(1));
                            }
                            if (!spPlayer.isElytraFlying()) {
                                byte b0 = player.getDataManager().get(FLAGS);
                                player.getDataManager().set(FLAGS, (byte) (b0 | 1 << 7));
                            }
                        } else if (spPlayer.isElytraFlying() && !spPlayer.movementInput.jump && !spPlayer.onGround) {
                            byte b0 = player.getDataManager().get(FLAGS);
                            player.getDataManager().set(FLAGS, (byte) (b0 & ~(1 << 7)));
                        }
                    }
                }
            }
        }
    }
    if (this == RegistrarBloodMagicItems.LIVING_ARMOUR_CHEST) {
        if (!hasLivingArmour(stack)) {
            setLivingArmour(stack, getLivingArmourFromStack(stack));
        }
        LivingArmour armour = getLivingArmour(stack);
        if (LivingArmour.hasFullSet(player)) {
            this.setIsEnabled(stack, true);
            armour.onTick(world, player);
        }
        setLivingArmour(stack, armour, false);
    }
}
Also used : LivingArmour(WayofTime.bloodmagic.livingArmour.LivingArmour) LivingArmourUpgrade(WayofTime.bloodmagic.livingArmour.LivingArmourUpgrade) LivingArmourUpgradeElytra(WayofTime.bloodmagic.livingArmour.upgrade.LivingArmourUpgradeElytra) PlayerFallDistancePacketProcessor(WayofTime.bloodmagic.network.PlayerFallDistancePacketProcessor) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) ItemStack(net.minecraft.item.ItemStack)

Aggregations

LivingArmour (WayofTime.bloodmagic.livingArmour.LivingArmour)1 LivingArmourUpgrade (WayofTime.bloodmagic.livingArmour.LivingArmourUpgrade)1 LivingArmourUpgradeElytra (WayofTime.bloodmagic.livingArmour.upgrade.LivingArmourUpgradeElytra)1 PlayerFallDistancePacketProcessor (WayofTime.bloodmagic.network.PlayerFallDistancePacketProcessor)1 EntityPlayerSP (net.minecraft.client.entity.EntityPlayerSP)1 ItemStack (net.minecraft.item.ItemStack)1