Search in sources :

Example 1 with IFirstTimeJoin

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

the class BlockSavePoint method updateState.

private void updateState(World world, BlockPos pos) {
    List list = world.getEntitiesWithinAABBExcludingEntity((Entity) null, new AxisAlignedBB(pos.add(0, 0, 0), pos.add(1, 1, 1)));
    if (!list.isEmpty())
        for (int i = 0; i < list.size(); i++) {
            Entity e = (Entity) list.get(i);
            if (e instanceof EntityPlayer) {
                EntityPlayer player = (EntityPlayer) e;
                IPlayerStats STATS = player.getCapability(ModCapabilities.PLAYER_STATS, null);
                // System.out.println(player.getBedLocation());
                // System.out.println(pos.getX());
                boolean samePos;
                BlockPos bedPos;
                if (player.getBedLocation() == null) {
                    IFirstTimeJoin originalPos = player.getCapability(ModCapabilities.FIRST_TIME_JOIN, null);
                    bedPos = new BlockPos(originalPos.getPosX(), originalPos.getPosY(), originalPos.getPosZ());
                } else {
                    bedPos = player.getBedLocation();
                }
                samePos = bedPos.getX() == pos.getX() && bedPos.getY() == pos.getY() && bedPos.getZ() == pos.getZ();
                if (player.isSneaking() && !samePos) {
                    player.setSpawnChunk(pos, true, 0);
                    player.setSpawnPoint(pos, true);
                    TextHelper.sendFormattedChatMessage("Spawn point saved!", TextFormatting.GREEN, player);
                    world.playSound((EntityPlayer) null, player.getPosition(), ModSounds.savespawn, SoundCategory.BLOCKS, 1.0f, 1.0f);
                }
                if (player.getHealth() < player.getMaxHealth() || STATS.getMP() < STATS.getMaxMP()) {
                    player.heal(1);
                    STATS.addMP(2);
                    if (player.getFoodStats().getFoodLevel() < 20)
                        player.getFoodStats().addStats(4, 0);
                    if (timeHealed + 1 <= (int) Minecraft.getSystemTime() / 1000) {
                        world.playSound((EntityPlayer) null, player.getPosition(), ModSounds.savepoint, SoundCategory.BLOCKS, 1.0f, 1.0f);
                        PacketDispatcher.sendToAllAround(new SpawnCureParticles(pos, true), player, 64.0D);
                    }
                    PacketDispatcher.sendTo(new SyncMagicData(player.getCapability(ModCapabilities.MAGIC_STATE, null), STATS), (EntityPlayerMP) player);
                }
            }
        }
    world.scheduleUpdate(new BlockPos(pos), this, this.tickRate(world));
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) SpawnCureParticles(uk.co.wehavecookies56.kk.common.network.packet.client.SpawnCureParticles) Entity(net.minecraft.entity.Entity) IFirstTimeJoin(uk.co.wehavecookies56.kk.common.capability.FirstTimeJoinCapability.IFirstTimeJoin) IPlayerStats(uk.co.wehavecookies56.kk.common.capability.PlayerStatsCapability.IPlayerStats) EntityPlayer(net.minecraft.entity.player.EntityPlayer) List(java.util.List) BlockPos(net.minecraft.util.math.BlockPos) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) SyncMagicData(uk.co.wehavecookies56.kk.common.network.packet.client.SyncMagicData)

Example 2 with IFirstTimeJoin

use of uk.co.wehavecookies56.kk.common.capability.FirstTimeJoinCapability.IFirstTimeJoin 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)

Aggregations

EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 List (java.util.List)1 Entity (net.minecraft.entity.Entity)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 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 BlockPos (net.minecraft.util.math.BlockPos)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)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 IFirstTimeJoin (uk.co.wehavecookies56.kk.common.capability.FirstTimeJoinCapability.IFirstTimeJoin)1 MagicStateCapability (uk.co.wehavecookies56.kk.common.capability.MagicStateCapability)1 MunnyCapability (uk.co.wehavecookies56.kk.common.capability.MunnyCapability)1 OrganizationXIIICapability (uk.co.wehavecookies56.kk.common.capability.OrganizationXIIICapability)1 PlayerStatsCapability (uk.co.wehavecookies56.kk.common.capability.PlayerStatsCapability)1 IPlayerStats (uk.co.wehavecookies56.kk.common.capability.PlayerStatsCapability.IPlayerStats)1