Search in sources :

Example 56 with EntityPlayer

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

the class ItemBackpack method updateHasItems.

public static void updateHasItems(EntityLivingBase entity, PropertiesBackpack backpackData) {
    if (entity.worldObj.isRemote || !(entity instanceof EntityPlayer))
        return;
    EntityPlayer player = (EntityPlayer) entity;
    boolean hasItems = ((backpackData.contents != null) && !StackUtils.isEmpty(backpackData.contents));
    if (backpackData.hasItems == hasItems)
        return;
    BetterStorage.networkChannel.sendTo(new PacketBackpackHasItems(hasItems), player);
    backpackData.hasItems = hasItems;
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) PacketBackpackHasItems(net.mcft.copy.betterstorage.network.packet.PacketBackpackHasItems)

Example 57 with EntityPlayer

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

the class SlotArmorBackpack method isItemValid.

@Override
public boolean isItemValid(ItemStack stack) {
    if (stack == null)
        return false;
    EntityPlayer player = ((InventoryPlayer) inventory).player;
    Item item = stack.getItem();
    if ((item instanceof ItemBackpack) && !ItemBackpack.canEquipBackpack(player))
        return false;
    return item.isValidArmor(stack, armorType, player);
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) Item(net.minecraft.item.Item) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemBackpack(net.mcft.copy.betterstorage.item.ItemBackpack)

Example 58 with EntityPlayer

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

the class EntityFrienderman method despawnEntity.

