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);
}
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();
}
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();
}
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);
}
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();
}
Aggregations