Java Code Examples for net.minecraft.util.Hand#MAIN_HAND
The following examples show how to use
net.minecraft.util.Hand#MAIN_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: HallowedTreasureChestBlock.java From the-hallow with MIT License | 6 votes |
@SuppressWarnings("deprecation") @Override public ActionResult onUse(BlockState blockState, World world, BlockPos pos, PlayerEntity playerEntity, Hand hand, BlockHitResult blockHitResult) { if (hand == Hand.MAIN_HAND) { float x = pos.getX() + .49f; float y = pos.getY(); float z = pos.getZ() + .51f; HallowedTreasureChestEntity entity = new HallowedTreasureChestEntity(world, x, y, z, true, blockState.get(FACING).asRotation()); entity.updatePosition(x, y, z); world.spawnEntity(entity); return ActionResult.SUCCESS; } return ActionResult.PASS; }
Example 2
Source File: GuiItem.java From LibGui with MIT License | 6 votes |
@Override public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) { if (world.isClient) { openScreen(); // In its own method to prevent class loading issues } return new TypedActionResult<ItemStack>(ActionResult.SUCCESS, (hand==Hand.MAIN_HAND) ? player.getMainHandStack() : player.getOffHandStack()); }
Example 3
Source File: RenderMiningLaser.java From MiningGadgets with MIT License | 5 votes |
private static void drawBeam(double xOffset, double yOffset, double zOffset, float thickness, Hand hand, double distance, BufferBuilder wr, double v1, double v2, float ticks) { ClientPlayerEntity player = Minecraft.getInstance().player; float startXOffset = -0.25f; float startYOffset = -.115f; float startZOffset = 0.65f + (1 - player.getFovModifier()); float f = (MathHelper.lerp(ticks, player.prevRotationPitch, player.rotationPitch) - MathHelper.lerp(ticks, player.prevRenderArmPitch, player.renderArmPitch)); float f1 = (MathHelper.lerp(ticks, player.prevRotationYaw, player.rotationYaw) - MathHelper.lerp(ticks, player.prevRenderArmYaw, player.renderArmYaw)); startXOffset = startXOffset + (f1 / 1000); startYOffset = startYOffset + (f / 1000); // Support for hand sides remembering to take into account of Skin options if( Minecraft.getInstance().gameSettings.mainHand != HandSide.RIGHT ) hand = hand == Hand.MAIN_HAND ? Hand.OFF_HAND : Hand.MAIN_HAND; wr.begin(GL_QUADS, DefaultVertexFormats.POSITION_TEX); if (hand == Hand.MAIN_HAND) { wr.pos(startXOffset, -thickness + startYOffset, startZOffset).tex(1, (float) v1).endVertex(); wr.pos(xOffset, -thickness + yOffset, distance + zOffset).tex(1, (float) v2).endVertex(); wr.pos(xOffset, thickness + yOffset, distance + zOffset).tex(0, (float) v2).endVertex(); wr.pos(startXOffset, thickness + startYOffset, startZOffset).tex(0, (float) v1).endVertex(); } else { startYOffset = -.120f; wr.pos(-startXOffset, thickness + startYOffset, startZOffset).tex(0, (float) v1).endVertex(); wr.pos(xOffset, thickness + yOffset, distance + zOffset).tex(0, (float) v2).endVertex(); wr.pos(xOffset, -thickness + yOffset, distance + zOffset).tex(1, (float) v2).endVertex(); wr.pos(-startXOffset, -thickness + startYOffset, startZOffset).tex(1, (float) v1).endVertex(); } Tessellator.getInstance().draw(); }
Example 4
Source File: BlockValue.java From fabric-carpet with MIT License | 4 votes |
private PlacementContext(World world_1, Direction direction_1, boolean sneakPlace, ItemStack itemStack_1, BlockHitResult hitres) { super(world_1, null, Hand.MAIN_HAND, itemStack_1, hitres); this.facing = direction_1; this.sneakPlace = sneakPlace; }
Example 5
Source File: RenderMiningLaser.java From MiningGadgets with MIT License | 4 votes |
private static void drawLasers(RenderWorldLastEvent event, Vec3d from, RayTraceResult trace, double xOffset, double yOffset, double zOffset, float r, float g, float b, float thickness, PlayerEntity player, float ticks, float speedModifier) { Hand activeHand; if (player.getHeldItemMainhand().getItem() instanceof MiningGadget) { activeHand = Hand.MAIN_HAND; } else if (player.getHeldItemOffhand().getItem() instanceof MiningGadget) { activeHand = Hand.OFF_HAND; } else { return; } ItemStack stack = player.getHeldItem(activeHand); double distance = from.subtract(trace.getHitVec()).length(); long gameTime = player.world.getGameTime(); double v = gameTime * speedModifier; float additiveThickness = (thickness * 3.5f) * calculateLaserFlickerModifier(gameTime); BufferBuilder wr = Tessellator.getInstance().getBuffer(); Vec3d view = Minecraft.getInstance().gameRenderer.getActiveRenderInfo().getProjectedView(); MatrixStack matrix = event.getMatrixStack(); matrix.translate(view.getX(), view.getY(), view.getZ()); if( trace.getType() == RayTraceResult.Type.MISS ) matrix.translate(-from.x, -from.y, -from.z); RenderSystem.pushMatrix(); RenderSystem.multMatrix(matrix.getLast().getMatrix()); RenderSystem.enableColorMaterial(); // This makes it so we don't clip into the world, we're effectively drawing on it RenderSystem.disableDepthTest(); RenderSystem.enableBlend(); //This makes it so multiplayer doesn't matter which side the player is standing on to see someone elses laser RenderSystem.disableCull(); RenderSystem.enableTexture(); RenderSystem.rotatef(MathHelper.lerp(ticks, -player.rotationYaw, -player.prevRotationYaw), 0, 1, 0); RenderSystem.rotatef(MathHelper.lerp(ticks, player.rotationPitch, player.prevRotationPitch), 1, 0, 0); // additive laser beam RenderSystem.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); RenderSystem.color4f(r, g, b, 0.7f); Minecraft.getInstance().getTextureManager().bindTexture(laserBeamGlow); drawBeam(xOffset, yOffset, zOffset, additiveThickness, activeHand, distance, wr, 0.5, 1, ticks); // main laser, colored part RenderSystem.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); RenderSystem.color4f(r, g, b, 1.0f); Minecraft.getInstance().getTextureManager().bindTexture(laserBeam2); drawBeam(xOffset, yOffset, zOffset, thickness, activeHand, distance, wr, v, v + distance * 1.5, ticks); // white core RenderSystem.color4f(MiningProperties.getColor(stack, MiningProperties.COLOR_RED_INNER) / 255f, MiningProperties.getColor(stack, MiningProperties.COLOR_GREEN_INNER) / 255f, MiningProperties.getColor(stack, MiningProperties.COLOR_BLUE_INNER) / 255f, 1.0f); Minecraft.getInstance().getTextureManager().bindTexture(laserBeam); drawBeam(xOffset, yOffset, zOffset, thickness / 2, activeHand, distance, wr, v, v + distance * 1.5, ticks); RenderSystem.enableDepthTest(); RenderSystem.enableCull(); RenderSystem.popMatrix(); }
Example 6
Source File: RenderMiningLaser2.java From MiningGadgets with MIT License | 4 votes |
private static void drawLasers(RenderWorldLastEvent event, Vec3d from, RayTraceResult trace, double xOffset, double yOffset, double zOffset, float r, float g, float b, float thickness, PlayerEntity player, float ticks, float speedModifier) { Hand activeHand; if (player.getHeldItemMainhand().getItem() instanceof MiningGadget) { activeHand = Hand.MAIN_HAND; } else if (player.getHeldItemOffhand().getItem() instanceof MiningGadget) { activeHand = Hand.OFF_HAND; } else { return; } IVertexBuilder builder; ItemStack stack = player.getHeldItem(activeHand); double distance = from.subtract(trace.getHitVec()).length(); long gameTime = player.world.getGameTime(); double v = gameTime * speedModifier; float additiveThickness = (thickness * 3.5f) * calculateLaserFlickerModifier(gameTime); float beam2r = MiningProperties.getColor(stack, MiningProperties.COLOR_RED_INNER) / 255f; float beam2g = MiningProperties.getColor(stack, MiningProperties.COLOR_GREEN_INNER) / 255f; float beam2b =MiningProperties.getColor(stack, MiningProperties.COLOR_BLUE_INNER) / 255f; Vec3d view = Minecraft.getInstance().gameRenderer.getActiveRenderInfo().getProjectedView(); IRenderTypeBuffer.Impl buffer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource(); MatrixStack matrix = event.getMatrixStack(); matrix.push(); matrix.translate(-view.getX(), -view.getY(), -view.getZ()); matrix.translate(from.x, from.y, from.z); matrix.rotate(Vector3f.YP.rotationDegrees(MathHelper.lerp(ticks, -player.rotationYaw, -player.prevRotationYaw))); matrix.rotate(Vector3f.XP.rotationDegrees(MathHelper.lerp(ticks, player.rotationPitch, player.prevRotationPitch))); MatrixStack.Entry matrixstack$entry = matrix.getLast(); Matrix3f matrixNormal = matrixstack$entry.getNormal(); Matrix4f positionMatrix = matrixstack$entry.getMatrix(); //additive laser beam builder = buffer.getBuffer(MyRenderType.LASER_MAIN_ADDITIVE); drawBeam(xOffset, yOffset, zOffset, builder, positionMatrix, matrixNormal, additiveThickness, activeHand, distance, 0.5, 1, ticks, r,g,b,0.7f); //main laser, colored part builder = buffer.getBuffer(MyRenderType.LASER_MAIN_BEAM); drawBeam(xOffset, yOffset, zOffset, builder, positionMatrix, matrixNormal, thickness, activeHand, distance, v, v + distance * 1.5, ticks, r,g,b,1f); //core builder = buffer.getBuffer(MyRenderType.LASER_MAIN_CORE); drawBeam(xOffset, yOffset, zOffset, builder, positionMatrix, matrixNormal, thickness/2, activeHand, distance, v, v + distance * 1.5, ticks, beam2r,beam2g,beam2b,1f); matrix.pop(); RenderSystem.disableDepthTest(); buffer.finish(); }
Example 7
Source File: RenderMiningLaser2.java From MiningGadgets with MIT License | 4 votes |
private static void drawBeam(double xOffset, double yOffset, double zOffset, IVertexBuilder builder, Matrix4f positionMatrix, Matrix3f matrixNormalIn, float thickness, Hand hand, double distance, double v1, double v2, float ticks, float r, float g, float b, float alpha) { Vector3f vector3f = new Vector3f(0.0f, 1.0f, 0.0f); vector3f.transform(matrixNormalIn); ClientPlayerEntity player = Minecraft.getInstance().player; // Support for hand sides remembering to take into account of Skin options if( Minecraft.getInstance().gameSettings.mainHand != HandSide.RIGHT ) hand = hand == Hand.MAIN_HAND ? Hand.OFF_HAND : Hand.MAIN_HAND; float startXOffset = -0.25f; float startYOffset = -.115f; float startZOffset = 0.65f + (1 - player.getFovModifier()); if (hand == Hand.OFF_HAND) { startYOffset = -.120f; startXOffset = 0.25f; } float f = (MathHelper.lerp(ticks, player.prevRotationPitch, player.rotationPitch) - MathHelper.lerp(ticks, player.prevRenderArmPitch, player.renderArmPitch)); float f1 = (MathHelper.lerp(ticks, player.prevRotationYaw, player.rotationYaw) - MathHelper.lerp(ticks, player.prevRenderArmYaw, player.renderArmYaw)); startXOffset = startXOffset + (f1 / 100000000); startYOffset = startYOffset + (f / 100000000); Vector4f vec1 = new Vector4f(startXOffset, -thickness + startYOffset, startZOffset, 1.0F); vec1.transform(positionMatrix); Vector4f vec2 = new Vector4f((float) xOffset, -thickness + (float) yOffset, (float) distance + (float) zOffset, 1.0F); vec2.transform(positionMatrix); Vector4f vec3 = new Vector4f((float) xOffset, thickness + (float) yOffset, (float) distance + (float) zOffset, 1.0F); vec3.transform(positionMatrix); Vector4f vec4 = new Vector4f(startXOffset, thickness + startYOffset, startZOffset, 1.0F); vec4.transform(positionMatrix); if (hand == Hand.MAIN_HAND) { builder.addVertex(vec4.getX(), vec4.getY(), vec4.getZ(), r, g, b, alpha, 0, (float) v1, OverlayTexture.NO_OVERLAY, 15728880, vector3f.getX(), vector3f.getY(), vector3f.getZ()); builder.addVertex(vec3.getX(), vec3.getY(), vec3.getZ(), r, g, b, alpha, 0, (float) v2, OverlayTexture.NO_OVERLAY, 15728880, vector3f.getX(), vector3f.getY(), vector3f.getZ()); builder.addVertex(vec2.getX(), vec2.getY(), vec2.getZ(), r, g, b, alpha, 1, (float) v2, OverlayTexture.NO_OVERLAY, 15728880, vector3f.getX(), vector3f.getY(), vector3f.getZ()); builder.addVertex(vec1.getX(), vec1.getY(), vec1.getZ(), r, g, b, alpha, 1, (float) v1, OverlayTexture.NO_OVERLAY, 15728880, vector3f.getX(), vector3f.getY(), vector3f.getZ()); //Rendering a 2nd time to allow you to see both sides in multiplayer, shouldn't be necessary with culling disabled but here we are.... builder.addVertex(vec1.getX(), vec1.getY(), vec1.getZ(), r, g, b, alpha, 1, (float) v1, OverlayTexture.NO_OVERLAY, 15728880, vector3f.getX(), vector3f.getY(), vector3f.getZ()); builder.addVertex(vec2.getX(), vec2.getY(), vec2.getZ(), r, g, b, alpha, 1, (float) v2, OverlayTexture.NO_OVERLAY, 15728880, vector3f.getX(), vector3f.getY(), vector3f.getZ()); builder.addVertex(vec3.getX(), vec3.getY(), vec3.getZ(), r, g, b, alpha, 0, (float) v2, OverlayTexture.NO_OVERLAY, 15728880, vector3f.getX(), vector3f.getY(), vector3f.getZ()); builder.addVertex(vec4.getX(), vec4.getY(), vec4.getZ(), r, g, b, alpha, 0, (float) v1, OverlayTexture.NO_OVERLAY, 15728880, vector3f.getX(), vector3f.getY(), vector3f.getZ()); } else { builder.addVertex(vec1.getX(), vec1.getY(), vec1.getZ(), r, g, b, alpha, 1, (float) v1, OverlayTexture.NO_OVERLAY, 15728880, vector3f.getX(), vector3f.getY(), vector3f.getZ()); builder.addVertex(vec2.getX(), vec2.getY(), vec2.getZ(), r, g, b, alpha, 1, (float) v2, OverlayTexture.NO_OVERLAY, 15728880, vector3f.getX(), vector3f.getY(), vector3f.getZ()); builder.addVertex(vec3.getX(), vec3.getY(), vec3.getZ(), r, g, b, alpha, 0, (float) v2, OverlayTexture.NO_OVERLAY, 15728880, vector3f.getX(), vector3f.getY(), vector3f.getZ()); builder.addVertex(vec4.getX(), vec4.getY(), vec4.getZ(), r, g, b, alpha, 0, (float) v1, OverlayTexture.NO_OVERLAY, 15728880, vector3f.getX(), vector3f.getY(), vector3f.getZ()); //Rendering a 2nd time to allow you to see both sides in multiplayer, shouldn't be necessary with culling disabled but here we are.... builder.addVertex(vec4.getX(), vec4.getY(), vec4.getZ(), r, g, b, alpha, 0, (float) v1, OverlayTexture.NO_OVERLAY, 15728880, vector3f.getX(), vector3f.getY(), vector3f.getZ()); builder.addVertex(vec3.getX(), vec3.getY(), vec3.getZ(), r, g, b, alpha, 0, (float) v2, OverlayTexture.NO_OVERLAY, 15728880, vector3f.getX(), vector3f.getY(), vector3f.getZ()); builder.addVertex(vec2.getX(), vec2.getY(), vec2.getZ(), r, g, b, alpha, 1, (float) v2, OverlayTexture.NO_OVERLAY, 15728880, vector3f.getX(), vector3f.getY(), vector3f.getZ()); builder.addVertex(vec1.getX(), vec1.getY(), vec1.getZ(), r, g, b, alpha, 1, (float) v1, OverlayTexture.NO_OVERLAY, 15728880, vector3f.getX(), vector3f.getY(), vector3f.getZ()); } }