Search in sources :

Example 6 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 7 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 8 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 9 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)

Example 10 with EntityPlayer

use of net.minecraft.entity.player.EntityPlayer 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)

Aggregations

EntityPlayer (net.minecraft.entity.player.EntityPlayer)524 ItemStack (net.minecraft.item.ItemStack)141 EntityLivingBase (net.minecraft.entity.EntityLivingBase)95 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)68 Entity (net.minecraft.entity.Entity)64 BlockPos (net.minecraft.util.math.BlockPos)53 World (net.minecraft.world.World)50 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)42 TileEntity (net.minecraft.tileentity.TileEntity)36 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)34 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)34 ArrayList (java.util.ArrayList)33 EntityItem (net.minecraft.entity.item.EntityItem)31 PotionEffect (net.minecraft.potion.PotionEffect)28 Block (net.minecraft.block.Block)25 IBlockState (net.minecraft.block.state.IBlockState)24 List (java.util.List)23 TextComponentString (net.minecraft.util.text.TextComponentString)23 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)20 WrongUsageException (net.minecraft.command.WrongUsageException)19