Java Code Examples for net.minecraft.init.Items#AIR
The following examples show how to use
net.minecraft.init.Items#AIR .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HotKeyHandler.java From I18nUpdateMod with MIT License | 6 votes |
/** * 获取输入按键,进行不同处理 * * @param stack 物品 * @return 是否成功 */ private boolean handleKey(ItemStack stack) { if (stack != null && stack != ItemStack.EMPTY && stack.getItem() != Items.AIR) { // 问题报告界面的打开 if (keyCodeCheck(reportKey.getKeyCode()) && Keyboard.isKeyDown(mainKey.getKeyCode()) && Keyboard.getEventKey() == reportKey.getKeyCode()) { return openReport(stack); } // Weblate 翻译界面的打开 else if (keyCodeCheck(weblateKey.getKeyCode()) && Keyboard.isKeyDown(mainKey.getKeyCode()) && Keyboard.getEventKey() == weblateKey.getKeyCode()) { return openWeblate(stack); } // mcmod 百科界面的打开 else if (keyCodeCheck(mcmodKey.getKeyCode()) && Keyboard.isKeyDown(mainKey.getKeyCode()) && Keyboard.getEventKey() == mcmodKey.getKeyCode()) { return openMcmod(stack); } } return false; }
Example 2
Source File: AutoArmorModule.java From seppuku with GNU General Public License v3.0 | 6 votes |
private int findArmorSlot(EntityEquipmentSlot type) { int slot = -1; float damage = 0; for (int i = 9; i < 45; i++) { final ItemStack s = Minecraft.getMinecraft().player.inventoryContainer.getSlot(i).getStack(); if (s != null && s.getItem() != Items.AIR) { if (s.getItem() instanceof ItemArmor) { final ItemArmor armor = (ItemArmor) s.getItem(); if (armor.armorType == type) { final float currentDamage = (armor.damageReduceAmount + EnchantmentHelper.getEnchantmentLevel(Enchantments.PROTECTION, s)); final boolean cursed = this.curse.getValue() ? (EnchantmentHelper.hasBindingCurse(s)) : false; if (currentDamage > damage && !cursed) { damage = currentDamage; slot = i; } } } } } return slot; }
Example 3
Source File: MissingMappingEventHandler.java From enderutilities with GNU Lesser General Public License v3.0 | 6 votes |
@SubscribeEvent public static void onMissingMappingEventItems(RegistryEvent.MissingMappings<Item> event) { List<Mapping<Item>> list = event.getMappings(); Map<String, String> renameMap = TileEntityID.getMap(); for (Mapping<Item> mapping : list) { ResourceLocation oldLoc = mapping.key; String newName = renameMap.get(oldLoc.toString()); if (newName != null) { Item item = ForgeRegistries.ITEMS.getValue(new ResourceLocation(newName)); if (item != null && item != Items.AIR) { mapping.remap(item); EnderUtilities.logger.info("Re-mapped item '{}' => '{}'", oldLoc, newName); } } } }
Example 4
Source File: HotBarRefillModule.java From seppuku with GNU General Public License v3.0 | 6 votes |
/** * Checks all items in the hotbar that can be refilled * If offhand is on, it is checked first * * @param player The player * @return The index of the first item to be refilled, -1 if there are no refillable items */ private int getRefillable(EntityPlayerSP player) { if (offHand.getValue()) { if (player.getHeldItemOffhand().getItem() != Items.AIR && player.getHeldItemOffhand().getCount() < player.getHeldItemOffhand().getMaxStackSize() && (double) player.getHeldItemOffhand().getCount() / player.getHeldItemOffhand().getMaxStackSize() <= (percentage.getValue() / 100.0)) { return 45; } } for (int i = 0; i < 9; i++) { ItemStack stack = player.inventory.mainInventory.get(i); if (stack.getItem() != Items.AIR && stack.getCount() < stack.getMaxStackSize() && (double) stack.getCount() / stack.getMaxStackSize() <= (percentage.getValue() / 100.0)) { return i; } } return -1; }
Example 5
Source File: HotBarRefillModule.java From seppuku with GNU General Public License v3.0 | 6 votes |
/** * Searches the player's inventory for the smallest stack. * Gets the smallest stack so that there are not a a bunch * of partially full stacks left in the player's inventory. * * @param player The player * @param itemStack The item type that should be found * @return The index of the smallest stack of the given item, -1 if the given item does not exist */ private int getSmallestStack(EntityPlayerSP player, ItemStack itemStack) { if (itemStack == null) { return -1; } int minCount = itemStack.getMaxStackSize() + 1; int minIndex = -1; // i starts at 9 so that the hotbar is not checked for (int i = 9; i < player.inventory.mainInventory.size(); i++) { ItemStack stack = player.inventory.mainInventory.get(i); if (stack.getItem() != Items.AIR && stack.getItem() == itemStack.getItem() && stack.getCount() < minCount) { minCount = stack.getCount(); minIndex = i; } } return minIndex; }
Example 6
Source File: QuickCraftModule.java From seppuku with GNU General Public License v3.0 | 6 votes |
@Listener public void onReceivePacket (EventReceivePacket event) { if (event.getStage() == EventStageable.EventStage.PRE) { if (event.getPacket() instanceof SPacketSetSlot) { // Check if this packet updates the recipe result and if the result is not empty if (((SPacketSetSlot) event.getPacket()).getSlot() == 0 && ((SPacketSetSlot) event.getPacket()).getStack().getItem() != Items.AIR) { Minecraft mc = Minecraft.getMinecraft(); if (mc.currentScreen instanceof GuiInventory || mc.currentScreen instanceof GuiCrafting) { mc.playerController.windowClick(mc.player.openContainer.windowId, 0, 0, ClickType.QUICK_MOVE, mc.player); mc.playerController.updateController(); } } } } }
Example 7
Source File: BlockLeekCrop.java From TofuCraftReload with MIT License | 6 votes |
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) { Random rand = world instanceof World ? ((World) world).rand : RANDOM; int age = getAge(state); int count = quantityDropped(state, fortune, rand); for (int i = 0; i < count; i++) { Item item = this.getItemDropped(state, rand, fortune); if (item != Items.AIR) { drops.add(new ItemStack(item, 1, this.damageDropped(state))); } } if (age >= getMaxAge()) { int k = 3 + fortune; for (int i = 0; i < k; ++i) { if (rand.nextInt(2 * getMaxAge()) <= age) { drops.add(new ItemStack(this.getSeed(), 1, this.damageDropped(state))); } } } }
Example 8
Source File: GiveCommand.java From seppuku with GNU General Public License v3.0 | 5 votes |
private int findEmptyhotbar() { for (int i = 0; i < 9; i++) { final ItemStack stack = Minecraft.getMinecraft().player.inventory.getStackInSlot(i); if (stack.getItem() == Items.AIR) { return i; } } return -1; }
Example 9
Source File: BakedModelHandler.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
public void addBuiltInBlock(Block block, String particleTexture) { this.builtInBlocks.add(new Tuple<>(block, particleTexture)); ModelLoader.setCustomStateMapper(block, SIMPLE_STATE_MAPPER); Item itemFromBlock = Item.getItemFromBlock(block); if (itemFromBlock != Items.AIR) { ModelLoader.setCustomMeshDefinition(itemFromBlock, SIMPLE_MESH_DEFINITION); } }
Example 10
Source File: SpawnEggCommand.java From seppuku with GNU General Public License v3.0 | 5 votes |
private int findEmptyhotbar() { for (int i = 0; i < 9; i++) { final ItemStack stack = Minecraft.getMinecraft().player.inventory.getStackInSlot(i); if (stack.getItem() == Items.AIR) { return i; } } return -1; }
Example 11
Source File: CraftBlock.java From Kettle with GNU General Public License v3.0 | 5 votes |
public Collection<ItemStack> getDrops() { List<ItemStack> drops = new ArrayList<ItemStack>(); net.minecraft.block.Block block = this.getNMSBlock(); if (block != Blocks.AIR) { IBlockState data = getData0(); // based on nms.Block.dropNaturally int count = block.quantityDroppedWithBonus(0, chunk.getHandle().getWorld().rand); for (int i = 0; i < count; ++i) { Item item = block.getItemDropped(data, chunk.getHandle().getWorld().rand, 0); if (item != Items.AIR) { // Skulls are special, their data is based on the tile entity if (Blocks.SKULL == block) { net.minecraft.item.ItemStack nmsStack = new net.minecraft.item.ItemStack(item, 1, block.damageDropped(data)); TileEntitySkull tileentityskull = (TileEntitySkull) chunk.getHandle().getWorld().getTileEntity(new BlockPos(x, y, z)); if (tileentityskull.getSkullType() == 3 && tileentityskull.getPlayerProfile() != null) { nmsStack.setTagCompound(new NBTTagCompound()); NBTTagCompound nbttagcompound = new NBTTagCompound(); NBTUtil.writeGameProfile(nbttagcompound, tileentityskull.getPlayerProfile()); nmsStack.getTagCompound().setTag("SkullOwner", nbttagcompound); } drops.add(CraftItemStack.asBukkitCopy(nmsStack)); // We don't want to drop cocoa blocks, we want to drop cocoa beans. } else if (Blocks.COCOA == block) { int age = (Integer) data.getValue(BlockCocoa.AGE); int dropAmount = (age >= 2 ? 3 : 1); for (int j = 0; j < dropAmount; ++j) { drops.add(new ItemStack(Material.INK_SACK, 1, (short) 3)); } } else { drops.add(new ItemStack(CraftMagicNumbers.getMaterial(item), 1, (short) block.damageDropped(data))); } } } } return drops; }
Example 12
Source File: CrashSlimeCommand.java From seppuku with GNU General Public License v3.0 | 5 votes |
private int findEmptyhotbar() { for (int i = 0; i < 9; i++) { final ItemStack stack = Minecraft.getMinecraft().player.inventory.getStackInSlot(i); if (stack.getItem() == Items.AIR) { return i; } } return -1; }
Example 13
Source File: ScaffoldModule.java From seppuku with GNU General Public License v3.0 | 5 votes |
private int findEmptyhotbar() { for (int i = 0; i < 9; i++) { final ItemStack stack = Minecraft.getMinecraft().player.inventory.getStackInSlot(i); if (stack.getItem() == Items.AIR) { return i; } } return -1; }
Example 14
Source File: RegenModule.java From seppuku with GNU General Public License v3.0 | 5 votes |
private int findEmptyHotbar() { for (int i = 0; i < 9; i++) { final ItemStack stack = Minecraft.getMinecraft().player.inventory.getStackInSlot(i); if (stack.getItem() == Items.AIR) { return i; } } return -1; }
Example 15
Source File: HotBarRefillModule.java From seppuku with GNU General Public License v3.0 | 4 votes |
/** * Refills a given slot in the hotbar from an item in the player's inventory. * Uses the slot's current ItemStack to decide what it should be refilled with. * * @param mc The Mincraft instance * @param slot The slot that should be refilled */ public void refillHotbarSlot(Minecraft mc, int slot) { ItemStack stack; if (slot == 45) { // Special case for offhand stack = mc.player.getHeldItemOffhand(); } else { stack = mc.player.inventory.mainInventory.get(slot); } // If the slot is air it cant be refilled if (stack.getItem() == Items.AIR) { return; } // The slot can't be refilled if there is nothing to refill it with int biggestStack = getSmallestStack(mc.player, stack); if (biggestStack == -1) { return; } // Special case for offhand (can't use QUICK_CLICK) if (slot == 45) { mc.playerController.windowClick(mc.player.inventoryContainer.windowId, biggestStack, 0, ClickType.PICKUP, mc.player); mc.playerController.windowClick(mc.player.inventoryContainer.windowId, 45, 0, ClickType.PICKUP, mc.player); mc.playerController.windowClick(mc.player.inventoryContainer.windowId, biggestStack, 0, ClickType.PICKUP, mc.player); return; } int overflow = -1; // The slot a shift click will overflow to for (int i = 0; i < 9 && overflow == -1; i++) { if (mc.player.inventory.mainInventory.get(i).getItem() == Items.AIR) { overflow = i; } } mc.playerController.windowClick(mc.player.inventoryContainer.windowId, biggestStack, 0, ClickType.QUICK_MOVE, mc.player); // If the two stacks don't overflow when combined we don't have to move overflow if (overflow != -1 && mc.player.inventory.mainInventory.get(overflow).getItem() != Items.AIR) { mc.playerController.windowClick(mc.player.inventoryContainer.windowId, biggestStack, overflow, ClickType.SWAP, mc.player); } }
Example 16
Source File: ItemList.java From NotEnoughItems with MIT License | 4 votes |
@Override public void execute() { ThreadOperationTimer timer = getTimer(500); LinkedList<ItemStack> items = new LinkedList<>(); LinkedList<ItemStack> permutations = new LinkedList<>(); ListMultimap<Item, ItemStack> itemMap = ArrayListMultimap.create(); timer.setLimit(500); for (Item item : Item.REGISTRY) { if (interrupted()) { return; } if (item == null || erroredItems.contains(item) || item == Items.AIR) { continue; } try { timer.reset(item); permutations.clear(); permutations.addAll(ItemInfo.itemOverrides.get(item)); if (permutations.isEmpty()) { item.getSubItems(CreativeTabs.SEARCH, new NonNullList<>(permutations, null)); } //TODO, the implementation of damageSearch is wrong, not sure if this is actually needed ever. //if (permutations.isEmpty()) { // damageSearch(item, permutations); //} permutations.addAll(ItemInfo.itemVariants.get(item)); timer.reset(); items.addAll(permutations); itemMap.putAll(item, permutations); } catch (Throwable t) { LogHelper.errorError("Removing item: %s from list.", t, item); erroredItems.add(item); } } if (interrupted()) { return; } ItemList.items = items; ItemList.itemMap = itemMap; synchronized (loadCallbacks) { for (ItemsLoadedCallback callback : loadCallbacks) { callback.itemsLoaded(); } } updateFilter.restart(); }
Example 17
Source File: ShootingStar.java From CommunityMod with GNU Lesser General Public License v2.1 | 4 votes |
public static void registerModels(String modid) { for (ModelCompound compound : modelList) { if (compound.getModid().equals(modid)) { if (compound.isBlock()) { if (compound.getFileName().equals("shootingstar.undefinedfilename")) { //Checks if block has an item if (Item.getItemFromBlock(compound.getBlock()) != Items.AIR) { ModelMethods.registerItemModel(compound.getItem(), compound.getMeta(), compound.getBlockStatePath(), compound.getInventoryVariant()); } if (shouldDoCustomVariant(compound)) { ModelMethods.setBlockStateMapper(compound.getBlock(), compound.getBlockStatePath(), compound.getVariant()); } else { ModelMethods.setBlockStateMapper(compound.getBlock(), compound.getBlockStatePath(), compound.getIgnoreProperties()); } } else { //Checks if block has an item if (Item.getItemFromBlock(compound.getBlock()) != Items.AIR) { ModelMethods.registerItemModel(compound.getItem(), compound.getMeta(), compound.getFileName(), compound.getBlockStatePath(), compound.getInventoryVariant()); } if (shouldDoCustomVariant(compound)) { ModelMethods.setBlockStateMapper(compound.getBlock(), compound.getFileName(), compound.getBlockStatePath(), compound.getVariant()); } else { ModelMethods.setBlockStateMapper(compound.getBlock(), compound.getFileName(), compound.getBlockStatePath(), compound.getIgnoreProperties()); } } } if (compound.isItem()) { if (compound.getFileName().equals("shootingstar.undefinedfilename")) { ModelMethods.registerItemModel(compound.getItem(), compound.getMeta(), compound.getBlockStatePath(), compound.getInventoryVariant()); } else { ModelMethods.registerItemModel(compound.getItem(), compound.getMeta(), compound.getFileName(), compound.getBlockStatePath(), compound.getInventoryVariant()); } } } } }
Example 18
Source File: RegenModule.java From seppuku with GNU General Public License v3.0 | 4 votes |
@Listener public void onUpdate(EventPlayerUpdate event) { if (event.getStage() == EventStageable.EventStage.PRE) { final Minecraft mc = Minecraft.getMinecraft(); final ItemStack stack = mc.player.inventory.getCurrentItem(); switch (this.mode.getValue()) { case POTION: break; case GAPPLE: if (mc.player.getHealth() <= this.health.getValue() && mc.player.getAbsorptionAmount() <= 0) { gappleSlot = getItemHotbar(Items.GOLDEN_APPLE); } if (gappleSlot != -1) { mc.player.inventory.currentItem = gappleSlot; mc.playerController.updateController(); if (stack.getItem() != Items.AIR && stack.getItem() == Items.GOLDEN_APPLE) { if (mc.currentScreen == null) { mc.gameSettings.keyBindUseItem.pressed = true; } else { mc.playerController.processRightClick(mc.player, mc.world, EnumHand.MAIN_HAND); } if (mc.player.getAbsorptionAmount() > 0) { mc.gameSettings.keyBindUseItem.pressed = false; gappleSlot = -1; if(this.once.getValue()) this.toggle(); } } } else { if (mc.player.getHealth() <= this.health.getValue() && mc.player.getAbsorptionAmount() <= 0) { if (this.refill.getValue()) { final int invSlot = findStackInventory(Items.GOLDEN_APPLE); if (invSlot != -1) { final int empty = findEmptyHotbar(); mc.playerController.windowClick(mc.player.inventoryContainer.windowId, invSlot, empty == -1 ? mc.player.inventory.currentItem : empty, ClickType.SWAP, mc.player); mc.playerController.updateController(); } } } } break; } } }
Example 19
Source File: BlockFoam.java From GregTech with GNU Lesser General Public License v3.0 | 4 votes |
@Override public Item getItemDropped(IBlockState state, Random rand, int fortune) { return Items.AIR; }
Example 20
Source File: BlockDoorBase.java From Sakura_mod with MIT License | 4 votes |
@Override public Item getItemDropped(IBlockState state, Random rand, int fortune) { return state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER ? Items.AIR : this.getItem(); }