Search in sources :

Example 96 with EnumHand

use of net.minecraft.util.EnumHand in project baritone by cabaletta.

the class BlockPlaceHelper method tick.

public void tick(boolean rightClickRequested) {
    if (rightClickTimer > 0) {
        rightClickTimer--;
        return;
    }
    RayTraceResult mouseOver = ctx.objectMouseOver();
    if (!rightClickRequested || ctx.player().isRowingBoat() || mouseOver == null || mouseOver.getBlockPos() == null || mouseOver.typeOfHit != RayTraceResult.Type.BLOCK) {
        return;
    }
    rightClickTimer = Baritone.settings().rightClickSpeed.value;
    for (EnumHand hand : EnumHand.values()) {
        if (ctx.playerController().processRightClickBlock(ctx.player(), ctx.world(), mouseOver.getBlockPos(), mouseOver.sideHit, mouseOver.hitVec, hand) == EnumActionResult.SUCCESS) {
            ctx.player().swingArm(hand);
            return;
        }
        if (!ctx.player().getHeldItem(hand).isEmpty() && ctx.playerController().processRightClick(ctx.player(), ctx.world(), hand) == EnumActionResult.SUCCESS) {
            return;
        }
    }
}
Also used : EnumHand(net.minecraft.util.EnumHand) RayTraceResult(net.minecraft.util.math.RayTraceResult)

Example 97 with EnumHand

use of net.minecraft.util.EnumHand in project nebula by Sxmurai.

the class SelfFill method onActivated.

