Search in sources :

Example 41 with EntityPlayerMP

use of net.minecraft.entity.player.EntityPlayerMP in project minecolonies by Minecolonies.

the class Colony method removeCitizen.

/**
     * Removes a citizen from the colony.
     *
     * @param citizen Citizen data to remove.
     */
public void removeCitizen(@NotNull final CitizenData citizen) {
    //Remove the Citizen
    citizens.remove(citizen.getId());
    for (@NotNull final AbstractBuilding building : buildings.values()) {
        building.removeCitizen(citizen);
    }
    workManager.clearWorkForCitizen(citizen);
    //  Inform Subscribers of removed citizen
    for (final EntityPlayerMP player : subscribers) {
        MineColonies.getNetwork().sendTo(new ColonyViewRemoveCitizenMessage(this, citizen.getId()), player);
    }
}
Also used : EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) NotNull(org.jetbrains.annotations.NotNull)

Example 42 with EntityPlayerMP

use of net.minecraft.entity.player.EntityPlayerMP in project ArsMagica2 by Mithion.

the class SkillData method learn.

public void learn(int id, int type) {
    if (entity.worldObj.isRemote) {
        AMDataWriter writer = new AMDataWriter();
        writer.add(SPELL_LEARNED);
        writer.add(this.entity.getEntityId());
        writer.add(id);
        writer.add(type);
        AMNetHandler.INSTANCE.sendPacketToServer(AMPacketIDs.SYNC_SPELL_KNOWLEDGE, writer.generate());
        MinecraftForge.EVENT_BUS.post(new SkillLearnedEvent(player, SkillManager.instance.getSkill(id)));
    } else {
        SkillPointTypes skillType = SkillTreeManager.instance.getSkillPointTypeForPart(id);
        boolean learned = false;
        switch(type) {
            case 0:
                if (!isShapeKnown(id) && getSpellPoints(skillType) > 0) {
                    setShapeKnown(id);
                    decrementSpellPoints(skillType);
                    learned = true;
                }
                updateFlags |= KNOWN_SHAPE_UPDATE;
                break;
            case 1:
                if (!isComponentKnown(id) && getSpellPoints(skillType) > 0) {
                    setComponentKnown(id);
                    decrementSpellPoints(skillType);
                    learned = true;
                }
                updateFlags |= KNOWN_COMPONENT_UPDATE;
                break;
            case 2:
                if (!isModifierKnown(id) && getSpellPoints(skillType) > 0) {
                    setModifierKnown(id);
                    decrementSpellPoints(skillType);
                    learned = true;
                }
                updateFlags |= KNOWN_MODIFIER_UPDATE;
                break;
            case 3:
                if (!isTalentKnown(id) && getSpellPoints(skillType) > 0) {
                    setTalentKnown(id);
                    decrementSpellPoints(skillType);
                    learned = true;
                }
                updateFlags |= KNOWN_TALENTS_UPDATE;
                break;
        }
        if (entity instanceof EntityPlayerMP && learned && skillType == SkillPointTypes.SILVER) {
            AMNetHandler.INSTANCE.sendSilverSkillPointPacket((EntityPlayerMP) entity);
        }
    }
}
Also used : EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) SkillLearnedEvent(am2.api.events.SkillLearnedEvent) AMDataWriter(am2.network.AMDataWriter) SkillPointTypes(am2.api.spell.enums.SkillPointTypes)

Example 43 with EntityPlayerMP

use of net.minecraft.entity.player.EntityPlayerMP in project ArsMagica2 by Mithion.

the class ExtendedProperties method setEntityReference.

//=======================================================================================
// Utility Methods
//=======================================================================================
public void setEntityReference(EntityLivingBase entity) {
    this.entity = entity;
    setOriginalSize(new AMVector2(entity.width, entity.height));
    hasInitialized = true;
    isCritical = entity instanceof EntityPlayerMP;
    yOffsetOrig = entity.yOffset;
    if (isCritical)
        ticksToRegen = 5;
    else
        ticksToRegen = 20;
    if (isCritical) {
        if (armorProcCooldowns[3] > 0) {
            AMCore.instance.proxy.blackoutArmorPiece((EntityPlayerMP) entity, 3, armorProcCooldowns[3]);
        }
        if (armorProcCooldowns[1] > 0) {
            AMCore.instance.proxy.blackoutArmorPiece((EntityPlayerMP) entity, 1, armorProcCooldowns[1]);
        }
        if (armorProcCooldowns[2] > 0) {
            AMCore.instance.proxy.blackoutArmorPiece((EntityPlayerMP) entity, 2, armorProcCooldowns[2]);
        }
        if (armorProcCooldowns[0] > 0) {
            AMCore.instance.proxy.blackoutArmorPiece((EntityPlayerMP) entity, 0, armorProcCooldowns[0]);
        }
    }
    if (entity.worldObj != null && entity.worldObj.isRemote && entity instanceof EntityPlayer && AMCore.proxy.playerTracker.hasAA((EntityPlayer) entity)) {
        EntityLivingBase localPlayer = AMCore.instance.proxy.getLocalPlayer();
        if (entity != localPlayer)
            AMNetHandler.INSTANCE.requestAuras((EntityPlayer) entity);
    }
}
Also used : AMVector2(am2.api.math.AMVector2) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Example 44 with EntityPlayerMP

use of net.minecraft.entity.player.EntityPlayerMP in project BetterStorage by copygirl.

the class TileEntityPresent method onBlockActivated.

