Java Code Examples for net.minecraft.util.EnumHand#OFF_HAND
The following examples show how to use
net.minecraft.util.EnumHand#OFF_HAND .
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: EntityUtils.java From litematica with GNU Lesser General Public License v3.0 | 5 votes |
/** * Checks if the requested item is currently in the player's hand such that it would be used for using/placing. * This means, that it must either be in the main hand, or the main hand must be empty and the item is in the offhand. * @param player * @param stack * @param lenient if true, then NBT tags and also damage of damageable items are ignored * @return */ @Nullable public static EnumHand getUsedHandForItem(EntityPlayer player, ItemStack stack, boolean lenient) { EnumHand hand = null; if (lenient) { if (ItemStack.areItemsEqualIgnoreDurability(player.getHeldItemMainhand(), stack)) { hand = EnumHand.MAIN_HAND; } else if (player.getHeldItemMainhand().isEmpty() && ItemStack.areItemsEqualIgnoreDurability(player.getHeldItemOffhand(), stack)) { hand = EnumHand.OFF_HAND; } } else { if (InventoryUtils.areStacksEqual(player.getHeldItemMainhand(), stack)) { hand = EnumHand.MAIN_HAND; } else if (player.getHeldItemMainhand().isEmpty() && InventoryUtils.areStacksEqual(player.getHeldItemOffhand(), stack)) { hand = EnumHand.OFF_HAND; } } return hand; }
Example 2
Source File: EssentialsMissingHandler.java From Cyberware with MIT License | 5 votes |
private void processEvent(Event event, EnumHand hand, EntityPlayer p, ICyberwareUserData cyberware) { EnumHandSide mainHand = p.getPrimaryHand(); EnumHandSide offHand = ((mainHand == EnumHandSide.LEFT) ? EnumHandSide.RIGHT : EnumHandSide.LEFT); EnumSide correspondingMainHand = ((mainHand == EnumHandSide.RIGHT) ? EnumSide.RIGHT : EnumSide.LEFT); EnumSide correspondingOffHand = ((offHand == EnumHandSide.RIGHT) ? EnumSide.RIGHT : EnumSide.LEFT); boolean leftUnpowered = false; ItemStack armLeft = cyberware.getCyberware(new ItemStack(CyberwareContent.cyberlimbs, 1, 0)); if (armLeft != null && !ItemCyberlimb.isPowered(armLeft)) { leftUnpowered = true; } boolean rightUnpowered = false; ItemStack armRight = cyberware.getCyberware(new ItemStack(CyberwareContent.cyberlimbs, 1, 1)); if (armRight != null && !ItemCyberlimb.isPowered(armRight)) { rightUnpowered = true; } if (hand == EnumHand.MAIN_HAND && (!cyberware.hasEssential(EnumSlot.ARM, correspondingMainHand) || leftUnpowered)) { event.setCanceled(true); } else if (hand == EnumHand.OFF_HAND && (!cyberware.hasEssential(EnumSlot.ARM, correspondingOffHand) || rightUnpowered)) { event.setCanceled(true); } }
Example 3
Source File: PythonBookItem.java From pycode-minecraft with MIT License | 5 votes |
@Nonnull @Override public ActionResult<ItemStack> onItemRightClick(@Nonnull ItemStack itemstack, World world, EntityPlayer playerIn, EnumHand hand) { FMLLog.info("Book onItemRightClick stack=%s, hand=%s", itemstack, hand); // don't activate the GUI if in offhand; don't do *anything* if (hand == EnumHand.OFF_HAND) return new ActionResult(EnumActionResult.FAIL, itemstack); PyCode.proxy.openBook(playerIn, itemstack); return new ActionResult(EnumActionResult.SUCCESS, itemstack); }
Example 4
Source File: EntityUtils.java From enderutilities with GNU Lesser General Public License v3.0 | 5 votes |
/** * Sets the held item, without playing the equip sound. * @param player * @param hand * @param stack */ public static void setHeldItemWithoutEquipSound(EntityPlayer player, EnumHand hand, ItemStack stack) { if (hand == EnumHand.MAIN_HAND) { player.inventory.mainInventory.set(player.inventory.currentItem, stack); } else if (hand == EnumHand.OFF_HAND) { player.inventory.offHandInventory.set(0, stack); } }
Example 5
Source File: ProxyCommon.java From WearableBackpacks with MIT License | 5 votes |
@SubscribeEvent public void onPlayerInteractBlock(PlayerInteractEvent.RightClickBlock event) { // This event is fired twice, once for each hand. Unfortunately there // is no way to set the result of the main hand interaction to SUCCESS // so the off hand one will be skipped. So: Hacky code! if (cancelOffHand) { cancelOffHand = false; if (event.getHand() == EnumHand.OFF_HAND) { event.setCanceled(true); return; } } // When players sneak-right-click the ground with an // empty hand, place down their equipped backpack. EntityPlayer player = event.getEntityPlayer(); World world = event.getWorld(); if (!player.isSneaking() || (event.getHand() != EnumHand.MAIN_HAND) || !player.getHeldItem(EnumHand.MAIN_HAND).isEmpty()) return; IBackpack backpack = BackpackHelper.getBackpack(player); if (backpack == null) return; // Try place the equipped backpack on the ground by using it. Also takes // care of setting the tile entity stack and data as well as unequipping. // See ItemBackpack.onItemUse. player.inventory.mainInventory.set(player.inventory.currentItem, backpack.getStack()); if (backpack.getStack().onItemUse( player, world, event.getPos(), EnumHand.MAIN_HAND, event.getFace(), 0.5F, 0.5F, 0.5F) == EnumActionResult.SUCCESS) { player.swingArm(EnumHand.MAIN_HAND); event.setCanceled(true); cancelOffHand = true; } else player.inventory.mainInventory.set(player.inventory.currentItem, ItemStack.EMPTY); }
Example 6
Source File: GTItemMagnifyingGlass.java From GT-Classic with GNU Lesser General Public License v3.0 | 4 votes |
@Override public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) { Block block = world.getBlockState(pos).getBlock(); if (player.isSneaking() || hand == EnumHand.OFF_HAND) { return EnumActionResult.PASS; } if (IC2.platform.isRendering()) { return EnumActionResult.SUCCESS; } TileEntity tileEntity = world.getTileEntity(pos); if (GTConfig.general.enableMagnifyingGlassGivesEUTooltips && tileEntity instanceof IEnergySink) { IEnergySink euSink = (IEnergySink) tileEntity; IC2.platform.messagePlayer(player, "Input Tier: " + euSink.getSinkTier()); IC2.platform.messagePlayer(player, "Input Max: " + EnergyNet.instance.getPowerFromTier(euSink.getSinkTier()) + " EU"); } if (tileEntity instanceof IProgressMachine) { IProgressMachine progress = (IProgressMachine) tileEntity; IC2.platform.messagePlayer(player, "Progress: " + +(Math.round((progress.getProgress() / progress.getMaxProgress()) * 100)) + "%"); } if (tileEntity instanceof IGTMultiTileStatus) { IGTMultiTileStatus multi = (IGTMultiTileStatus) tileEntity; IC2.platform.messagePlayer(player, "Correct Strucuture: " + multi.getStructureValid()); } if (tileEntity instanceof IGTDebuggableTile) { LinkedHashMap<String, Boolean> data = new LinkedHashMap<>(); IGTDebuggableTile debug = (IGTDebuggableTile) tileEntity; debug.getData(data); for (Map.Entry<String, Boolean> entry : data.entrySet()) { if (!entry.getValue()) { IC2.platform.messagePlayer(player, entry.getKey()); } } } if (GTBedrockOreHandler.isBedrockOre(block)) { ItemStack resource = GTBedrockOreHandler.getResource(block); String amount = resource.getCount() > 1 ? " x " + resource.getCount() : ""; IC2.platform.messagePlayer(player, "Contains: " + GTBedrockOreHandler.getResource(block).getDisplayName() + amount); } world.playSound(null, player.getPosition(), SoundEvents.ENTITY_VILLAGER_AMBIENT, SoundCategory.PLAYERS, 1.0F, 1.0F); return EnumActionResult.SUCCESS; }
Example 7
Source File: EssentialsMissingHandlerClient.java From Cyberware with MIT License | 4 votes |
private void renderItemInFirstPerson(float partialTicks) { ItemRenderer ir = mc.getItemRenderer(); AbstractClientPlayer abstractclientplayer = mc.thePlayer; float f = abstractclientplayer.getSwingProgress(partialTicks); EnumHand enumhand = (EnumHand)Objects.firstNonNull(abstractclientplayer.swingingHand, EnumHand.MAIN_HAND); float f1 = abstractclientplayer.prevRotationPitch + (abstractclientplayer.rotationPitch - abstractclientplayer.prevRotationPitch) * partialTicks; float f2 = abstractclientplayer.prevRotationYaw + (abstractclientplayer.rotationYaw - abstractclientplayer.prevRotationYaw) * partialTicks; boolean flag = true; boolean flag1 = true; if (abstractclientplayer.isHandActive()) { ItemStack itemstack = abstractclientplayer.getActiveItemStack(); if (itemstack != null && itemstack.getItem() == Items.BOW) //Forge: Data watcher can desync and cause this to NPE... { EnumHand enumhand1 = abstractclientplayer.getActiveHand(); flag = enumhand1 == EnumHand.MAIN_HAND; flag1 = !flag; } } rotateArroundXAndY(f1, f2); setLightmap(); rotateArm(partialTicks); GlStateManager.enableRescaleNormal(); ItemStack itemStackMainHand = ReflectionHelper.getPrivateValue(ItemRenderer.class, ir, 3); ItemStack itemStackOffHand = ReflectionHelper.getPrivateValue(ItemRenderer.class, ir, 4); float equippedProgressMainHand = ReflectionHelper.getPrivateValue(ItemRenderer.class, ir, 5); float prevEquippedProgressMainHand = ReflectionHelper.getPrivateValue(ItemRenderer.class, ir, 6); float equippedProgressOffHand = ReflectionHelper.getPrivateValue(ItemRenderer.class, ir, 7); float prevEquippedProgressOffHand = ReflectionHelper.getPrivateValue(ItemRenderer.class, ir, 8); RenderCyberlimbHand.INSTANCE.itemStackMainHand = itemStackMainHand; RenderCyberlimbHand.INSTANCE.itemStackOffHand = itemStackOffHand; if (flag && !missingSecondArm) { float f3 = enumhand == EnumHand.MAIN_HAND ? f : 0.0F; float f5 = 1.0F - (prevEquippedProgressMainHand + (equippedProgressMainHand - prevEquippedProgressMainHand) * partialTicks); RenderCyberlimbHand.INSTANCE.leftRobot = hasRoboLeft; RenderCyberlimbHand.INSTANCE.rightRobot = hasRoboRight; RenderCyberlimbHand.INSTANCE.renderItemInFirstPerson(abstractclientplayer, partialTicks, f1, EnumHand.MAIN_HAND, f3, itemStackMainHand, f5); } if (flag1 && !missingArm) { float f4 = enumhand == EnumHand.OFF_HAND ? f : 0.0F; float f6 = 1.0F - (prevEquippedProgressOffHand + (equippedProgressOffHand - prevEquippedProgressOffHand) * partialTicks); RenderCyberlimbHand.INSTANCE.leftRobot = hasRoboLeft; RenderCyberlimbHand.INSTANCE.rightRobot = hasRoboRight; RenderCyberlimbHand.INSTANCE.renderItemInFirstPerson(abstractclientplayer, partialTicks, f1, EnumHand.OFF_HAND, f4, itemStackOffHand, f6); } GlStateManager.disableRescaleNormal(); RenderHelper.disableStandardItemLighting(); }
Example 8
Source File: RendererBackpack.java From WearableBackpacks with MIT License | 4 votes |
public void doRenderLayer(EntityLivingBase entity, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch, float scale) { IBackpack backpack; RenderOptions renderOptions; if (_overrideBackpack != null) { backpack = _overrideBackpack; renderOptions = _overrideRenderOptions; } else { backpack = BackpackHelper.getBackpack(entity); BackpackEntityEntry entry = BackpackRegistry.getEntityEntry(entity.getClass()); renderOptions = (entry != null) ? entry.renderOptions : null; } if ((backpack == null) || (renderOptions == null)) return; GlStateManager.pushMatrix(); if (entity.isChild()) { GlStateManager.scale(0.5F, 0.5F, 0.5F); GlStateManager.translate(0.0F, 24.0F * scale, 0.0F); } ModelBase modelBase = this.livingEntityRenderer.getMainModel(); if (modelBase instanceof ModelBiped) { ModelRenderer bipedBody = ((ModelBiped) modelBase).bipedBody; if (entity.isSneaking()) { // FIXME: Can be sneaking while flying with the elytra, then backpack is misaligned..? GlStateManager.translate(0.0F, 0.2F, 0.0F); } bipedBody.postRender(scale); } else { // Fallback to the custom way of transforming the backpack. // Make backpack swing with body as players swing their arms. float swingProgress = entity.getSwingProgress(partialTicks); float swingAngle = MathHelper.sin(MathHelper.sqrt(swingProgress) * ((float)Math.PI * 2.0F)) * 0.2F; if ((entity.swingingHand == EnumHand.OFF_HAND) ^ (entity.getPrimaryHand() == EnumHandSide.LEFT)) swingAngle *= -1; if (swingAngle != 0) GlStateManager.rotate((float)Math.toDegrees(swingAngle), 0.0F, 1.0F, 0.0F); // Rotate backpack if entity is sneaking. if (entity.isSneaking()) { // FIXME: Can be sneaking while flying with the elytra, then backpack is misaligned..? GlStateManager.translate(0.0F, 0.2F, 0.0F); GlStateManager.rotate(90.0F / (float)Math.PI, 1.0F, 0.0F, 0.0F); } } GlStateManager.scale(renderOptions.scale, renderOptions.scale, renderOptions.scale); GlStateManager.translate(8.0F * scale, renderOptions.y * scale, renderOptions.z * scale); GlStateManager.rotate(180.0F, 0.0F, 0.0F, 1.0F); GlStateManager.rotate((float)renderOptions.rotate, 1.0F, 0.0F, 0.0F); GlStateManager.translate(0, ProxyClient.MODEL_BACKPACK_BOX.maxY * scale * -16, ProxyClient.MODEL_BACKPACK_BOX.minZ * scale * -16); renderBackpack(backpack, entity.ticksExisted + partialTicks, false); GlStateManager.popMatrix(); }