@Override
protected void onActivated() {
    BlockPos pos = new BlockPos(mc.player.posX, mc.player.posY, mc.player.posZ);
    // if we are already burrowed
    if (!mc.world.getCollisionBoxes(mc.player, new AxisAlignedBB(pos)).isEmpty()) {
        disable();
        return;
    }
    int slot = InventoryUtil.getSlot(InventorySpace.HOTBAR, (s) -> s.getItem() instanceof ItemBlock && ((ItemBlock) s.getItem()).getBlock().equals(mode.getValue().block));
    if (slot == -1) {
        disable();
        return;
    }
    EnumHand hand = slot == InventoryUtil.OFFHAND_SLOT ? EnumHand.OFF_HAND : EnumHand.MAIN_HAND;
    int oldSlot = -1;
    if (hand.equals(EnumHand.MAIN_HAND)) {
        oldSlot = mc.player.inventory.currentItem;
        getNebula().getHotbarManager().sendSlotChange(slot, swap.getValue());
    }
    for (double offset : FAKE_JUMP) {
        mc.player.connection.sendPacket(new Position(mc.player.posX, pos.getY() + offset, mc.player.posZ, false));
    }
    getNebula().getInteractionManager().placeBlock(pos, hand, rotate.getValue(), swing.getValue());
    if (flag.getValue()) {
        mc.player.connection.sendPacket(new Position(mc.player.posX, pos.getY() + 2.3, mc.player.posZ, false));
    } else {
        if (!mc.world.getBlockState(pos).getMaterial().isReplaceable()) {
            mc.player.setPosition(pos.getX(), pos.getY() + 1.0, pos.getZ());
        }
    }
    if (oldSlot != -1) {
        getNebula().getHotbarManager().sendSlotChange(oldSlot, swap.getValue());
    }
    disable();
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Position(net.minecraft.network.play.client.CPacketPlayer.Position) EnumHand(net.minecraft.util.EnumHand) BlockPos(net.minecraft.util.math.BlockPos) ItemBlock(net.minecraft.item.ItemBlock)

Example 98 with EnumHand

use of net.minecraft.util.EnumHand in project GregTech by GregTechCEu.

the class PlayerInventoryUIFactory method readHolderFromSyncData.

@Override
@SideOnly(Side.CLIENT)
protected PlayerInventoryHolder readHolderFromSyncData(PacketBuffer syncData) {
    EntityPlayer entityPlayer = Minecraft.getMinecraft().player;
    EnumHand enumHand = EnumHand.values()[syncData.readByte()];
    ItemStack itemStack;
    try {
        itemStack = syncData.readItemStack();
    } catch (IOException exception) {
        throw new RuntimeException(exception);
    }
    return new PlayerInventoryHolder(entityPlayer, enumHand, itemStack);
}
Also used : EnumHand(net.minecraft.util.EnumHand) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IOException(java.io.IOException) ItemStack(net.minecraft.item.ItemStack) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 99 with EnumHand

use of net.minecraft.util.EnumHand in project Lands-of-Icaria by Axanthic-Game-Studios.

the class LOIItemStackRenderer method renderByItem.

public void renderByItem(ItemStack stack, float partialTicks) {
    Item item = stack.getItem();
    if (item instanceof ItemBlockMobHead) {
        if (TileEntitySpecialRendererMobHead.instance != null) {
            GlStateManager.pushMatrix();
            GlStateManager.disableCull();
            TileEntitySpecialRendererMobHead.instance.renderSkull(0.0F, 0.1F, 0.0F, EnumFacing.DOWN, 0.0F, ((BlockMobHead) ((ItemBlock) item).getBlock()).name, -1, 1.6F);
            GlStateManager.enableCull();
            GlStateManager.popMatrix();
        }
    }
    if (item instanceof ItemSaltedFood) {
        GlStateManager.pushMatrix();
        GlStateManager.translate(0.5F, 0.5F, 0.5F);
        if (stack.hasTagCompound()) {
            ItemStack foodStack = ItemSaltedFood.getContainedItem(stack.getTagCompound());
            if (!foodStack.isEmpty())
                Minecraft.getMinecraft().getRenderItem().renderItem(foodStack, ItemCameraTransforms.TransformType.NONE);
        }
        Minecraft.getMinecraft().getRenderItem().renderItem(saltOverlay, ItemCameraTransforms.TransformType.NONE);
        GlStateManager.popMatrix();
    }
    if (item instanceof ItemBlock && ((ItemBlock) item).getBlock() instanceof BlockGrinder) {
        if (TileEntitySpecialRendererGrinder.instance != null) {
            GlStateManager.pushMatrix();
            GlStateManager.disableCull();
            TileEntitySpecialRendererGrinder.instance.renderInventory();
            GlStateManager.enableCull();
            GlStateManager.popMatrix();
        }
    }
    if (item instanceof ItemScroll) {
        ItemScroll scroll = ((ItemScroll) item);
        if (!Minecraft.getMinecraft().player.isInvisible()) {
            EnumHand rightHand = EnumHand.MAIN_HAND;
            EnumHand leftHand = EnumHand.OFF_HAND;
            if (Minecraft.getMinecraft().player.getPrimaryHand() == EnumHandSide.LEFT) {
                rightHand = EnumHand.OFF_HAND;
                leftHand = EnumHand.MAIN_HAND;
            }
            // render player arms
            if (BakedModelScroll.transform == TransformType.FIRST_PERSON_RIGHT_HAND) {
                GlStateManager.translate(((float) Minecraft.getMinecraft().displayWidth) / ((float) Minecraft.getMinecraft().displayHeight) * 0.5F, 0.9F, 0.4F);
                GlStateManager.disableCull();
                GlStateManager.pushMatrix();
                GlStateManager.rotate(90.0F, 0.0F, 1.0F, 0.0F);
                if (Minecraft.getMinecraft().player.getHeldItem(leftHand).isEmpty() && rightHand != EnumHand.OFF_HAND)
                    renderArm(EnumHandSide.LEFT);
                GlStateManager.translate(0.0F, 0.3F, -0.7F);
                GlStateManager.rotate(-60.0F, 1.0F, 0.0F, 0.0F);
                renderArm(EnumHandSide.RIGHT);
                GlStateManager.popMatrix();
                GlStateManager.enableCull();
            }
            if (BakedModelScroll.transform == TransformType.FIRST_PERSON_LEFT_HAND) {
                GlStateManager.translate(((float) Minecraft.getMinecraft().displayWidth) / ((float) Minecraft.getMinecraft().displayHeight) * -0.5F + 1.68F, 0.9F, 0.4F);
                GlStateManager.disableCull();
                GlStateManager.pushMatrix();
                GlStateManager.rotate(90.0F, 0.0F, 1.0F, 0.0F);
                GlStateManager.translate(-0.1F, 0.03F, -0.7F);
                if (Minecraft.getMinecraft().player.getHeldItem(rightHand).isEmpty() && leftHand != EnumHand.OFF_HAND)
                    renderArm(EnumHandSide.RIGHT);
                GlStateManager.translate(0.1F, 0.27F, 0.7F);
                GlStateManager.rotate(60.0F, 1.0F, 0.0F, 0.0F);
                renderArm(EnumHandSide.LEFT);
                GlStateManager.popMatrix();
                GlStateManager.enableCull();
            }
        }
        // render scroll background
        GlStateManager.scale(0.76F, 0.76F, 0.76F);
        GlStateManager.disableLighting();
        Minecraft.getMinecraft().getTextureManager().bindTexture(RES_SCROLL_BACKGROUND);
        Tessellator tessellator = Tessellator.getInstance();
        BufferBuilder bufferbuilder = tessellator.getBuffer();
        GlStateManager.translate(-1.0F, -0.6F, -0.2F);
        GlStateManager.scale(0.0078125F, 0.0078125F, 0.0078125F);
        bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX);
        bufferbuilder.pos(0.0D, 0.0D, 0.0D).tex(0.0D, 1.0D).endVertex();
        bufferbuilder.pos(142.0D, 0.0D, 0.0D).tex(1.0D, 1.0D).endVertex();
        bufferbuilder.pos(142.0D, 142.0D, 0.0D).tex(1.0D, 0.0D).endVertex();
        bufferbuilder.pos(0.0D, 142.0D, 0.0D).tex(0.0D, 0.0D).endVertex();
        tessellator.draw();
        GlStateManager.translate(71.0F, 44.5F, 0.01F);
        // render scroll title
        GlStateManager.pushMatrix();
        GlStateManager.rotate(180.0F, 1.0F, 0.0F, 0.0F);
        FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
        String title = I18n.translateToLocal("spell." + scroll.getName() + ".name");
        fontRenderer.drawString(title, -fontRenderer.getStringWidth(title) / 2, -60, 0x82735A);
        GlStateManager.popMatrix();
        GlStateManager.scale(25.0F, 25.0F, 0.001F);
        // render ingredients
        Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
        GlStateManager.pushMatrix();
        GlStateManager.scale(0.6F, 0.6F, 1.0F);
        GlStateManager.translate(0.55F - scroll.getRecipe().order.size() * 0.55F, 2.5F, 0.0F);
        for (int i = 0; i < scroll.getRecipe().order.size(); ++i) {
            Minecraft.getMinecraft().getRenderItem().renderItem(scroll.getRecipe().getInputs().get(scroll.getRecipe().order.get(i)).getMatchingStacks()[0], ItemCameraTransforms.TransformType.GUI);
            GlStateManager.translate(1.1F, 0.0F, 0.0F);
        }
        GlStateManager.popMatrix();
        // render result
        Minecraft.getMinecraft().getRenderItem().renderItem(scroll.getRecipe().recipeOutput, ItemCameraTransforms.TransformType.GUI);
        GlStateManager.enableLighting();
    }
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) BlockGrinder(com.axanthic.loi.blocks.BlockGrinder) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) ItemBlock(net.minecraft.item.ItemBlock) Item(net.minecraft.item.Item) ItemBlockMobHead(com.axanthic.loi.items.ItemBlockMobHead) EnumHand(net.minecraft.util.EnumHand) ItemSaltedFood(com.axanthic.loi.items.ItemSaltedFood) FontRenderer(net.minecraft.client.gui.FontRenderer) ItemStack(net.minecraft.item.ItemStack) ItemScroll(com.axanthic.loi.items.ItemScroll)

