use of net.mcft.copy.betterstorage.item.ItemBackpack in project BetterStorage by copygirl.
the class CommonProxy method onPlayerTick.
@SubscribeEvent
public void onPlayerTick(PlayerTickEvent event) {
if (event.side == Side.SERVER && event.phase == Phase.END) {
//Cleanup in case the backpack is not equipped correctly, due to changing the backpackChestplate setting.
ItemStack stack = event.player.getEquipmentInSlot(EquipmentSlot.CHEST);
if (stack != null && stack.getItem() instanceof ItemBackpack && !BetterStorage.globalConfig.getBoolean(GlobalConfig.backpackChestplate)) {
//First thing that never should happen...
event.player.setCurrentItemOrArmor(EquipmentSlot.CHEST, null);
ItemBackpack.setBackpack(event.player, stack, ItemBackpack.getBackpackData(event.player).contents);
} else if ((stack == null || (stack.getItem() != null && !(stack.getItem() instanceof ItemBackpack))) && ItemBackpack.getBackpackData(event.player).backpack != null && BetterStorage.globalConfig.getBoolean(GlobalConfig.backpackChestplate)) {
//And that.
ItemStack backpack = ItemBackpack.getBackpack(event.player);
//Not really a good practice, I'd say.
ItemBackpack.getBackpackData(event.player).backpack = null;
if (stack != null) {
//Drop the armor if the player had some and decided to switch the setting anyways.
WorldUtils.dropStackFromEntity(event.player, stack, 4.0F);
}
event.player.setCurrentItemOrArmor(EquipmentSlot.CHEST, backpack);
}
}
}
use of net.mcft.copy.betterstorage.item.ItemBackpack 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.mcft.copy.betterstorage.item.ItemBackpack 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.mcft.copy.betterstorage.item.ItemBackpack in project BetterStorage by copygirl.
the class ClientProxy method onRenderPlayerSpecialsPre.
@SubscribeEvent
public void onRenderPlayerSpecialsPre(RenderPlayerEvent.Specials.Pre event) {
ItemStack backpack = ItemBackpack.getBackpackData(event.entityPlayer).backpack;
if (backpack != null) {
EntityPlayer player = event.entityPlayer;
float partial = event.partialRenderTick;
ItemBackpack backpackType = (ItemBackpack) backpack.getItem();
int color = backpackType.getColor(backpack);
ModelBackpackArmor model = (ModelBackpackArmor) backpackType.getArmorModel(player, backpack, 0);
model.onGround = ReflectionUtils.invoke(RendererLivingEntity.class, event.renderer, "func_77040_d", "renderSwingProgress", EntityLivingBase.class, float.class, player, partial);
model.setLivingAnimations(player, 0, 0, partial);
RenderUtils.bindTexture(new ResourceLocation(backpackType.getArmorTexture(backpack, player, 0, null)));
RenderUtils.setColorFromInt((color >= 0) ? color : 0xFFFFFF);
model.render(player, 0, 0, 0, 0, 0, 0);
if (color >= 0) {
RenderUtils.bindTexture(new ResourceLocation(backpackType.getArmorTexture(backpack, player, 0, "overlay")));
GL11.glColor3f(1.0F, 1.0F, 1.0F);
model.render(player, 0, 0, 0, 0, 0, 0);
}
if (backpack.isItemEnchanted()) {
float f9 = player.ticksExisted + partial;
RenderUtils.bindTexture(Resources.enchantedEffect);
GL11.glEnable(GL11.GL_BLEND);
GL11.glColor4f(0.5F, 0.5F, 0.5F, 1.0F);
GL11.glDepthFunc(GL11.GL_EQUAL);
GL11.glDepthMask(false);
for (int k = 0; k < 2; ++k) {
GL11.glDisable(GL11.GL_LIGHTING);
float f11 = 0.76F;
GL11.glColor4f(0.5F * f11, 0.25F * f11, 0.8F * f11, 1.0F);
GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE);
GL11.glMatrixMode(GL11.GL_TEXTURE);
GL11.glLoadIdentity();
float f12 = f9 * (0.001F + k * 0.003F) * 20.0F;
float f13 = 0.33333334F;
GL11.glScalef(f13, f13, f13);
GL11.glRotatef(30.0F - k * 60.0F, 0.0F, 0.0F, 1.0F);
GL11.glTranslatef(0.0F, f12, 0.0F);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
model.render(player, 0, 0, 0, 0, 0, 0);
}
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glMatrixMode(GL11.GL_TEXTURE);
GL11.glDepthMask(true);
GL11.glLoadIdentity();
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_BLEND);
GL11.glDepthFunc(GL11.GL_LEQUAL);
}
} else
backpack = ItemBackpack.getBackpack(event.entityPlayer);
if (backpack != null)
event.renderCape = false;
}
use of net.mcft.copy.betterstorage.item.ItemBackpack in project BetterStorage by copygirl.
the class BetterStorageItems method initialize.
public static void initialize() {
key = MiscUtils.conditionalNew(ItemKey.class, GlobalConfig.keyEnabled);
lock = MiscUtils.conditionalNew(ItemLock.class, GlobalConfig.lockEnabled);
keyring = MiscUtils.conditionalNew(ItemKeyring.class, GlobalConfig.keyringEnabled);
cardboardSheet = MiscUtils.conditionalNew(ItemCardboardSheet.class, GlobalConfig.cardboardSheetEnabled);
masterKey = MiscUtils.conditionalNew(ItemMasterKey.class, GlobalConfig.masterKeyEnabled);
drinkingHelmet = MiscUtils.conditionalNew(ItemDrinkingHelmet.class, GlobalConfig.drinkingHelmetEnabled);
slimeBucket = MiscUtils.conditionalNew(ItemBucketSlime.class, GlobalConfig.slimeBucketEnabled);
presentBook = new ItemPresentBook();
itemBackpack = MiscUtils.conditionalNew(ItemBackpack.class, GlobalConfig.backpackEnabled);
itemEnderBackpack = MiscUtils.conditionalNew(ItemEnderBackpack.class, GlobalConfig.enderBackpackEnabled);
cardboardHelmet = conditionalNewArmor(GlobalConfig.cardboardHelmetEnabled, 0);
cardboardChestplate = conditionalNewArmor(GlobalConfig.cardboardChestplateEnabled, 1);
cardboardLeggings = conditionalNewArmor(GlobalConfig.cardboardLeggingsEnabled, 2);
cardboardBoots = conditionalNewArmor(GlobalConfig.cardboardBootsEnabled, 3);
cardboardSword = MiscUtils.conditionalNew(ItemCardboardSword.class, GlobalConfig.cardboardSwordEnabled);
cardboardPickaxe = MiscUtils.conditionalNew(ItemCardboardPickaxe.class, GlobalConfig.cardboardPickaxeEnabled);
cardboardShovel = MiscUtils.conditionalNew(ItemCardboardShovel.class, GlobalConfig.cardboardShovelEnabled);
cardboardAxe = MiscUtils.conditionalNew(ItemCardboardAxe.class, GlobalConfig.cardboardAxeEnabled);
cardboardHoe = MiscUtils.conditionalNew(ItemCardboardHoe.class, GlobalConfig.cardboardHoeEnabled);
anyCardboardItemsEnabled = ((BetterStorageItems.cardboardHelmet != null) || (BetterStorageItems.cardboardChestplate != null) || (BetterStorageItems.cardboardLeggings != null) || (BetterStorageItems.cardboardBoots != null) || (BetterStorageItems.cardboardSword != null) || (BetterStorageItems.cardboardPickaxe != null) || (BetterStorageItems.cardboardAxe != null) || (BetterStorageItems.cardboardShovel != null) || (BetterStorageItems.cardboardHoe != null));
if (cardboardSheet != null)
OreDictionary.registerOre("sheetCardboard", cardboardSheet);
Addon.initializeItemsAll();
}
Aggregations