Search in sources :

Example 1 with EntityPlayerMP

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

the class ChristmasEventHandler method onPlayerDeath.

@SubscribeEvent
public void onPlayerDeath(LivingDeathEvent event) {
    if (!(event.entity instanceof EntityPlayerMP))
        return;
    EntityPlayer player = (EntityPlayer) event.entity;
    BetterChristmasProperties properties = EntityUtils.getProperties(player, BetterChristmasProperties.class);
    NBTTagCompound entityData = player.getEntityData();
    NBTTagCompound persistent = entityData.getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG);
    entityData.setTag(EntityPlayer.PERSISTED_NBT_TAG, persistent);
    NBTTagCompound propertiesCompound = new NBTTagCompound();
    properties.saveNBTData(propertiesCompound);
    persistent.setTag(BetterChristmasProperties.identifier, propertiesCompound);
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 2 with EntityPlayerMP

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

the class ItemBackpack method onPlaceBackpack.

/** Places an equipped backpack when the player right clicks
	 *  on the ground while sneaking and holding nothing. */
public static boolean onPlaceBackpack(EntityPlayer player, int x, int y, int z, int side) {
    if (player.getCurrentEquippedItem() != null || !player.isSneaking())
        return false;
    ItemStack backpack = ItemBackpack.getBackpack(player);
    if (backpack == null)
        return false;
    boolean success = false;
    if (!ItemBackpack.isBackpackOpen(player)) {
        // Try to place the backpack as if it was being held and used by the player.
        success = backpack.getItem().onItemUse(backpack, player, player.worldObj, x, y, z, side, 0, 0, 0);
        if (backpack.stackSize <= 0) {
            ItemBackpack.setBackpack(player, null, null);
            backpack = null;
        }
    }
    // Make sure the client has the same information as the server. It does not sync when backpackChestplate is disabled because there are no changes to the slot in that case.
    if (!player.worldObj.isRemote && success && player instanceof EntityPlayerMP && BetterStorage.globalConfig.getBoolean(GlobalConfig.backpackChestplate)) {
        ((EntityPlayerMP) player).playerNetServerHandler.sendPacket(new S2FPacketSetSlot(0, 6, backpack));
    }
    if (success)
        player.swingItem();
    return success;
}
Also used : S2FPacketSetSlot(net.minecraft.network.play.server.S2FPacketSetSlot) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack)

Example 3 with EntityPlayerMP

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

the class BackpackHandler method onEntityInteract.

@SubscribeEvent
public void onEntityInteract(EntityInteractEvent event) {
    if (event.entity.worldObj.isRemote || !(event.entity instanceof EntityPlayerMP) || !(event.target instanceof EntityLivingBase) || (((EntityPlayerMP) event.entity).playerNetServerHandler == null) || ((event.target instanceof EntityPlayer) && !BetterStorage.globalConfig.getBoolean(GlobalConfig.enableBackpackInteraction)))
        return;
    EntityPlayerMP player = (EntityPlayerMP) event.entity;
    EntityLivingBase target = (EntityLivingBase) event.target;
    if (ItemBackpack.openBackpack(player, target))
        player.swingItem();
}
Also used : EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 4 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 5 with EntityPlayerMP

use of net.minecraft.entity.player.EntityPlayerMP in project BluePower by Qmunity.

the class ContainerMachineBase method detectAndSendChanges.

/**
     * Looks for changes made in the container, sends them to every listener.
     */
@Override
public void detectAndSendChanges() {
    super.detectAndSendChanges();
    for (Object crafter : crafters) {
        ICrafting icrafting = (ICrafting) crafter;
        if (backlogSize != machine.getBacklog().size() && icrafting instanceof EntityPlayerMP) {
            BPNetworkHandler.INSTANCE.sendTo(new MessageSyncMachineBacklog(machine, machine.getBacklog()), (EntityPlayerMP) icrafting);
        }
    }
    backlogSize = machine.getBacklog().size();
}
Also used : ICrafting(net.minecraft.inventory.ICrafting) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) MessageSyncMachineBacklog(com.bluepowermod.network.message.MessageSyncMachineBacklog)

Aggregations

EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)124 EntityPlayer (net.minecraft.entity.player.EntityPlayer)20 Entity (net.minecraft.entity.Entity)15 ItemStack (net.minecraft.item.ItemStack)15 TileEntity (net.minecraft.tileentity.TileEntity)13 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)13 EntityLivingBase (net.minecraft.entity.EntityLivingBase)12 BlockPos (net.minecraft.util.math.BlockPos)9 WrongUsageException (net.minecraft.command.WrongUsageException)7 NetHandlerPlayServer (net.minecraft.network.NetHandlerPlayServer)7 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)6 Block (net.minecraft.block.Block)6 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)6 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)6 World (net.minecraft.world.World)6 GenericStructure (ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)5 MinecraftServer (net.minecraft.server.MinecraftServer)5 EntityAnimal (net.minecraft.entity.passive.EntityAnimal)4 TextComponentString (net.minecraft.util.text.TextComponentString)4 WorldServer (net.minecraft.world.WorldServer)4