本文整理汇总了Java中net.minecraft.client.gui.inventory.GuiContainer.getSlotUnderMouse方法的典型用法代码示例。如果您正苦于以下问题:Java GuiContainer.getSlotUnderMouse方法的具体用法?Java GuiContainer.getSlotUnderMouse怎么用?Java GuiContainer.getSlotUnderMouse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.client.gui.inventory.GuiContainer
的用法示例。
在下文中一共展示了GuiContainer.getSlotUnderMouse方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: preKeyboardInput
import net.minecraft.client.gui.inventory.GuiContainer; //导入方法依赖的package包/类
@SubscribeEvent
public void preKeyboardInput(GuiScreenEvent.KeyboardInputEvent.Pre event) {
if (event.getGui() instanceof GuiContainer && playerHasBook()) {
GuiContainer gui = (GuiContainer) event.getGui();
Slot slot = gui.getSlotUnderMouse();
if (slot != null && slot.getHasStack()) {
if (Keyboard.getEventKey() == ProxyClient.recipeKey.getKeyCode() && RecipeManager.hasRecipes(slot.getStack())) {
GuideBookGui.onOpenCmd = "recipe";
GuideBookGui.onOpenArg = slot.getStack();
Minecraft.getMinecraft().player.openGui(GuideBookMod.instance, 0, Minecraft.getMinecraft().world, 0, 0, 0);
}
else if(Keyboard.getEventKey() == ProxyClient.usageKey.getKeyCode() && RecipeManager.hasUsages(slot.getStack())) {
GuideBookGui.onOpenCmd = "usage";
GuideBookGui.onOpenArg = slot.getStack();
Minecraft.getMinecraft().player.openGui(GuideBookMod.instance, 0, Minecraft.getMinecraft().world, 0, 0, 0);
}
}
}
}
示例2: onTick
import net.minecraft.client.gui.inventory.GuiContainer; //导入方法依赖的package包/类
@SubscribeEvent
public void onTick(TickEvent event) {
if (mc.currentScreen != null && mc.currentScreen instanceof GuiContainer) {
GuiContainer container = (GuiContainer) mc.currentScreen;
if (Keyboard.isKeyDown(ClientProxy.craftinggui.getKeyCode())) {
if (!openpressed) {
openpressed = true;
if (container.getSlotUnderMouse() != null) {
Slot slot = container.getSlotUnderMouse();
if (slot.getStack() != null) {
ItemStack stack = slot.getStack();
for (CommonGuiRecipe guirecipe : ClientRegistryUtil.getGuirecipes()) {
if (guirecipe.getRecipeOutput() != null && guirecipe.getRecipeOutput().isItemEqual(stack)) {
mc.displayGuiScreen(new GuiCraftingRecipes(guirecipe.getRecipeOutput(), guirecipe.getRecipeInput(), mc.currentScreen));
break;
}
}
}
}
}
} else {
openpressed = false;
}
}
}
示例3: storeSourceSlotCandidate
import net.minecraft.client.gui.inventory.GuiContainer; //导入方法依赖的package包/类
/**
* Store a reference to the slot when a slot is left or right clicked on.
* The slot is then later used to determine which inventory an ItemStack was
* picked up from, if the stack from the cursor is dropped while holding shift.
*/
private void storeSourceSlotCandidate(GuiContainer gui)
{
// Left or right mouse button was pressed
if (Mouse.getEventButtonState() && (Mouse.getEventButton() == 0 || Mouse.getEventButton() == 1))
{
Slot slot = gui.getSlotUnderMouse();
if (slot != null)
{
ItemStack stackCursor = gui.mc.player.inventory.getItemStack();
ItemStack stack = InventoryUtils.EMPTY_STACK;
if (InventoryUtils.isStackEmpty(stackCursor) == false)
{
// Do a cheap copy without NBT data
stack = new ItemStack(stackCursor.getItem(), InventoryUtils.getStackSize(stackCursor), stackCursor.getMetadata());
}
this.stackInCursorLast = stack;
this.sourceSlotCandidate = new WeakReference<Slot>(slot);
}
}
}
示例4: buttonDown
import net.minecraft.client.gui.inventory.GuiContainer; //导入方法依赖的package包/类
public boolean buttonDown(Pair<Float,Float> input) {
GuiContainer gui = (GuiContainer) Minecraft.getMinecraft().currentScreen;
if(gui == null) return true;
Slot cs = gui.getSlotUnderMouse();
int xStart, yStart;
if(cs == null) {
xStart = Mouse.getEventX() * gui.width / Minecraft.getMinecraft().displayWidth;
yStart = gui.height - Mouse.getEventY() * gui.height / Minecraft.getMinecraft().displayHeight - 1;
} else {
xStart = cs.xPos + gui.getGuiLeft();
yStart = cs.yPos + gui.getGuiTop();
}
float x = input.getLeft();
float y = input.getRight();
Slot newSlot = null;
if(Direction.UP.isTriggered(x, y)) {
newSlot = search(gui, xStart + (SLOT_WIDTH / 2), yStart, 0, -SLOT_WIDTH, SLOT_WIDTH/2, 0);
} else if(Direction.DOWN.isTriggered(x, y)) {
newSlot = search(gui, xStart + SLOT_WIDTH / 2, yStart + SLOT_WIDTH, 0, SLOT_WIDTH, SLOT_WIDTH/2, 0);
} else if(Direction.LEFT.isTriggered(x, y)) {
newSlot = search(gui, xStart, yStart + SLOT_WIDTH / 2, -SLOT_WIDTH, 0, 0, SLOT_WIDTH/2);
} else if(Direction.RIGHT.isTriggered(x, y)){
newSlot = search(gui, xStart + SLOT_WIDTH, yStart + SLOT_WIDTH / 2, SLOT_WIDTH, 0, 0, SLOT_WIDTH/2);
}
if(newSlot != null) {
ActionEmulationHelper.moveMouseInGui(newSlot.xPos + SLOT_WIDTH / 2 + gui.getGuiLeft(), newSlot.yPos + SLOT_WIDTH / 2 + gui.getGuiTop(), gui.width, gui.height);
}
return true;
}
示例5: onRightClick
import net.minecraft.client.gui.inventory.GuiContainer; //导入方法依赖的package包/类
@SubscribeEvent
public void onRightClick(GuiScreenEvent.MouseInputEvent event)
{
if (event.getGui() instanceof GuiContainer && Mouse.isButtonDown(1))
{
GuiContainer container = (GuiContainer) event.getGui();
if (container.getSlotUnderMouse() != null
&& Minecraft.getMinecraft().player.inventory.getItemStack().isEmpty()
&& container.getSlotUnderMouse().getStack().getItem() == QBarItems.MULTIBLOCK_BOX)
{
new MultiblockBoxPacket(container.getSlotUnderMouse().slotNumber).sendToServer();
event.setCanceled(true);
}
}
}
示例6: shiftPlaceItems
import net.minecraft.client.gui.inventory.GuiContainer; //导入方法依赖的package包/类
private boolean shiftPlaceItems(GuiContainer gui)
{
Slot slot = gui.getSlotUnderMouse();
// Left click to place the items from the cursor to the slot
InventoryUtils.leftClickSlot(gui, slot.slotNumber);
// Ugly fix to prevent accidentally drag-moving the stack from the slot that it was just placed into...
this.draggedSlots.add(slot.slotNumber);
InventoryUtils.tryMoveStacks(slot, gui, true, false, false);
return true;
}
示例7: canShiftPlaceItems
import net.minecraft.client.gui.inventory.GuiContainer; //导入方法依赖的package包/类
public static boolean canShiftPlaceItems(GuiContainer gui)
{
if (GuiScreen.isShiftKeyDown() == false || Mouse.getEventButton() != 0)
{
return false;
}
Slot slot = gui.getSlotUnderMouse();
ItemStack stackCursor = gui.mc.player.inventory.getItemStack();
// The target slot needs to be an empty, valid slot, and there needs to be items in the cursor
return slot != null && isStackEmpty(stackCursor) == false && isValidSlot(slot, gui, false) &&
slot.getHasStack() == false && slot.isItemValid(stackCursor);
}
示例8: storeOrLoadRecipe
import net.minecraft.client.gui.inventory.GuiContainer; //导入方法依赖的package包/类
public static void storeOrLoadRecipe(GuiContainer gui, int index)
{
Slot slot = gui.getSlotUnderMouse();
RecipeStorage recipes = InputEventHandler.instance().getRecipes();
// A crafting output slot with a stack under the cursor, store a recipe
if (GuiScreen.isShiftKeyDown() && slot != null && isCraftingSlot(gui, slot))
{
if (slot.getHasStack())
{
recipes.storeCraftingRecipe(index, gui, slot);
}
else
{
recipes.clearRecipe(index);
}
}
// Not a crafting output slot with a stack, load a stored recipe
else
{
recipes.changeSelectedRecipe(index);
if (slot != null && isStackEmpty(recipes.getSelectedRecipe().getResult()) == false)
{
tryMoveItemsToCraftingGridSlots(gui, slot, recipes, false);
}
}
}
示例9: rightClickCraftOneStack
import net.minecraft.client.gui.inventory.GuiContainer; //导入方法依赖的package包/类
public static void rightClickCraftOneStack(GuiContainer gui)
{
Slot slot = gui.getSlotUnderMouse();
InventoryPlayer inv = gui.mc.player.inventory;
ItemStack stackCursor = inv.getItemStack();
if (slot == null || slot.getHasStack() == false ||
(isStackEmpty(stackCursor) == false) && areStacksEqual(slot.getStack(), stackCursor) == false)
{
return;
}
int sizeLast = 0;
while (true)
{
rightClickSlot(gui, slot.slotNumber);
stackCursor = inv.getItemStack();
// Failed to craft items, or the stack became full, or ran out of ingredients
if (isStackEmpty(stackCursor) || getStackSize(stackCursor) <= sizeLast ||
getStackSize(stackCursor) >= stackCursor.getMaxStackSize() ||
areStacksEqual(slot.getStack(), stackCursor) == false)
{
break;
}
sizeLast = getStackSize(stackCursor);
}
}
示例10: onKeyInputEventPre
import net.minecraft.client.gui.inventory.GuiContainer; //导入方法依赖的package包/类
@SubscribeEvent
public void onKeyInputEventPre(GuiScreenEvent.KeyboardInputEvent.Pre event)
{
if ((event.getGui() instanceof GuiContainer) == false ||
event.getGui().mc == null || event.getGui().mc.player == null)
{
return;
}
GuiContainer gui = (GuiContainer) event.getGui();
if (Keyboard.getEventKey() == Keyboard.KEY_I && Keyboard.getEventKeyState() &&
GuiScreen.isAltKeyDown() && GuiScreen.isCtrlKeyDown() && GuiScreen.isShiftKeyDown())
{
if (gui.getSlotUnderMouse() != null)
{
debugPrintSlotInfo(gui, gui.getSlotUnderMouse());
}
else
{
ItemScroller.logger.info("GUI class: {}", gui.getClass().getName());
}
}
// Drop all matching stacks from the same inventory when pressing Ctrl + Shift + Drop key
else if (Configs.enableControlShiftDropkeyDropItems && Keyboard.getEventKeyState() &&
Configs.GUI_BLACKLIST.contains(gui.getClass().getName()) == false &&
GuiScreen.isCtrlKeyDown() && GuiScreen.isShiftKeyDown() &&
gui.mc.gameSettings.keyBindDrop.isActiveAndMatches(Keyboard.getEventKey()))
{
Slot slot = gui.getSlotUnderMouse();
if (slot != null && slot.getHasStack())
{
InventoryUtils.dropStacks(gui, slot.getStack(), slot);
}
}
// Toggle mouse functionality on/off
else if (Keyboard.getEventKeyState() && ClientProxy.KEY_DISABLE.isActiveAndMatches(Keyboard.getEventKey()))
{
this.disabled = ! this.disabled;
if (this.disabled)
{
gui.mc.player.playSound(SoundEvents.BLOCK_NOTE_BASS, 0.8f, 0.8f);
}
else
{
gui.mc.player.playSound(SoundEvents.BLOCK_NOTE_PLING, 0.5f, 1.0f);
}
}
// Show or hide the recipe selection
else if (Keyboard.getEventKey() == ClientProxy.KEY_RECIPE.getKeyCode())
{
if (Keyboard.getEventKeyState())
{
RenderEventHandler.setRenderStoredRecipes(true);
}
else
{
RenderEventHandler.setRenderStoredRecipes(false);
}
}
// Store or load a recipe
else if (Keyboard.getEventKeyState() && Keyboard.isKeyDown(ClientProxy.KEY_RECIPE.getKeyCode()) &&
Keyboard.getEventKey() >= Keyboard.KEY_1 && Keyboard.getEventKey() <= Keyboard.KEY_9)
{
int index = MathHelper.clamp(Keyboard.getEventKey() - Keyboard.KEY_1, 0, 8);
InventoryUtils.storeOrLoadRecipe(gui, index);
event.setCanceled(true);
}
}