@Override
protected void despawnEntity() {
    if (isNoDespawnRequired()) {
        entityAge = 0;
        return;
    }
    EntityPlayer player = worldObj.getClosestPlayerToEntity(this, -1.0D);
    double distance = ((player != null) ? getDistanceToEntity(player) : 64000);
    if (// Do nothing, in case I want to add a feature
    entityAge < 0) // Do nothing, in case I want to add a feature
    {
    } else // that'll make friendly endermen stay around longer.
    if (distance < 16)
        entityAge = 0;
    else if (distance < 32)
        entityAge = Math.max(0, entityAge - 2);
    else if (distance < 48)
        entityAge = Math.max(0, entityAge - 1);
    else if ((distance > 64) && (entityAge > 20 * 60 * 5) && RandomUtils.getBoolean(0.001))
        setDead();
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 59 with EntityPlayer

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

the class TileEntityPresentRenderer method renderTileEntityAt.

public void renderTileEntityAt(TileEntityPresent present, double x, double y, double z, float partialTicks) {
    TextureManager texMan = Minecraft.getMinecraft().getTextureManager();
    GL11.glPushMatrix();
    GL11.glEnable(GL12.GL_RESCALE_NORMAL);
    GL11.glTranslated(x + 0.5, y, z + 0.5);
    texMan.bindTexture(texMan.getResourceLocation(0));
    renderSome(present.colorInner, 1);
    renderSome(present.colorOuter, (present.skojanzaMode ? new int[] { 2, 3 } : new int[] { 2 }));
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glDepthFunc(GL11.GL_EQUAL);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    texMan.bindTexture(Resources.texturePresentOverlay);
    model.render(1);
    GL11.glDepthFunc(GL11.GL_LEQUAL);
    GL11.glDisable(GL11.GL_BLEND);
    EntityPlayer player = Minecraft.getMinecraft().thePlayer;
    if ((present.nameTag != null) && (present.getWorldObj() != null) && (player != null) && (player.getDistanceSq(present.xCoord + 0.5, present.yCoord + 0.5, present.zCoord + 0.5) < NAMETAG_RENDER_RANGE_SQ)) {
        MovingObjectPosition o = Minecraft.getMinecraft().objectMouseOver;
        renderNameTag(present.nameTag, player.getCommandSenderName().equalsIgnoreCase(present.nameTag), ((o.blockX == present.xCoord) && (o.blockY == present.yCoord) && (o.blockZ == present.zCoord)));
    }
    GL11.glDisable(GL12.GL_RESCALE_NORMAL);
    GL11.glPopMatrix();
}
Also used : TextureManager(net.minecraft.client.renderer.texture.TextureManager) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 60 with EntityPlayer

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

the class BackpackHandler method onLivingUpdate.

@SubscribeEvent
public void onLivingUpdate(LivingUpdateEvent event) {
    EntityLivingBase entity = event.entityLiving;
    EntityPlayer player = ((entity instanceof EntityPlayer) ? (EntityPlayer) entity : null);
    ItemStack backpack = ItemBackpack.getBackpack(entity);
    PropertiesBackpack backpackData;
    if (backpack == null) {
        backpackData = EntityUtils.getProperties(entity, PropertiesBackpack.class);
        if (backpackData == null)
            return;
        // with a backpack, equip it with one.
        if (backpackData.spawnsWithBackpack) {
            ItemStack[] contents = null;
            if (entity instanceof EntityFrienderman) {
                backpack = new ItemStack(BetterStorageItems.itemEnderBackpack);
                // Remove drop chance for the backpack.
                ((EntityLiving) entity).setEquipmentDropChance(EquipmentSlot.CHEST, 0.0F);
            } else {
                backpack = new ItemStack(BetterStorageItems.itemBackpack, 1, RandomUtils.getInt(120, 240));
                ItemBackpack backpackType = (ItemBackpack) backpack.getItem();
                if (RandomUtils.getBoolean(0.15)) {
                    // Give the backpack a random color.
                    int r = RandomUtils.getInt(32, 224);
                    int g = RandomUtils.getInt(32, 224);
                    int b = RandomUtils.getInt(32, 224);
                    int color = (r << 16) | (g << 8) | b;
                    StackUtils.set(backpack, color, "display", "color");
                }
                contents = new ItemStack[backpackType.getBackpackColumns() * backpackType.getBackpackRows()];
                // Set drop chance for the backpack to 100%.
                ((EntityLiving) entity).setEquipmentDropChance(EquipmentSlot.CHEST, 1.0F);
            }
            // If the entity spawned with enchanted armor,
            // move the enchantments over to the backpack.
            ItemStack armor = entity.getEquipmentInSlot(EquipmentSlot.CHEST);
            if (armor != null && armor.isItemEnchanted()) {
                NBTTagCompound compound = new NBTTagCompound();
                compound.setTag("ench", armor.getTagCompound().getTag("ench"));
                backpack.setTagCompound(compound);
            }
            if (contents != null) {
                // Add random items to the backpack.
                InventoryStacks inventory = new InventoryStacks(contents);
                // Add normal random backpack loot.
                WeightedRandomChestContent.generateChestContents(RandomUtils.random, randomBackpackItems, inventory, 20);
                // With a chance of 10%, add some random dungeon loot.
                if (RandomUtils.getDouble() < 0.1) {
                    ChestGenHooks info = ChestGenHooks.getInfo(ChestGenHooks.DUNGEON_CHEST);
                    WeightedRandomChestContent.generateChestContents(RandomUtils.random, info.getItems(RandomUtils.random), inventory, 5);
                }
            }
            ItemBackpack.setBackpack(entity, backpack, contents);
            backpackData.spawnsWithBackpack = false;
        } else {
            // but still has some backpack data, drop the items.
            if (backpackData.contents != null) {
                for (ItemStack stack : backpackData.contents) WorldUtils.dropStackFromEntity(entity, stack, 1.5F);
                backpackData.contents = null;
            }
        }
    }
    ItemBackpack.getBackpackData(entity).update(entity);
    if (backpack != null)
        ((ItemBackpack) backpack.getItem()).onEquippedUpdate(entity, backpack);
}
Also used : EntityFrienderman(net.mcft.copy.betterstorage.entity.EntityFrienderman) EntityLiving(net.minecraft.entity.EntityLiving) EntityLivingBase(net.minecraft.entity.EntityLivingBase) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ChestGenHooks(net.minecraftforge.common.ChestGenHooks) EntityPlayer(net.minecraft.entity.player.EntityPlayer) PropertiesBackpack(net.mcft.copy.betterstorage.misc.PropertiesBackpack) ItemBackpack(net.mcft.copy.betterstorage.item.ItemBackpack) ItemStack(net.minecraft.item.ItemStack) InventoryStacks(net.mcft.copy.betterstorage.inventory.InventoryStacks) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Aggregations

EntityPlayer (net.minecraft.entity.player.EntityPlayer)625 ItemStack (net.minecraft.item.ItemStack)169 EntityLivingBase (net.minecraft.entity.EntityLivingBase)104 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)81 Entity (net.minecraft.entity.Entity)77 World (net.minecraft.world.World)73 BlockPos (net.minecraft.util.math.BlockPos)61 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)49 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)44 TileEntity (net.minecraft.tileentity.TileEntity)43 PotionEffect (net.minecraft.potion.PotionEffect)41 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)38 EntityItem (net.minecraft.entity.item.EntityItem)37 Block (net.minecraft.block.Block)36 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)35 ArrayList (java.util.ArrayList)33 IBlockState (net.minecraft.block.state.IBlockState)33 List (java.util.List)28 TextComponentString (net.minecraft.util.text.TextComponentString)27 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)23