Search in sources :

Example 1 with IOrganizationXIII

use of uk.co.wehavecookies56.kk.common.capability.OrganizationXIIICapability.IOrganizationXIII in project Kingdom-Keys-Re-Coded by Wehavecookies56.

the class SummonOrgWeapon method process.

@Override
public void process(EntityPlayer player, Side side) {
    if (hand == EnumHand.MAIN_HAND)
        player.inventory.setInventorySlotContents(player.inventory.currentItem, stack);
    else
        player.inventory.offHandInventory.set(0, stack);
    player.world.playSound((EntityPlayer) null, player.getPosition(), ModSounds.summon, SoundCategory.MASTER, 1.0f, 1.0f);
    IOrganizationXIII ORG = player.getCapability(ModCapabilities.ORGANIZATION_XIII, null);
    ORG.setWeaponSummoned(hand, true);
    PacketDispatcher.sendToAllAround(new SpawnOrgWeaponParticles(player, ORG.getMember().ordinal()), player, 64.0D);
    PacketDispatcher.sendTo(new SyncOrgXIIIData(player.getCapability(ModCapabilities.ORGANIZATION_XIII, null)), (EntityPlayerMP) player);
}
Also used : SyncOrgXIIIData(uk.co.wehavecookies56.kk.common.network.packet.client.SyncOrgXIIIData) SpawnOrgWeaponParticles(uk.co.wehavecookies56.kk.common.network.packet.client.SpawnOrgWeaponParticles) IOrganizationXIII(uk.co.wehavecookies56.kk.common.capability.OrganizationXIIICapability.IOrganizationXIII)

Example 2 with IOrganizationXIII

use of uk.co.wehavecookies56.kk.common.capability.OrganizationXIIICapability.IOrganizationXIII in project Kingdom-Keys-Re-Coded by Wehavecookies56.

the class CapabilityEvents method onEntityConstructing.