Example 100 with EnumHand

use of net.minecraft.util.EnumHand in project ProjectE by sinkillerj.

the class GuiHandler method getClientGuiElement.

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
    TileEntity tile = !ITEM_IDS.contains(ID) ? world.getTileEntity(new BlockPos(x, y, z)) : null;
    // if not a TE, x will hold which hand it came from. 1 for off, 0 otherwise
    EnumHand hand = ITEM_IDS.contains(ID) ? (x == 1 ? EnumHand.OFF_HAND : EnumHand.MAIN_HAND) : null;
    switch(ID) {
        case Constants.ALCH_CHEST_GUI:
            if (tile != null && tile instanceof AlchChestTile)
                return new GUIAlchChest(player.inventory, (AlchChestTile) tile);
            break;
        case Constants.ALCH_BAG_GUI:
            {
                EnumDyeColor color = EnumDyeColor.byMetadata(player.getHeldItem(hand).getItemDamage());
                IItemHandlerModifiable inventory = (IItemHandlerModifiable) player.getCapability(ProjectEAPI.ALCH_BAG_CAPABILITY, null).getBag(color);
                return new GUIAlchChest(player.inventory, hand, inventory);
            }
        case Constants.CONDENSER_GUI:
            if (tile != null && tile instanceof CondenserTile)
                return new GUICondenser(player.inventory, (CondenserTile) tile);
            break;
        case Constants.TRANSMUTE_STONE_GUI:
            return new GUITransmutation(player.inventory, new TransmutationInventory(player), null);
        case Constants.RM_FURNACE_GUI:
            if (tile != null && tile instanceof RMFurnaceTile)
                return new GUIRMFurnace(player.inventory, (RMFurnaceTile) tile);
            break;
        case Constants.DM_FURNACE_GUI:
            if (tile != null && tile instanceof DMFurnaceTile)
                return new GUIDMFurnace(player.inventory, (DMFurnaceTile) tile);
            break;
        case Constants.COLLECTOR1_GUI:
            if (tile != null && tile instanceof CollectorMK1Tile)
                return new GUICollectorMK1(player.inventory, (CollectorMK1Tile) tile);
            break;
        case Constants.COLLECTOR2_GUI:
            if (tile != null && tile instanceof CollectorMK2Tile)
                return new GUICollectorMK2(player.inventory, (CollectorMK2Tile) tile);
            break;
        case Constants.COLLECTOR3_GUI:
            if (tile != null && tile instanceof CollectorMK3Tile)
                return new GUICollectorMK3(player.inventory, (CollectorMK3Tile) tile);
            break;
        case Constants.RELAY1_GUI:
            if (tile != null && tile instanceof RelayMK1Tile)
                return new GUIRelayMK1(player.inventory, (RelayMK1Tile) tile);
            break;
        case Constants.RELAY2_GUI:
            if (tile != null && tile instanceof RelayMK2Tile)
                return new GUIRelayMK2(player.inventory, (RelayMK2Tile) tile);
            break;
        case Constants.RELAY3_GUI:
            if (tile != null && tile instanceof RelayMK3Tile)
                return new GUIRelayMK3(player.inventory, (RelayMK3Tile) tile);
            break;
        case Constants.MERCURIAL_GUI:
            return new GUIMercurialEye(player.inventory, new MercurialEyeInventory(player.getHeldItem(hand)));
        case Constants.PHILOS_STONE_GUI:
            return new GUIPhilosStone(player.inventory);
        case Constants.TRANSMUTATION_GUI:
            return new GUITransmutation(player.inventory, new TransmutationInventory(player), hand);
        case Constants.ETERNAL_DENSITY_GUI:
            return new GUIEternalDensity(player.inventory, new EternalDensityInventory(player.getHeldItem(hand), player));
        case Constants.CONDENSER_MK2_GUI:
            return new GUICondenserMK2(player.inventory, (CondenserMK2Tile) tile);
    }
    return null;
}
Also used : AlchChestTile(moze_intel.projecte.gameObjs.tiles.AlchChestTile) GUIRMFurnace(moze_intel.projecte.gameObjs.gui.GUIRMFurnace) GUITransmutation(moze_intel.projecte.gameObjs.gui.GUITransmutation) GUIMercurialEye(moze_intel.projecte.gameObjs.gui.GUIMercurialEye) CollectorMK3Tile(moze_intel.projecte.gameObjs.tiles.CollectorMK3Tile) RelayMK2Tile(moze_intel.projecte.gameObjs.tiles.RelayMK2Tile) TileEntity(net.minecraft.tileentity.TileEntity) GUIAlchChest(moze_intel.projecte.gameObjs.gui.GUIAlchChest) IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) TransmutationInventory(moze_intel.projecte.gameObjs.container.inventory.TransmutationInventory) EnumHand(net.minecraft.util.EnumHand) GUIEternalDensity(moze_intel.projecte.gameObjs.gui.GUIEternalDensity) CondenserTile(moze_intel.projecte.gameObjs.tiles.CondenserTile) MercurialEyeInventory(moze_intel.projecte.gameObjs.container.inventory.MercurialEyeInventory) CollectorMK2Tile(moze_intel.projecte.gameObjs.tiles.CollectorMK2Tile) BlockPos(net.minecraft.util.math.BlockPos) GUICondenser(moze_intel.projecte.gameObjs.gui.GUICondenser) RelayMK1Tile(moze_intel.projecte.gameObjs.tiles.RelayMK1Tile) GUICollectorMK1(moze_intel.projecte.gameObjs.gui.GUICollectorMK1) GUICollectorMK2(moze_intel.projecte.gameObjs.gui.GUICollectorMK2) GUICollectorMK3(moze_intel.projecte.gameObjs.gui.GUICollectorMK3) EternalDensityInventory(moze_intel.projecte.gameObjs.container.inventory.EternalDensityInventory) GUIPhilosStone(moze_intel.projecte.gameObjs.gui.GUIPhilosStone) GUICondenserMK2(moze_intel.projecte.gameObjs.gui.GUICondenserMK2) DMFurnaceTile(moze_intel.projecte.gameObjs.tiles.DMFurnaceTile) CollectorMK1Tile(moze_intel.projecte.gameObjs.tiles.CollectorMK1Tile) EnumDyeColor(net.minecraft.item.EnumDyeColor) RMFurnaceTile(moze_intel.projecte.gameObjs.tiles.RMFurnaceTile) GUIDMFurnace(moze_intel.projecte.gameObjs.gui.GUIDMFurnace) GUIRelayMK1(moze_intel.projecte.gameObjs.gui.GUIRelayMK1) RelayMK3Tile(moze_intel.projecte.gameObjs.tiles.RelayMK3Tile) GUIRelayMK2(moze_intel.projecte.gameObjs.gui.GUIRelayMK2) GUIRelayMK3(moze_intel.projecte.gameObjs.gui.GUIRelayMK3)

Aggregations

EnumHand (net.minecraft.util.EnumHand)117 ItemStack (net.minecraft.item.ItemStack)62 EntityPlayer (net.minecraft.entity.player.EntityPlayer)55 BlockPos (net.minecraft.util.math.BlockPos)45 EnumFacing (net.minecraft.util.EnumFacing)32 Vec3d (net.minecraft.util.math.Vec3d)24 World (net.minecraft.world.World)24 Entity (net.minecraft.entity.Entity)23 RayTraceResult (net.minecraft.util.math.RayTraceResult)21 EntityLivingBase (net.minecraft.entity.EntityLivingBase)19 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)19 Item (net.minecraft.item.Item)18 CPacketPlayerTryUseItemOnBlock (net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock)18 IBlockState (net.minecraft.block.state.IBlockState)17 TileEntity (net.minecraft.tileentity.TileEntity)16 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)15 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)14 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)13 List (java.util.List)12 Block (net.minecraft.block.Block)11