Java Code Examples for net.minecraft.item.ItemStack#getItem()
The following examples show how to use
net.minecraft.item.ItemStack#getItem() .
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: HandEntity.java From pycode-minecraft with MIT License | 6 votes |
public boolean handleItemInteraction(EntityPlayer player, ItemStack heldItem) { FMLLog.info("Hand Entity handleItemInteraction item=%s", heldItem); if (heldItem == null) { if (this.code.hasKey("run")) { this.code.put("hand", new HandMethods(this)); this.code.setRunner(player); this.code.invoke("run", new MyEntityPlayer(player)); this.code.setRunner(this); } return true; } Item item = heldItem.getItem(); if (item instanceof PythonWandItem) { PythonWandItem.invokeOnEntity(player, this); return true; } else if (item instanceof PythonBookItem || item instanceof ItemWritableBook) { BlockPos pos = this.getPosition(); this.code.put("hand", new HandMethods(this)); this.code.setCodeFromBook(this.getEntityWorld(), player, this, pos, heldItem); return true; } FMLLog.info("... returning FALSE YEAH"); return false; }
Example 2
Source File: TileGuidanceComputerHatch.java From AdvancedRocketry with MIT License | 6 votes |
@Override public boolean linkRocket(EntityRocketBase rocket) { this.rocket = (EntityRocket) rocket; IInventory guidanceComputer; if(!chipEjected && buttonState[buttonAutoEject] && (guidanceComputer = this.rocket.storage.getGuidanceComputer()) != null ) { ItemStack stack = guidanceComputer.getStackInSlot(0); if(!stack.isEmpty()) { if( (stack.getItem() instanceof ItemSatelliteIdentificationChip && buttonState[buttonSatellite]) || (stack.getItem() instanceof ItemPlanetIdentificationChip && buttonState[buttonPlanet]) || (stack.getItem() instanceof ItemStationChip && buttonState[buttonStation])) { ejectChipFrom(guidanceComputer); chipEjected = true; } } else chipEjected = true; } return true; }
Example 3
Source File: BW_MetaGenerated_Items.java From bartworks with MIT License | 6 votes |
@Override public void onUpdate(ItemStack aStack, World aWorld, Entity aPlayer, int aTimer, boolean aIsInHand) { super.onUpdate(aStack, aWorld, aPlayer, aTimer, aIsInHand); if (aStack == null || aStack.getItem() == null || !(aPlayer instanceof EntityLivingBase)) return; EntityLivingBase bPlayer = (EntityPlayer) aPlayer; Werkstoff w = werkstoffHashMap.get((short)aStack.getItemDamage()); if (w == null || w.getStats() == null) return; if (w.getStats().isToxic() && !GT_Utility.isWearingFullBioHazmat(bPlayer)){ bPlayer.addPotionEffect(new PotionEffect(Potion.poison.getId(),80,4)); } if (w.getStats().isRadioactive() && !GT_Utility.isWearingFullRadioHazmat(bPlayer)){ bPlayer.addPotionEffect(new PotionEffect(IC2Potion.radiation.id,80,4)); } }
Example 4
Source File: MinecraftTypeHelper.java From malmo with MIT License | 6 votes |
/** Attempt to parse string as a Variation, allowing for block properties having different names to the enum values<br> * (eg blue_orchid vs orchidBlue etc.) * @param part the string (potentially in the 'wrong' format, eg 'orchidBlue') * @param is the ItemStack from which this string came (eg from is.getUnlocalisedName) * @return a Variation, if one exists, that matches the part string passed in, or one of the ItemStacks current property values. */ public static Variation attemptToGetAsVariant(String part, ItemStack is) { if (is.getItem() instanceof ItemBlock) { // Unlocalised name doesn't always match the names we use in types.xsd // (which are the names displayed by Minecraft when using the F3 debug etc.) ItemBlock ib = (ItemBlock)(is.getItem()); IBlockState bs = ib.block.getStateFromMeta(is.getMetadata()); for (IProperty prop : bs.getProperties().keySet()) { Comparable<?> comp = bs.getValue(prop); Variation var = attemptToGetAsVariant(comp.toString()); if (var != null) return var; } return null; } else return attemptToGetAsVariant(part); }
Example 5
Source File: EntityUtils.java From enderutilities with GNU Lesser General Public License v3.0 | 6 votes |
public static ItemStack getHeldItemOfType(EntityLivingBase entity, Item item) { ItemStack stack = entity.getHeldItemMainhand(); if (stack.isEmpty() == false && stack.getItem() == item) { return stack; } stack = entity.getHeldItemOffhand(); if (stack.isEmpty() == false && stack.getItem() == item) { return stack; } return ItemStack.EMPTY; }
Example 6
Source File: TunnellerHack.java From Wurst7 with GNU General Public License v3.0 | 6 votes |
private boolean equipTorch() { for(int slot = 0; slot < 9; slot++) { // filter out non-block items ItemStack stack = MC.player.inventory.getStack(slot); if(stack.isEmpty() || !(stack.getItem() instanceof BlockItem)) continue; // filter out non-torch blocks Block block = Block.getBlockFromItem(stack.getItem()); if(!(block instanceof TorchBlock)) continue; MC.player.inventory.selectedSlot = slot; return true; } return false; }
Example 7
Source File: BlockGarden.java From GardenCollection with MIT License | 5 votes |
public Block getPlantBlockFromSlot (IBlockAccess blockAccess, int x, int y, int z, int slot) { TileEntityGarden te = getTileEntity(blockAccess, x, y, z); ItemStack stack = te.getPlantInSlot(slot); if (stack == null || stack.getItem() == null) return null; return Block.getBlockFromItem(stack.getItem()); }
Example 8
Source File: ContainerNewBrewingStand.java From Et-Futurum with The Unlicense | 5 votes |
@Override public void onPickupFromSlot(EntityPlayer player, ItemStack stack) { if (stack.getItem() instanceof ItemPotion && stack.getItemDamage() > 0) player.addStat(AchievementList.potion, 1); super.onPickupFromSlot(player, stack); }
Example 9
Source File: PacketToggleMode.java From YouTubeModdingTutorial with MIT License | 5 votes |
private void handle(PacketToggleMode message, MessageContext ctx) { EntityPlayerMP playerEntity = ctx.getServerHandler().player; ItemStack heldItem = playerEntity.getHeldItem(EnumHand.MAIN_HAND); if (!heldItem.isEmpty() && heldItem.getItem() instanceof ItemWand) { ItemWand wand = (ItemWand) (heldItem.getItem()); wand.toggleMode(playerEntity, heldItem); } }
Example 10
Source File: ContainerProgrammableController.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
@Override public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2){ ItemStack var3 = null; Slot var4 = (Slot)inventorySlots.get(par2); if(var4 != null && var4.getHasStack()) { ItemStack var5 = var4.getStack(); var3 = var5.copy(); if(par2 < 5) { if(!mergeItemStack(var5, 5, 40, false)) return null; var4.onSlotChange(var5, var3); } else if(te.isItemValidForSlot(0, var3)) { if(!mergeItemStack(var5, 0, 1, false)) return null; var4.onSlotChange(var5, var3); } else if(var3.getItem() == Itemss.machineUpgrade) { if(!mergeItemStack(var5, 1, 5, false)) return null; var4.onSlotChange(var5, var3); } if(var5.stackSize == 0) { var4.putStack((ItemStack)null); } else { var4.onSlotChanged(); } if(var5.stackSize == var3.stackSize) return null; var4.onPickupFromSlot(par1EntityPlayer, var5); } return var3; }
Example 11
Source File: ItemRuler.java From enderutilities with GNU Lesser General Public License v3.0 | 5 votes |
@Override public int getMaxModules(ItemStack containerStack, ItemStack moduleStack) { if (moduleStack.isEmpty() || (moduleStack.getItem() instanceof IModule) == false) { return 0; } return this.getMaxModules(containerStack, ((IModule) moduleStack.getItem()).getModuleType(moduleStack)); }
Example 12
Source File: NEIServerUtils.java From NotEnoughItems with MIT License | 5 votes |
/** * @param stack1 The {@link ItemStack} being compared. * @param stack2 The {@link ItemStack} to compare to. * @return whether the two items are the same in terms of damage and itemID. */ public static boolean areStacksSameType(ItemStack stack1, ItemStack stack2) { return stack1 != null && stack2 != null && (stack1.getItem() == stack2.getItem() && (!stack2.getHasSubtypes() || stack2.getItemDamage() == stack1.getItemDamage()) && ItemStack.areItemStackTagsEqual(stack2, stack1)); }
Example 13
Source File: BW_NEI_BioVatHandler.java From bartworks with MIT License | 4 votes |
@Override public void loadCraftingRecipes(ItemStack aResult) { if (aResult == null || !(aResult.getItem() instanceof LabParts && aResult.getItemDamage() < 3)) { super.loadCraftingRecipes(aResult); } }
Example 14
Source File: EventHandler.java From Wizardry with GNU Lesser General Public License v3.0 | 4 votes |
@SubscribeEvent(priority = EventPriority.HIGHEST) public void playerTick(TickEvent.PlayerTickEvent event) { //Leaving the underowrld if (event.player.getEntityWorld().provider.getDimension() == Wizardry.underWorld.getId()) { if (event.player.posY < 0) { //Gets the players spwanpoint and sets the location to teleport to around that event.player.isDead = false; BlockPos spawn = event.player.isSpawnForced(0) ? event.player.getBedLocation(0) : event.player.world.getSpawnPoint().add(event.player.world.rand.nextGaussian() * 16, 0, event.player.world.rand.nextGaussian() * 16); BlockPos teleportTo = spawn.add(0, 300 - spawn.getY(), 0); //stops fall damage fallResetter.add(event.player.getUniqueID()); TeleportUtil.teleportToDimension(event.player, 0, teleportTo.getX(), teleportTo.getY(), teleportTo.getZ()); } } //adds pass to check if player on bedrock after reached velocity if (event.player.getEntityWorld().provider.getDimension() == 0 && ConfigValues.underworldFallSpeed <= 0) { if (event.player.motionY < ConfigValues.underworldFallSpeed || passmap.get(event.player.getEntityId()) != null) { passmap.put(event.player.getEntityId(), true); BlockPos location = event.player.getPosition(); BlockPos bedrock = PosUtils.checkNeighborBlocksThoroughly(event.player.getEntityWorld(), location, Blocks.BEDROCK); if (bedrock != null) { event.player.isDead = false; fallResetter.add(event.player.getUniqueID()); TeleportUtil.teleportToDimension(event.player, Wizardry.underWorld.getId(), 0, 300, 0); passmap.remove(event.player.getEntityId()); } else if (event.player.motionY > ConfigValues.underworldFallSpeed) {//resets pass if stopped falling or slowed down alot passmap.remove(event.player.getEntityId()); } } } if (!event.player.world.isRemote) { for (ItemStack stack : event.player.inventory.mainInventory) { if (stack.getItem() == ModItems.LEVITATION_ORB) { if (stack.getItemDamage() + 1 > stack.getMaxDamage()) { stack.shrink(1); continue; } if (event.player.world.getTotalWorldTime() % 10 == 0) stack.setItemDamage(stack.getItemDamage() + 1); if (!event.player.isPotionActive(ModPotions.LOW_GRAVITY)) { event.player.addPotionEffect(new PotionEffect(ModPotions.LOW_GRAVITY, 3, 3, false, false)); } break; } } } }
Example 15
Source File: AutoSoupHack.java From Wurst7 with GNU General Public License v3.0 | 4 votes |
@Override public void onUpdate() { // sort empty bowls for(int i = 0; i < 36; i++) { // filter out non-bowl items and empty bowl slot ItemStack stack = MC.player.inventory.getStack(i); if(stack == null || stack.getItem() != Items.BOWL || i == 9) continue; // check if empty bowl slot contains a non-bowl item ItemStack emptyBowlStack = MC.player.inventory.getStack(9); boolean swap = !emptyBowlStack.isEmpty() && emptyBowlStack.getItem() != Items.BOWL; // place bowl in empty bowl slot IMC.getInteractionManager().windowClick_PICKUP(i < 9 ? 36 + i : i); IMC.getInteractionManager().windowClick_PICKUP(9); // place non-bowl item from empty bowl slot in current slot if(swap) IMC.getInteractionManager() .windowClick_PICKUP(i < 9 ? 36 + i : i); } // search soup in hotbar int soupInHotbar = findSoup(0, 9); // check if any soup was found if(soupInHotbar != -1) { // check if player should eat soup if(!shouldEatSoup()) { stopIfEating(); return; } // save old slot if(oldSlot == -1) oldSlot = MC.player.inventory.selectedSlot; // set slot MC.player.inventory.selectedSlot = soupInHotbar; // eat soup MC.options.keyUse.setPressed(true); IMC.getInteractionManager().rightClickItem(); return; } stopIfEating(); // search soup in inventory int soupInInventory = findSoup(9, 36); // move soup in inventory to hotbar if(soupInInventory != -1) IMC.getInteractionManager().windowClick_QUICK_MOVE(soupInInventory); }
Example 16
Source File: BW_GT_ItemRenderer.java From bartworks with MIT License | 4 votes |
@Override public void renderItem(IItemRenderer.ItemRenderType type, ItemStack aStack, Object... data) { if (!GT_Utility.isStackInvalid(aStack)) { short aMetaData = (short) aStack.getItemDamage(); if (aMetaData >= 0) { BW_Meta_Items.BW_GT_MetaGen_Item_Hook aItem = (BW_Meta_Items.BW_GT_MetaGen_Item_Hook) aStack.getItem(); GL11.glEnable(3042); if (type == IItemRenderer.ItemRenderType.ENTITY) { if (RenderItem.renderInFrame) { GL11.glScalef(0.85F, 0.85F, 0.85F); GL11.glRotatef(-90.0F, 0.0F, 1.0F, 0.0F); } GL11.glTranslated(-0.5D, -0.42D, 0.0D); } GL11.glColor3f(1.0F, 1.0F, 1.0F); IIcon tIcon = (IIcon) BW_Util.get2DCoordFrom1DArray(aMetaData, 0, 2, aItem.mIconList); Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationItemsTexture); GL11.glBlendFunc(770, 771); if (type.equals(IItemRenderer.ItemRenderType.INVENTORY)) { if (aMetaData < CircuitImprintLoader.reverseIDs) GT_RenderUtil.renderItemIcon(tIcon, 16.0D, 0.001D, 0.0F, 0.0F, -1.0F); else { for (int i = 0; i < 4; i++) { GT_RenderUtil.renderItemIcon(tIcon, 0.0D+i*2D,0.0D+i*2D,10.0D+i*2D,10.0D+i*2D, 0.001D, 0.0F, 0.0F, -1.0F); } } } else { if (aMetaData < CircuitImprintLoader.reverseIDs) ItemRenderer.renderItemIn2D(Tessellator.instance,tIcon.getMaxU(), tIcon.getMinV(), tIcon.getMinU(), tIcon.getMaxV(), tIcon.getIconWidth(), tIcon.getIconHeight(), 0.0625F); // else { // for (int i = 0; i < 4; i++) { // ItemRenderer.renderItemIn2D(Tessellator.instance, 0.0F+i*2F,0.0F+i*2F,10.0F+i*2F,10.0F+i*2F, tIcon.getIconWidth(), tIcon.getIconHeight(),0.0625F); // } // } // ItemRenderer.renderItemIn2D(Tessellator.instance, tIcon.getMaxU(), tIcon.getMinV(), tIcon.getMinU(), tIcon.getMaxV(), tIcon.getIconWidth(), tIcon.getIconHeight(), 0.0625F); } IIcon tOverlay = (IIcon) BW_Util.get2DCoordFrom1DArray(aMetaData, 1, 2, aItem.mIconList); GL11.glColor3f(1.0F, 1.0F, 1.0F); if (tOverlay != null) { Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationItemsTexture); GL11.glBlendFunc(770, 771); if (type.equals(IItemRenderer.ItemRenderType.INVENTORY)) { GT_RenderUtil.renderItemIcon(tOverlay, 16.0D, 0.001D, 0.0F, 0.0F, -1.0F); } else { ItemRenderer.renderItemIn2D(Tessellator.instance, tOverlay.getMaxU(), tOverlay.getMinV(), tOverlay.getMinU(), tOverlay.getMaxV(), tOverlay.getIconWidth(), tOverlay.getIconHeight(), 0.0625F); } } } GL11.glDisable(3042); } }
Example 17
Source File: GTTileBaseMachine.java From GT-Classic with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void update() { handleRedstone(); updateNeighbors(); boolean noRoom = addToInventory(); if (shouldCheckRecipe) { lastRecipe = getRecipe(); shouldCheckRecipe = false; } boolean canWork = canWork() && !noRoom; boolean operate = (canWork && lastRecipe != null && lastRecipe != GTRecipeMultiInputList.INVALID_RECIPE); if (operate) { handleChargeSlot(maxEnergy); } if (operate && canContinue() && energy >= energyConsume) { if (!getActive()) { getNetwork().initiateTileEntityEvent(this, 0, false); } setActive(true); progress += progressPerTick; useEnergy(recipeEnergy); if (progress >= recipeOperation) { process(lastRecipe); progress = 0; notifyNeighbors(); } getNetwork().updateTileGuiField(this, "progress"); } else { if (getActive()) { if (progress != 0) { getNetwork().initiateTileEntityEvent(this, 1, false); } else { getNetwork().initiateTileEntityEvent(this, 2, false); } } if (progress != 0) { progress = 0; getNetwork().updateTileGuiField(this, "progress"); } setActive(false); } if (supportsUpgrades) { for (int i = 0; i < upgradeSlots; i++) { ItemStack item = inventory.get(i + inventory.size() - upgradeSlots); if (item.getItem() instanceof IMachineUpgradeItem) { ((IMachineUpgradeItem) item.getItem()).onTick(item, this); } } } updateComparators(); }
Example 18
Source File: TNTBlock.java From LiquidBounce with GNU General Public License v3.0 | 4 votes |
@EventTarget public void onMotionUpdate(MotionEvent event) { for(final Entity entity : mc.theWorld.loadedEntityList) { if(entity instanceof EntityTNTPrimed && mc.thePlayer.getDistanceToEntity(entity) <= rangeValue.get()) { final EntityTNTPrimed tntPrimed = (EntityTNTPrimed) entity; if(tntPrimed.fuse <= fuseValue.get()) { if(autoSwordValue.get()) { int slot = -1; float bestDamage = 1F; for(int i = 0; i < 9; i++) { final ItemStack itemStack = mc.thePlayer.inventory.getStackInSlot(i); if(itemStack != null && itemStack.getItem() instanceof ItemSword) { final float itemDamage = ((ItemSword) itemStack.getItem()).getDamageVsEntity() + 4F; if(itemDamage > bestDamage) { bestDamage = itemDamage; slot = i; } } } if(slot != -1 && slot != mc.thePlayer.inventory.currentItem) { mc.thePlayer.inventory.currentItem = slot; mc.playerController.updateController(); } } if(mc.thePlayer.getHeldItem() != null && mc.thePlayer.getHeldItem().getItem() instanceof ItemSword) { mc.gameSettings.keyBindUseItem.pressed = true; blocked = true; } return; } } } if(blocked && !GameSettings.isKeyDown(mc.gameSettings.keyBindUseItem)) { mc.gameSettings.keyBindUseItem.pressed = false; blocked = false; } }
Example 19
Source File: CraftingManagerTFC.java From TFC2 with GNU General Public License v3.0 | 4 votes |
public ItemStack findMatchingRecipe(RecipeType rt, InventoryCrafting inventorycrafting, World world) { List<IRecipeTFC> rec = Collections.emptyList(); if(rt == RecipeType.NORMAL) rec = recipes; else if(rt == RecipeType.KNAPPING) rec = recipes_knapping; else if(rt == RecipeType.ANVIL) rec = recipes_anvil; else if(rt == RecipeType.POTTERY) rec = recipes_pottery; for (int k = 0; k < rec.size(); k++) { IRecipeTFC irecipe = rec.get(k); if (irecipe.matches(inventorycrafting, world)) { ItemStack out = irecipe.getCraftingResult(inventorycrafting); if(irecipe.isRepairRecipe()) { for(int i = 0; i < inventorycrafting.getSizeInventory(); i++) { ItemStack is = inventorycrafting.getStackInSlot(i); if(is.getItem() == out.getItem()) { int dam = is.getItemDamage(); out.setItemDamage(dam/2); if(is.hasTagCompound() && ! out.hasTagCompound()) out.setTagCompound(is.getTagCompound()); if(out.getItem() instanceof ItemTerraTool) { ((ItemTerraTool)out.getItem()).onRepair(out); } break; } } } return out; } } return ItemStack.EMPTY; }
Example 20
Source File: SatelliteBase.java From AdvancedRocketry with MIT License | 2 votes |
/** * @param stack stack to check (can be null) * @return true if the item stack is a valid controller for the satellite */ public boolean isAcceptableControllerItemStack(ItemStack stack) { return !stack.isEmpty() && stack.getItem() == AdvancedRocketryItems.itemSatelliteIdChip; }