@SubscribeEvent
public void onEntityConstructing(AttachCapabilitiesEvent<Entity> event) {
    if (event.getObject() instanceof EntityPlayer) {
        event.addCapability(new ResourceLocation(Reference.MODID, "IOrganizationXIII"), new ICapabilitySerializable<NBTTagCompound>() {

            OrganizationXIIICapability.IOrganizationXIII inst = ModCapabilities.ORGANIZATION_XIII.getDefaultInstance();

            @Override
            public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing) {
                return capability == ModCapabilities.ORGANIZATION_XIII;
            }

            @Override
            public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) {
                return capability == ModCapabilities.ORGANIZATION_XIII ? (T) inst : null;
            }

            @Override
            public NBTTagCompound serializeNBT() {
                return (NBTTagCompound) ModCapabilities.ORGANIZATION_XIII.getStorage().writeNBT(ModCapabilities.ORGANIZATION_XIII, inst, null);
            }

            @Override
            public void deserializeNBT(NBTTagCompound nbt) {
                ModCapabilities.ORGANIZATION_XIII.getStorage().readNBT(ModCapabilities.ORGANIZATION_XIII, inst, null, nbt);
            }
        });
        event.addCapability(new ResourceLocation(Reference.MODID, "IMunny"), new ICapabilitySerializable<NBTPrimitive>() {

            MunnyCapability.IMunny inst = ModCapabilities.MUNNY.getDefaultInstance();

            @Override
            public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
                return capability == ModCapabilities.MUNNY;
            }

            @SuppressWarnings("unchecked")
            @Override
            public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
                return capability == ModCapabilities.MUNNY ? (T) inst : null;
            }

            @Override
            public NBTPrimitive serializeNBT() {
                return (NBTPrimitive) ModCapabilities.MUNNY.getStorage().writeNBT(ModCapabilities.MUNNY, inst, null);
            }

            @Override
            public void deserializeNBT(NBTPrimitive nbt) {
                ModCapabilities.MUNNY.getStorage().readNBT(ModCapabilities.MUNNY, inst, null, nbt);
            }
        });
        event.addCapability(new ResourceLocation(Reference.MODID, "ICheatMode"), new ICapabilitySerializable<NBTPrimitive>() {

            CheatModeCapability.ICheatMode inst = ModCapabilities.CHEAT_MODE.getDefaultInstance();

            @Override
            public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
                return capability == ModCapabilities.CHEAT_MODE;
            }

            @SuppressWarnings("unchecked")
            @Override
            public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
                return capability == ModCapabilities.CHEAT_MODE ? (T) inst : null;
            }

            @Override
            public NBTPrimitive serializeNBT() {
                return (NBTPrimitive) ModCapabilities.CHEAT_MODE.getStorage().writeNBT(ModCapabilities.CHEAT_MODE, inst, null);
            }

            @Override
            public void deserializeNBT(NBTPrimitive nbt) {
                ModCapabilities.CHEAT_MODE.getStorage().readNBT(ModCapabilities.CHEAT_MODE, inst, null, nbt);
            }
        });
        event.addCapability(new ResourceLocation(Reference.MODID, "IPlayerStats"), new ICapabilitySerializable<NBTTagCompound>() {

            PlayerStatsCapability.IPlayerStats inst = ModCapabilities.PLAYER_STATS.getDefaultInstance();

            @Override
            public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
                return capability == ModCapabilities.PLAYER_STATS;
            }

            @SuppressWarnings("unchecked")
            @Override
            public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
                return capability == ModCapabilities.PLAYER_STATS ? (T) inst : null;
            }

            @Override
            public NBTTagCompound serializeNBT() {
                return (NBTTagCompound) ModCapabilities.PLAYER_STATS.getStorage().writeNBT(ModCapabilities.PLAYER_STATS, inst, null);
            }

            @Override
            public void deserializeNBT(NBTTagCompound nbt) {
                ModCapabilities.PLAYER_STATS.getStorage().readNBT(ModCapabilities.PLAYER_STATS, inst, null, nbt);
            }
        });
        event.addCapability(new ResourceLocation(Reference.MODID, "ISummonKeyblade"), new ICapabilitySerializable<NBTTagCompound>() {

            SummonKeybladeCapability.ISummonKeyblade inst = ModCapabilities.SUMMON_KEYBLADE.getDefaultInstance();

            @Override
            public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
                return capability == ModCapabilities.SUMMON_KEYBLADE;
            }

            @SuppressWarnings("unchecked")
            @Override
            public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
                return capability == ModCapabilities.SUMMON_KEYBLADE ? (T) inst : null;
            }

            @Override
            public NBTTagCompound serializeNBT() {
                return (NBTTagCompound) ModCapabilities.SUMMON_KEYBLADE.getStorage().writeNBT(ModCapabilities.SUMMON_KEYBLADE, inst, null);
            }

            @Override
            public void deserializeNBT(NBTTagCompound nbt) {
                ModCapabilities.SUMMON_KEYBLADE.getStorage().readNBT(ModCapabilities.SUMMON_KEYBLADE, inst, null, nbt);
            }
        });
        event.addCapability(new ResourceLocation(Reference.MODID, "IMagicState"), new ICapabilitySerializable<NBTTagCompound>() {

            MagicStateCapability.IMagicState inst = ModCapabilities.MAGIC_STATE.getDefaultInstance();

            @Override
            public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
                return capability == ModCapabilities.MAGIC_STATE;
            }

            @SuppressWarnings("unchecked")
            @Override
            public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
                return capability == ModCapabilities.MAGIC_STATE ? (T) inst : null;
            }

            @Override
            public NBTTagCompound serializeNBT() {
                return (NBTTagCompound) ModCapabilities.MAGIC_STATE.getStorage().writeNBT(ModCapabilities.MAGIC_STATE, inst, null);
            }

            @Override
            public void deserializeNBT(NBTTagCompound nbt) {
                ModCapabilities.MAGIC_STATE.getStorage().readNBT(ModCapabilities.MAGIC_STATE, inst, null, nbt);
            }
        });
        event.addCapability(new ResourceLocation(Reference.MODID, "IDriveState"), new ICapabilitySerializable<NBTTagCompound>() {

            DriveStateCapability.IDriveState inst = ModCapabilities.DRIVE_STATE.getDefaultInstance();

            @Override
            public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
                return capability == ModCapabilities.DRIVE_STATE;
            }

            @SuppressWarnings("unchecked")
            @Override
            public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
                return capability == ModCapabilities.DRIVE_STATE ? (T) inst : null;
            }

            @Override
            public NBTTagCompound serializeNBT() {
                return (NBTTagCompound) ModCapabilities.DRIVE_STATE.getStorage().writeNBT(ModCapabilities.DRIVE_STATE, inst, null);
            }

            @Override
            public void deserializeNBT(NBTTagCompound nbt) {
                ModCapabilities.DRIVE_STATE.getStorage().readNBT(ModCapabilities.DRIVE_STATE, inst, null, nbt);
            }
        });
        event.addCapability(new ResourceLocation(Reference.MODID, "IFirstTimeJoin"), new ICapabilitySerializable<NBTTagCompound>() {

            FirstTimeJoinCapability.IFirstTimeJoin inst = ModCapabilities.FIRST_TIME_JOIN.getDefaultInstance();

            @Override
            public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
                return capability == ModCapabilities.FIRST_TIME_JOIN;
            }

            @SuppressWarnings("unchecked")
            @Override
            public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
                return capability == ModCapabilities.FIRST_TIME_JOIN ? (T) inst : null;
            }

            @Override
            public NBTTagCompound serializeNBT() {
                return (NBTTagCompound) ModCapabilities.FIRST_TIME_JOIN.getStorage().writeNBT(ModCapabilities.FIRST_TIME_JOIN, inst, null);
            }

            @Override
            public void deserializeNBT(NBTTagCompound nbt) {
                ModCapabilities.FIRST_TIME_JOIN.getStorage().readNBT(ModCapabilities.FIRST_TIME_JOIN, inst, null, nbt);
            }
        });
        event.addCapability(new ResourceLocation(Reference.MODID, "ISynthesisRecipe"), new ICapabilitySerializable<NBTTagCompound>() {

            SynthesisRecipeCapability.ISynthesisRecipe inst = ModCapabilities.SYNTHESIS_RECIPES.getDefaultInstance();

            @Override
            public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
                return capability == ModCapabilities.SYNTHESIS_RECIPES;
            }

            @SuppressWarnings("unchecked")
            @Override
            public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
                return capability == ModCapabilities.SYNTHESIS_RECIPES ? (T) inst : null;
            }

            @Override
            public NBTTagCompound serializeNBT() {
                return (NBTTagCompound) ModCapabilities.SYNTHESIS_RECIPES.getStorage().writeNBT(ModCapabilities.SYNTHESIS_RECIPES, inst, null);
            }

            @Override
            public void deserializeNBT(NBTTagCompound nbt) {
                ModCapabilities.SYNTHESIS_RECIPES.getStorage().readNBT(ModCapabilities.SYNTHESIS_RECIPES, inst, null, nbt);
            }
        });
        event.addCapability(new ResourceLocation(Reference.MODID, "ISynthesisMaterial"), new ICapabilitySerializable<NBTTagCompound>() {

            SynthesisMaterialCapability.ISynthesisMaterial inst = ModCapabilities.SYNTHESIS_MATERIALS.getDefaultInstance();

            @Override
            public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
                return capability == ModCapabilities.SYNTHESIS_MATERIALS;
            }

            @SuppressWarnings("unchecked")
            @Override
            public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
                return capability == ModCapabilities.SYNTHESIS_MATERIALS ? (T) inst : null;
            }

            @Override
            public NBTTagCompound serializeNBT() {
                return (NBTTagCompound) ModCapabilities.SYNTHESIS_MATERIALS.getStorage().writeNBT(ModCapabilities.SYNTHESIS_MATERIALS, inst, null);
            }

            @Override
            public void deserializeNBT(NBTTagCompound nbt) {
                ModCapabilities.SYNTHESIS_MATERIALS.getStorage().readNBT(ModCapabilities.SYNTHESIS_MATERIALS, inst, null, nbt);
            }
        });
    }
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) SynthesisRecipeCapability(uk.co.wehavecookies56.kk.common.capability.SynthesisRecipeCapability) ResourceLocation(net.minecraft.util.ResourceLocation) DriveStateCapability(uk.co.wehavecookies56.kk.common.capability.DriveStateCapability) MunnyCapability(uk.co.wehavecookies56.kk.common.capability.MunnyCapability) MagicStateCapability(uk.co.wehavecookies56.kk.common.capability.MagicStateCapability) OrganizationXIIICapability(uk.co.wehavecookies56.kk.common.capability.OrganizationXIIICapability) NBTPrimitive(net.minecraft.nbt.NBTPrimitive) SynthesisMaterialCapability(uk.co.wehavecookies56.kk.common.capability.SynthesisMaterialCapability) SummonKeybladeCapability(uk.co.wehavecookies56.kk.common.capability.SummonKeybladeCapability) FirstTimeJoinCapability(uk.co.wehavecookies56.kk.common.capability.FirstTimeJoinCapability) PlayerStatsCapability(uk.co.wehavecookies56.kk.common.capability.PlayerStatsCapability) EntityPlayer(net.minecraft.entity.player.EntityPlayer) CheatModeCapability(uk.co.wehavecookies56.kk.common.capability.CheatModeCapability) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with IOrganizationXIII

