Jump to content

[1.7.2] Temporarily hijacking hotbar shortcuts?


Minothor

Recommended Posts

First off, sorry for the rather obscure title.

Secondly, does anyone know what would be the best way of achieving the following?

Handling a "hand" of cards rendered in first person view, making the active card switchable with keys 1-0 or with the mouse scroll.

The two major complications are these:

  • I want to allow players to quit the card game (and return shortcuts to normal) with escape.
  • I would also like to allow players to hit their chat key and type in a message to talk while playing.

The idea I'm toying with at the moment is using a custom Map renderer to render the cards held in the player's hands but how to selectively override hotbar keys is something I'm not quite sure off. it also feels a horrendously messy approach to GUI-less play.

 

If anyone has any suggestions as to a solution or a better method of play, I'm all ears!

Thanks in Advance.

Link to comment
Share on other sites

I think you can use keybinding and intercept key input events by using event handling and checking for the keys you care about and checking if you're currently in the minigame and then doing what you want.

 

Here is tutorial on keybinding, assuming you're using 1.7.2: http://www.minecraftforge.net/wiki/Key_Binding

 

You can find out more about event handling at my tutorial (and others out there, like CoolAlias'): http://jabelarminecraft.blogspot.com/p/minecraft-forge-172-event-handling.html

 

You'll want to handle the FML event called KeyInputEvent.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

cheers Jabelar, I'll try that now (and yes, I am using 1.7.2, sorry, updated the title now)

 

((EDIT: ADDENDUM: Also, sorry, but is there any simple way of getting the local client's player when the keyevent is fired or am I stuck with using a player tickhandler to listen for the relevant keys?))

Link to comment
Share on other sites

Ok, I've managed to get a somewhat hacky solution going, but I'm struggling to stop the hotbar from switching item slot.

Could anyone shed any light on how best to tackle this please?

(also, suggestions on optimising are more than welcome!)

package EmeraldCasino.events;


import java.awt.Event;

import org.lwjgl.input.Keyboard;

import net.minecraft.entity.player.*;
import cpw.mods.fml.client.registry.ClientRegistry;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.world.World;
import cpw.mods.fml.common.gameevent.InputEvent;
import cpw.mods.fml.common.gameevent.TickEvent.PlayerTickEvent;
import cpw.mods.fml.common.event.FMLEvent;
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.InputEvent.KeyInputEvent;

public class cardHandHandler {

private boolean sneaky=false;
private EntityPlayer localPlayer;

@SubscribeEvent(priority=EventPriority.HIGH, receiveCanceled=true)
public void onEvent(PlayerTickEvent e){
	if(e.player.isSneaking()){
		sneaky=true;
		if(localPlayer==null)
			localPlayer=e.player;
	} else {
		sneaky = false;
	}
}

@SubscribeEvent(priority=EventPriority.HIGHEST, receiveCanceled=true)
public void onEvent(InputEvent.KeyInputEvent e)
{
	if(sneaky){
	int index=-1;
	int invSlot=localPlayer.inventory.currentItem;
	switch(Keyboard.getEventKey()){
	case Keyboard.KEY_1: index = 1; break;
	case Keyboard.KEY_2: index = 2; break;
	}
	if(index>=0){
		System.out.println(""+index+" Pressed");
	}
	localPlayer.inventory.changeCurrentItem(invSlot);
	}
}
}

Link to comment
Share on other sites

Is the lack of GUI a necessity...e.g. do you want the player to be able to move-around?

 

The easiest solution that I could think of (if an immobile player was okay) would be to actually use  a GUI -- as that provides a central place to intercept key events...and if you don't have slots in your container, then no slot-selection/item moving will happen.  And you don't -have- to draw anything in the GUI, so it could be transparent...the player just wouldn't be able to move while it were open, and would have a mouse cursor on their screen.

 

 

Getting the local client has always been as easy as calling Mincraft.getMinecraft.thePlayer

Keep in mind, that needs to be called from behind a client-side proxy (like other input handling), or things will crash when deployed on server

Link to comment
Share on other sites

cheers for the reply and the easy player method, don't worry, I'll side it appropiately.

Concerning GUIs, simply put, no it's not a necessity and it would help with things like locking the player in place.

My main issue is that GUIs can be unplayably small. I also quite liked the visual aesthetic of first person view and people swinging their arm to play their chosen cards.

I'll revert to a GUI if there's no other way, but I'll try the cardHand item's left/right click functions with a sneaking toggle first.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
    • It is an issue with quark - update it to this build: https://www.curseforge.com/minecraft/mc-mods/quark/files/3642325
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.