@Override
public boolean onBlockActivated(EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
    ItemStack holding = player.getCurrentEquippedItem();
    if (holding == null) {
        if (breakPause > 0)
            return false;
        breakPause = 10 - breakProgress / 10;
        if ((nameTag != null) && !player.getCommandSenderName().equalsIgnoreCase(nameTag)) {
            breakPause = 40;
            if (!worldObj.isRemote)
                ((EntityPlayerMP) player).addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "This present is for " + nameTag + ", not you!"));
            return false;
        }
        if ((breakProgress += 20) > 100)
            destroyed = true;
        if (worldObj.isRemote)
            return true;
        double x = xCoord + 0.5;
        double y = yCoord + 0.5;
        double z = zCoord + 0.5;
        String sound = Block.soundTypeCloth.getBreakSound();
        worldObj.playSoundEffect(x, y, z, sound, 0.75F, 0.8F + breakProgress / 80.0F);
        worldObj.playSoundEffect(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, sound, 1.0F, 0.4F + breakProgress / 160.0F);
        BetterStorage.networkChannel.sendToAllAround(new PacketPresentOpen(xCoord, yCoord, zCoord, destroyed), worldObj, x, y, z, 64);
        if (!destroyed)
            return true;
        if (BetterStorageTiles.cardboardBox != null) {
            if (worldObj.setBlock(xCoord, yCoord, zCoord, BetterStorageTiles.cardboardBox)) {
                TileEntityCardboardBox box = WorldUtils.get(worldObj, xCoord, yCoord, zCoord, TileEntityCardboardBox.class);
                box.uses = ItemCardboardBox.getUses();
                box.color = color;
                System.arraycopy(contents, 0, box.contents, 0, contents.length);
            } else
                for (ItemStack stack : contents) WorldUtils.dropStackFromBlock(worldObj, xCoord, yCoord, zCoord, stack);
        } else if (worldObj.setBlockToAir(xCoord, yCoord, zCoord))
            for (ItemStack stack : contents) WorldUtils.dropStackFromBlock(worldObj, xCoord, yCoord, zCoord, stack);
        return true;
    } else if ((holding.getItem() == Items.name_tag) && (nameTag == null) && holding.hasDisplayName()) {
        if (holding.getDisplayName().matches("^[a-zA-Z0-9_]{2,16}$")) {
            if (!worldObj.isRemote) {
                nameTag = holding.getDisplayName();
                holding.stackSize--;
                markForUpdate();
            }
            return true;
        } else {
            if (!worldObj.isRemote)
                ((EntityPlayerMP) player).addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "The nametag doesn't seem to contain a valid username."));
            return false;
        }
    } else
        return false;
}
Also used : PacketPresentOpen(net.mcft.copy.betterstorage.network.packet.PacketPresentOpen) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 45 with EntityPlayerMP

use of net.minecraft.entity.player.EntityPlayerMP in project ArsMagica2 by Mithion.

the class BlockLectern method onBlockActivated.

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) {
    super.onBlockActivated(world, x, y, z, player, par6, par7, par8, par9);
    TileEntityLectern te = getTileEntity(world, x, y, z);
    if (te == null) {
        return true;
    }
    if (te.hasStack()) {
        if (player.isSneaking()) {
            if (!world.isRemote && ((player instanceof EntityPlayerMP) && ((EntityPlayerMP) player).theItemInWorldManager.getGameType() != GameType.ADVENTURE)) {
                float f = world.rand.nextFloat() * 0.8F + 0.1F;
                float f1 = world.rand.nextFloat() * 0.8F + 0.1F;
                float f2 = world.rand.nextFloat() * 0.8F + 0.1F;
                ItemStack newItem = new ItemStack(te.getStack().getItem(), 1, te.getStack().getItemDamage());
                if (te.getStack().stackTagCompound != null)
                    newItem.setTagCompound((NBTTagCompound) te.getStack().stackTagCompound.copy());
                EntityItem entityitem = new EntityItem(world, x + f, y + f1, z + f2, newItem);
                float f3 = 0.05F;
                entityitem.motionX = (float) world.rand.nextGaussian() * f3;
                entityitem.motionY = (float) world.rand.nextGaussian() * f3 + 0.2F;
                entityitem.motionZ = (float) world.rand.nextGaussian() * f3;
                world.spawnEntityInWorld(entityitem);
                te.setStack(null);
            }
        } else {
            te.getStack().getItem().onItemRightClick(te.getStack(), world, player);
        }
    } else {
        if (player.getCurrentEquippedItem() != null) {
            if (te.setStack(player.getCurrentEquippedItem())) {
                player.getCurrentEquippedItem().stackSize--;
                if (player.getCurrentEquippedItem().stackSize <= 0) {
                    player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
                }
            }
        }
    }
    return true;
}
Also used : TileEntityLectern(am2.blocks.tileentities.TileEntityLectern) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)163 EntityPlayer (net.minecraft.entity.player.EntityPlayer)32 ItemStack (net.minecraft.item.ItemStack)23 TileEntity (net.minecraft.tileentity.TileEntity)18 Entity (net.minecraft.entity.Entity)17 EntityLivingBase (net.minecraft.entity.EntityLivingBase)15 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)15 ChatComponentTranslation (net.minecraft.util.ChatComponentTranslation)14 BlockPos (net.minecraft.util.math.BlockPos)14 Block (net.minecraft.block.Block)11 IBlockState (net.minecraft.block.state.IBlockState)8 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)8 World (net.minecraft.world.World)8 WrongUsageException (net.minecraft.command.WrongUsageException)7 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)7 NetHandlerPlayServer (net.minecraft.network.NetHandlerPlayServer)7 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)6 TrainPacket (club.nsdn.nyasamarailway.network.TrainPacket)5 TileEntityReceiver (club.nsdn.nyasamatelecom.api.tileentity.TileEntityReceiver)5 GenericStructure (ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)5