use of uk.co.wehavecookies56.kk.common.capability.OrganizationXIIICapability.IOrganizationXIII in project Kingdom-Keys-Re-Coded by Wehavecookies56.

the class EntityEvents method onLivingDeathEvent.

@SubscribeEvent
public void onLivingDeathEvent(LivingDeathEvent event) {
    if (!event.getEntity().world.isRemote && event.getEntity() instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) event.getEntity();
        SummonKeybladeCapability.ISummonKeyblade SUMMON = player.getCapability(ModCapabilities.SUMMON_KEYBLADE, null);
        IOrganizationXIII ORG = player.getCapability(ModCapabilities.ORGANIZATION_XIII, null);
        if (SUMMON.getIsKeybladeSummoned(EnumHand.MAIN_HAND)) {
            if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) {
                PacketDispatcher.sendToServer(new DeSummonKeyblade());
                PacketDispatcher.sendTo(new SyncKeybladeData(SUMMON), (EntityPlayerMP) player);
            } else {
                SUMMON.setIsKeybladeSummoned(EnumHand.MAIN_HAND, false);
                if (event.getEntity().world.getGameRules().getBoolean("keepInventory")) {
                    for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
                        if (!ItemStack.areItemStacksEqual(player.inventory.getStackInSlot(i), ItemStack.EMPTY)) {
                            if (player.inventory.getStackInSlot(i).getItem() instanceof ItemRealKeyblade) {
                                player.inventory.setInventorySlotContents(i, ItemStack.EMPTY);
                            }
                        }
                    }
                }
            }
        } else if (ORG.summonedWeapon(EnumHand.MAIN_HAND)) {
            if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) {
                PacketDispatcher.sendToServer(new DeSummonOrgWeapon());
                PacketDispatcher.sendTo(new SyncOrgXIIIData(ORG), (EntityPlayerMP) player);
            } else {
                SUMMON.setIsKeybladeSummoned(EnumHand.MAIN_HAND, false);
                if (event.getEntity().world.getGameRules().getBoolean("keepInventory")) {
                    for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
                        if (!ItemStack.areItemStacksEqual(player.inventory.getStackInSlot(i), ItemStack.EMPTY)) {
                            if (player.inventory.getStackInSlot(i).getItem() instanceof IOrgWeapon) {
                                player.inventory.setInventorySlotContents(i, ItemStack.EMPTY);
                            }
                        }
                    }
                }
            }
        }
    }
    if (event.getEntity() instanceof EntityDragon) {
        WorldSavedDataKingdomKeys.get(DimensionManager.getWorld(DimensionType.OVERWORLD.getId())).setSpawnHeartless(true);
    }
    if (!event.getEntity().world.isRemote && event.getEntity() instanceof EntityMob)
        if (event.getSource().getTrueSource() instanceof EntityPlayer) {
            EntityPlayer player = (EntityPlayer) event.getSource().getTrueSource();
            EntityMob mob = (EntityMob) event.getEntity();
            player.getCapability(ModCapabilities.PLAYER_STATS, null).addExperience(player, (int) (mob.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).getAttributeValue() / 2));
            if (!player.getCapability(ModCapabilities.PLAYER_STATS, null).enderDragonDefeated()) {
                player.getCapability(ModCapabilities.DRIVE_STATE, null).setDriveGaugeLevel(player.getCapability(ModCapabilities.DRIVE_STATE, null).getDriveGaugeLevel() + 1);
                player.getCapability(ModCapabilities.DRIVE_STATE, null).setDP(player.getCapability(ModCapabilities.DRIVE_STATE, null).getMaxDP());
                PacketDispatcher.sendTo(new SyncDriveData(player.getCapability(ModCapabilities.DRIVE_STATE, null)), (EntityPlayerMP) player);
                TextComponentTranslation driMessage = new TextComponentTranslation(Strings.Chat_DriveBoost, new TextComponentTranslation("" + player.getCapability(ModCapabilities.DRIVE_STATE, null).getDriveGaugeLevel()));
                driMessage.getStyle().setColor(TextFormatting.GREEN);
                player.sendMessage(driMessage);
                player.getCapability(ModCapabilities.PLAYER_STATS, null).setEnderDragonDefeated(true);
            }
            if (event.getEntity() instanceof EntityDragon) {
                player.getCapability(ModCapabilities.PLAYER_STATS, null).addExperience(player, 2000);
            }
            if (event.getEntity() instanceof EntityWither) {
                player.getCapability(ModCapabilities.PLAYER_STATS, null).addExperience(player, 1500);
            }
            PacketDispatcher.sendTo(new SyncLevelData(player.getCapability(ModCapabilities.PLAYER_STATS, null)), (EntityPlayerMP) player);
        }
}
Also used : EntityDragon(net.minecraft.entity.boss.EntityDragon) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) SyncLevelData(uk.co.wehavecookies56.kk.common.network.packet.client.SyncLevelData) DeSummonKeyblade(uk.co.wehavecookies56.kk.common.network.packet.server.DeSummonKeyblade) SyncKeybladeData(uk.co.wehavecookies56.kk.common.network.packet.client.SyncKeybladeData) ItemRealKeyblade(uk.co.wehavecookies56.kk.common.item.base.ItemRealKeyblade) SyncOrgXIIIData(uk.co.wehavecookies56.kk.common.network.packet.client.SyncOrgXIIIData) EntityMob(net.minecraft.entity.monster.EntityMob) SummonKeybladeCapability(uk.co.wehavecookies56.kk.common.capability.SummonKeybladeCapability) SyncDriveData(uk.co.wehavecookies56.kk.common.network.packet.client.SyncDriveData) DeSummonOrgWeapon(uk.co.wehavecookies56.kk.common.network.packet.server.DeSummonOrgWeapon) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) EntityWither(net.minecraft.entity.boss.EntityWither) IOrgWeapon(uk.co.wehavecookies56.kk.common.item.org.IOrgWeapon) IOrganizationXIII(uk.co.wehavecookies56.kk.common.capability.OrganizationXIIICapability.IOrganizationXIII) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with IOrganizationXIII

