Java Code Examples for net.minecraft.client.entity.EntityPlayerSP#getHeldItem()
The following examples show how to use
net.minecraft.client.entity.EntityPlayerSP#getHeldItem() .
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: BaitManager.java From SkyblockAddons with MIT License | 5 votes |
/** * Check if our Player is holding a Fishing Rod, and filters out the Grapple Hook (If any more items are made that * are Items.fishing_rods but aren't used for fishing, add them here) * * @return True if it can be used for fishing */ public boolean isHoldingRod() { EntityPlayerSP player = Minecraft.getMinecraft().thePlayer; if (player != null) { ItemStack item = player.getHeldItem(); if (item == null || item.getItem() != Items.fishing_rod) return false; return !"GRAPPLING_HOOK".equals(ItemUtils.getSkyBlockItemID(item)); } return false; }
Example 2
Source File: ProjectilesModule.java From seppuku with GNU General Public License v3.0 | 5 votes |
private ThrowableType getTypeFromCurrentItem(EntityPlayerSP player) { // Check if we're holding an item first if (player.getHeldItemMainhand() == null) { return ThrowableType.NONE; } final ItemStack itemStack = player.getHeldItem(EnumHand.MAIN_HAND); // Check what type of item this is switch (Item.getIdFromItem(itemStack.getItem())) { case 261: // ItemBow if (player.isHandActive()) return ThrowableType.ARROW; break; case 346: // ItemFishingRod return ThrowableType.FISHING_ROD; case 438: //splash potion case 441: //splash potion linger return ThrowableType.POTION; case 384: // ItemExpBottle return ThrowableType.EXPERIENCE; case 332: // ItemSnowball case 344: // ItemEgg case 368: // ItemEnderPearl return ThrowableType.NORMAL; default: break; } return ThrowableType.NONE; }
Example 3
Source File: PlayerControllerMPHook.java From SkyblockAddons with MIT License | 4 votes |
/** * Cancels stem breaks if holding an item, to avoid accidental breaking. */ public static void onPlayerDamageBlock(BlockPos loc, ReturnValue<Boolean> returnValue) { SkyblockAddons main = SkyblockAddons.getInstance(); Minecraft mc = Minecraft.getMinecraft(); EntityPlayerSP p = mc.thePlayer; ItemStack heldItem = p.getHeldItem(); if (heldItem != null) { Block block = mc.theWorld.getBlockState(loc).getBlock(); long now = System.currentTimeMillis(); if (main.getConfigValues().isEnabled(Feature.AVOID_BREAKING_STEMS) && (block.equals(Blocks.melon_stem) || block.equals(Blocks.pumpkin_stem))) { if (main.getConfigValues().isEnabled(Feature.ENABLE_MESSAGE_WHEN_BREAKING_STEMS) && now - lastStemMessage > 20000) { lastStemMessage = now; main.getUtils().sendMessage(main.getConfigValues().getRestrictedColor(Feature.AVOID_BREAKING_STEMS) + Message.MESSAGE_CANCELLED_STEM_BREAK.getMessage()); } returnValue.cancel(); } else if (main.getConfigValues().isEnabled(Feature.ONLY_MINE_ORES_DEEP_CAVERNS) && DEEP_CAVERNS_LOCATIONS.contains(main.getUtils().getLocation()) && main.getUtils().isPickaxe(heldItem.getItem()) && !DEEP_CAVERNS_MINEABLE_BLOCKS.contains(block)) { if (main.getConfigValues().isEnabled(Feature.ENABLE_MESSAGE_WHEN_MINING_DEEP_CAVERNS) && now - lastUnmineableMessage > 60000) { lastUnmineableMessage = now; main.getUtils().sendMessage(main.getConfigValues().getRestrictedColor(Feature.ONLY_MINE_ORES_DEEP_CAVERNS) + Message.MESSAGE_CANCELLED_NON_ORES_BREAK.getMessage()); } returnValue.cancel(); } else if (main.getConfigValues().isEnabled(Feature.ONLY_MINE_VALUABLES_NETHER) && Location.BLAZING_FORTRESS.equals(main.getUtils().getLocation()) && main.getUtils().isPickaxe(heldItem.getItem()) && !NETHER_MINEABLE_BLOCKS.contains(block)) { if (main.getConfigValues().isEnabled(Feature.ENABLE_MESSAGE_WHEN_MINING_NETHER) && now - lastUnmineableMessage > 60000) { lastUnmineableMessage = now; main.getUtils().sendMessage(main.getConfigValues().getRestrictedColor(Feature.ONLY_MINE_VALUABLES_NETHER) + Message.MESSAGE_CANCELLED_NON_ORES_BREAK.getMessage()); } returnValue.cancel(); } else if (main.getConfigValues().isEnabled(Feature.ONLY_BREAK_LOGS_PARK) && PARK_LOCATIONS.contains(main.getUtils().getLocation()) && main.getUtils().isAxe(heldItem.getItem()) && !LOGS.contains(block)) { if (main.getConfigValues().isEnabled(Feature.ENABLE_MESSAGE_WHEN_BREAKING_PARK) && now - lastUnmineableMessage > 60000) { lastUnmineableMessage = now; main.getUtils().sendMessage(main.getConfigValues().getRestrictedColor(Feature.ONLY_BREAK_LOGS_PARK) + Message.MESSAGE_CANCELLED_NON_LOGS_BREAK.getMessage()); } returnValue.cancel(); } else if (main.getConfigValues().isEnabled(Feature.JUNGLE_AXE_COOLDOWN)) { if ((block.equals(Blocks.log) || block.equals(Blocks.log2)) && p.getHeldItem() != null) { final boolean holdingJungleAxeOnCooldown = InventoryUtils.JUNGLE_AXE_DISPLAYNAME.equals(p.getHeldItem().getDisplayName()) && CooldownManager.isOnCooldown(InventoryUtils.JUNGLE_AXE_DISPLAYNAME); final boolean holdingTreecapitatorOnCooldown = InventoryUtils.TREECAPITATOR_DISPLAYNAME.equals(p.getHeldItem().getDisplayName()) && CooldownManager.isOnCooldown(InventoryUtils.TREECAPITATOR_DISPLAYNAME); if (holdingJungleAxeOnCooldown || holdingTreecapitatorOnCooldown) { returnValue.cancel(); } } } } }
Example 4
Source File: PlayerListener.java From SkyblockAddons with MIT License | 4 votes |
@SubscribeEvent() public void onTickMagmaBossChecker(EntityEvent.EnteringChunk e) { Entity entity = e.entity; if (main.getUtils().isOnSkyblock() && main.getConfigValues().isEnabled(Feature.ZEALOT_COUNTER_EXPLOSIVE_BOW_SUPPORT) && entity instanceof EntityArrow) { EntityArrow arrow = (EntityArrow)entity; EntityPlayerSP p = Minecraft.getMinecraft().thePlayer; ItemStack heldItem = p.getHeldItem(); if (heldItem != null && "EXPLOSIVE_BOW".equals(ItemUtils.getSkyBlockItemID(heldItem))) { AxisAlignedBB playerRadius = new AxisAlignedBB(p.posX - 3, p.posY - 3, p.posZ - 3, p.posX + 3, p.posY + 3, p.posZ + 3); if (playerRadius.isVecInside(arrow.getPositionVector())) { // System.out.println("Spawned explosive arrow!"); main.getNewScheduler().scheduleRepeatingTask(new SkyblockRunnable() { @Override public void run() { if (arrow.isDead || arrow.isCollided || arrow.inGround) { cancel(); // System.out.println("Arrow is done, added an explosion!"); Vec3 explosionLocation = new Vec3(arrow.posX, arrow.posY, arrow.posZ); explosiveBowExplosions.put(System.currentTimeMillis(), explosionLocation); recentlyKilledZealots.keySet().removeIf((killedTime) -> System.currentTimeMillis() - killedTime > 150); Set<Vec3> filteredRecentlyKilledZealots = new HashSet<>(); for (Map.Entry<Long, Set<Vec3>> recentlyKilledZealotEntry : recentlyKilledZealots.entrySet()) { filteredRecentlyKilledZealots.addAll(recentlyKilledZealotEntry.getValue()); } if (filteredRecentlyKilledZealots.isEmpty()) return; // int possibleZealotsKilled = filteredRecentlyKilledZealots.size(); // System.out.println("This means "+possibleZealotsKilled+" may have been killed..."); // int originalPossibleZealotsKilled = possibleZealotsKilled; for (Vec3 zealotDeathLocation : filteredRecentlyKilledZealots) { double distance = explosionLocation.distanceTo(zealotDeathLocation); System.out.println("Distance was "+distance+"!"); if (distance < 4.6) { // possibleZealotsKilled--; main.getPersistentValues().addKill(); EndstoneProtectorManager.onKill(); } } // System.out.println((originalPossibleZealotsKilled-possibleZealotsKilled)+" zealots were actually killed..."); } } }, 0, 1); } } } if (main.getUtils().getLocation() == Location.BLAZING_FORTRESS) { if (magmaBossSpawnArea.isVecInside(new Vec3(entity.posX, entity.posY, entity.posZ))) { // timers will trigger if 15 magmas/8 blazes spawn in the box within a 4 second time period long currentTime = System.currentTimeMillis(); if (e.entity instanceof EntityMagmaCube) { if (!recentlyLoadedChunks.contains(new IntPair(e.newChunkX, e.newChunkZ)) && entity.ticksExisted == 0) { recentMagmaCubes++; main.getScheduler().schedule(Scheduler.CommandType.SUBTRACT_MAGMA_COUNT, 4); if (recentMagmaCubes >= 17) { magmaTime = 600; magmaAccuracy = EnumUtils.MagmaTimerAccuracy.EXACTLY; if (currentTime - lastMagmaWavePost > 300000) { lastMagmaWavePost = currentTime; main.getUtils().sendInventiveTalentPingRequest(EnumUtils.MagmaEvent.MAGMA_WAVE); } } } } else if (e.entity instanceof EntityBlaze) { if (!recentlyLoadedChunks.contains(new IntPair(e.newChunkX, e.newChunkZ)) && entity.ticksExisted == 0) { recentBlazes++; main.getScheduler().schedule(Scheduler.CommandType.SUBTRACT_BLAZE_COUNT, 4); if (recentBlazes >= 10) { magmaTime = 1200; magmaAccuracy = EnumUtils.MagmaTimerAccuracy.EXACTLY; if (currentTime - lastBlazeWavePost > 300000) { lastBlazeWavePost = currentTime; main.getUtils().sendInventiveTalentPingRequest(EnumUtils.MagmaEvent.BLAZE_WAVE); } } } } } } }