use of uk.co.wehavecookies56.kk.common.capability.OrganizationXIIICapability.IOrganizationXIII in project Kingdom-Keys-Re-Coded by Wehavecookies56.

the class InputHandler method summonPortal.

private void summonPortal(EntityPlayer player, PortalCoords coords) {
    IOrganizationXIII orgXIII = player.getCapability(ModCapabilities.ORGANIZATION_XIII, null);
    RayTraceResult rtr = InputHandler.getMouseOverExtended(100);
    if (rtr != null) {
        if (rtr.typeOfHit == rtr.typeOfHit.BLOCK) {
            double distanceSq = player.getDistanceSq(rtr.getBlockPos());
            double reachSq = 100 * 100;
            if (reachSq >= distanceSq) {
                BlockPos pos = rtr.getBlockPos();
                BlockPos destination = new BlockPos(coords.getX(), coords.getY(), coords.getZ());
                PacketDispatcher.sendToServer(new OrgPortal(rtr.getBlockPos(), destination, coords.getDimID()));
                player.world.playSound((EntityPlayer) player, player.getPosition(), ModSounds.lockon, SoundCategory.MASTER, 1.0f, 1.0f);
            }
        }
    }
}
Also used : RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockPos(net.minecraft.util.math.BlockPos) EntityOrgPortal(uk.co.wehavecookies56.kk.common.entity.magic.EntityOrgPortal) OrgPortal(uk.co.wehavecookies56.kk.common.network.packet.server.OrgPortal) IOrganizationXIII(uk.co.wehavecookies56.kk.common.capability.OrganizationXIIICapability.IOrganizationXIII)

Aggregations

IOrganizationXIII (uk.co.wehavecookies56.kk.common.capability.OrganizationXIIICapability.IOrganizationXIII)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 SummonKeybladeCapability (uk.co.wehavecookies56.kk.common.capability.SummonKeybladeCapability)2 SyncOrgXIIIData (uk.co.wehavecookies56.kk.common.network.packet.client.SyncOrgXIIIData)2 EntityDragon (net.minecraft.entity.boss.EntityDragon)1 EntityWither (net.minecraft.entity.boss.EntityWither)1 EntityMob (net.minecraft.entity.monster.EntityMob)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 NBTPrimitive (net.minecraft.nbt.NBTPrimitive)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 EnumFacing (net.minecraft.util.EnumFacing)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 BlockPos (net.minecraft.util.math.BlockPos)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1 CheatModeCapability (uk.co.wehavecookies56.kk.common.capability.CheatModeCapability)1 DriveStateCapability (uk.co.wehavecookies56.kk.common.capability.DriveStateCapability)1 FirstTimeJoinCapability (uk.co.wehavecookies56.kk.common.capability.FirstTimeJoinCapability)1 MagicStateCapability (uk.co.wehavecookies56.kk.common.capability.MagicStateCapability)1