Hi, for some reason it gives me an error at the line in the 1.7.2 keybind code that says "public KeyHandler()". When I hover over it, it says: "Return type for the method is missing" and recommends that I change it to a void or constructor.
Hi, for some reason it gives me an error at the line in the 1.7.2 keybind code that says "public KeyHandler()". When I hover over it, it says: "Return type for the method is missing" and recommends that I change it to a void or constructor.
Well, you must have named your class differently, because that is supposed to be the constructor. So change it to the constructor.
I have managed to get the keybind to work in 1.7.2 but how do I open a GUI with it? I need the EntityPlayer and World to do so. I tried the ITickHandler thing but that doesnt exist in 1.7.2.
I have managed to get the keybind to work in 1.7.2 but how do I open a GUI with it? I need the EntityPlayer and World to do so. I tried the ITickHandler thing but that doesnt exist in 1.7.2.
A mod that I am currently working on uses a keybinding to open an overlay. Here is the repo, search around a bit.
How would i make so that when i press the key it adds motion to a custom entity?
Send a packet to the server with the entity id, then on the server side get the entity by id from the world and entity.motionX += amount, etc. If your custom entity is registered properly, the motion updates will be sent automatically for nearby clients (players) to see.
In 1.6 the keybinding method has key up and key down witch makes it so you can press the button and let's say keep moving upwards,(my goal was to make a jetpack) but now in 1.7 the method only activates each time you press the button, is there a method for 1.7 that makes it so i can keep pressing my button and the player keeps moving upwards?
[yourkey].isPressed() should return true so long as the key is held down, e.g. keys[CUSTOM_INV].isPressed()
I'm having the same problem, that doesn't work. It only activates once, and than you need to press it again.
You have to check the key outside of the KeyInputEvent, as that ONLY fires when a key is actually pressed down; if you put [custom_key].isPressed() in, say, a TickEvent, it would continue to return true so long as you held the key down, and you could do whatever you want from there.
I'm trying to make it so that if i press "R" while I'm holding my mod bow it turns into my mod sword, any idea how I would do that? I'm pretty sure that i need this class to do it but I'm not completely sure. (Very beginner modder here if you couldn't tell)
My Keyhandler works the problem is, how do i access the backpack when it is in a armorslot? I tried it with checking and that stuff. It goes through all the if's and print out:
player
not holding
in armor slot
armoritem in slot
right item
armor slot/Client
but in the end it doesnt open ._.
public class GuiHandler implements IGuiHandler
{
private Minecraft mc;
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
TileEntity tileEntity = world.getTileEntity(x, y, z);
mc = Minecraft.getMinecraft();
switch(ID)
{
case 0: return ID == 0 ? new ContainerAltar(player.inventory, (TileEntityAltar) tileEntity) : null;
case 2: return ID == 2 ? new ContainerCobaltFurnace(player.inventory, (TileEntityCobaltFurnace) tileEntity) : null;
case 3: return ID == 3 ? new ContainerRitualStone(player.inventory, (TileEntityRitualStone) tileEntity) : null;
case 4: return ID == 4 && world.getBlock(x, y, z) == CMStuff.cobexworkbench ? new ContainerBlueWoodWorkBench(player.inventory, world, x, y, z) : null;
case 5:
if (player != null) {
System.out.println("player");
if (player.getHeldItem() != null) {
System.out.println("hold in hands");
if (player.getHeldItem().getItem() == CMStuff.cobaltbackpack) {
System.out.println("right item in Hands");
System.out.println("hands/Server");
return ID == 5 ? new ContainerBackpack(player, player.inventory, new InventoryBackpack(player.getHeldItem())) : null;
}
}
else if(armor[2] != null)
{
System.out.println("not holding");
System.out.println("in armor slot");
Item item = armor[2].getItem();
if(item instanceof ItemArmor)
{
System.out.println("armoritem in slot");
ItemArmor itemA = (ItemArmor) item;
if(itemA.getArmorMaterial() == CMStuff.WoolArmor)
{
ItemStack backpack = armor[2];
System.out.println("right item");
System.out.println("armor slot/Server");
return ID == 5 ? new ContainerBackpack(player, player.inventory, new InventoryBackpack(backpack)) : null;
}
}
}
}
}
return null;
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
TileEntity tileEntity = world.getTileEntity(x, y, z);
switch(ID)
{
case 0: return ID == 0 ? new GuiAltar(player.inventory, (TileEntityAltar) tileEntity) : null;
case 1: return ID == 1 ? new GuiRecipeBook(player) : null;
case 2: return ID == 2 ? new GuiCobaltFurnace(player.inventory, (TileEntityCobaltFurnace) tileEntity) : null;
case 3: return ID == 3 ? new GuiRitualStone(player.inventory, (TileEntityRitualStone) tileEntity) : null;
case 4: return ID == 4 && world.getBlock(x, y, z) == CMStuff.cobexworkbench ? new GuiBlueWoodWorkBench(player.inventory, world, x, y, z) : null;
case 5:
i also tried it with armor[2] instead of backpack, but it still not work. when i have it in my hands and press rightclick it works perfectly, its simply the key + slot problem :/ Hope someone can help me ^^
Hmm, but how can I still remove duplicate messages, the method playerTick? Through the condition put isRemote nothing happens.
Again, it is not necessary. The problem has solved itself.
Well, you must have named your class differently, because that is supposed to be the constructor. So change it to the constructor.
I make Minecraft Let's Plays!
A mod that I am currently working on uses a keybinding to open an overlay. Here is the repo, search around a bit.
Send a packet to the server with the entity id, then on the server side get the entity by id from the world and entity.motionX += amount, etc. If your custom entity is registered properly, the motion updates will be sent automatically for nearby clients (players) to see.
[yourkey].isPressed() should return true so long as the key is held down, e.g. keys[CUSTOM_INV].isPressed()
You have to check the key outside of the KeyInputEvent, as that ONLY fires when a key is actually pressed down; if you put [custom_key].isPressed() in, say, a TickEvent, it would continue to return true so long as you held the key down, and you could do whatever you want from there.
This button is to "sticky"?clear
Make high-quality models in the Techne. And do the model in Blender.
player
not holding
in armor slot
armoritem in slot
right item
armor slot/Client
but in the end it doesnt open ._.
{
private Minecraft mc;
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
TileEntity tileEntity = world.getTileEntity(x, y, z);
mc = Minecraft.getMinecraft();
switch(ID)
{
case 0: return ID == 0 ? new ContainerAltar(player.inventory, (TileEntityAltar) tileEntity) : null;
case 2: return ID == 2 ? new ContainerCobaltFurnace(player.inventory, (TileEntityCobaltFurnace) tileEntity) : null;
case 3: return ID == 3 ? new ContainerRitualStone(player.inventory, (TileEntityRitualStone) tileEntity) : null;
case 4: return ID == 4 && world.getBlock(x, y, z) == CMStuff.cobexworkbench ? new ContainerBlueWoodWorkBench(player.inventory, world, x, y, z) : null;
case 5:
ItemStack[] armor = mc.thePlayer.inventory.armorInventory;
if (player != null) {
System.out.println("player");
if (player.getHeldItem() != null) {
System.out.println("hold in hands");
if (player.getHeldItem().getItem() == CMStuff.cobaltbackpack) {
System.out.println("right item in Hands");
System.out.println("hands/Server");
return ID == 5 ? new ContainerBackpack(player, player.inventory, new InventoryBackpack(player.getHeldItem())) : null;
}
}
else if(armor[2] != null)
{
System.out.println("not holding");
System.out.println("in armor slot");
Item item = armor[2].getItem();
if(item instanceof ItemArmor)
{
System.out.println("armoritem in slot");
ItemArmor itemA = (ItemArmor) item;
if(itemA.getArmorMaterial() == CMStuff.WoolArmor)
{
ItemStack backpack = armor[2];
System.out.println("right item");
System.out.println("armor slot/Server");
return ID == 5 ? new ContainerBackpack(player, player.inventory, new InventoryBackpack(backpack)) : null;
}
}
}
}
}
return null;
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
TileEntity tileEntity = world.getTileEntity(x, y, z);
switch(ID)
{
case 0: return ID == 0 ? new GuiAltar(player.inventory, (TileEntityAltar) tileEntity) : null;
case 1: return ID == 1 ? new GuiRecipeBook(player) : null;
case 2: return ID == 2 ? new GuiCobaltFurnace(player.inventory, (TileEntityCobaltFurnace) tileEntity) : null;
case 3: return ID == 3 ? new GuiRitualStone(player.inventory, (TileEntityRitualStone) tileEntity) : null;
case 4: return ID == 4 && world.getBlock(x, y, z) == CMStuff.cobexworkbench ? new GuiBlueWoodWorkBench(player.inventory, world, x, y, z) : null;
case 5:
ItemStack[] armor = mc.thePlayer.inventory.armorInventory;
if (player != null) {
System.out.println("player");
if (player.getHeldItem() != null) {
System.out.println("hold in hands");
if (player.getHeldItem().getItem() == CMStuff.cobaltbackpack) {
System.out.println("right item in Hands");
System.out.println("hands/Client");
return ID == 5 ? new GuiBackpack((ContainerBackpack) new ContainerBackpack(player, player.inventory, new InventoryBackpack(player.getHeldItem()))) : null;
}
}
else if(armor[2] != null)
{
System.out.println("not holding");
System.out.println("in armor slot");
Item item = armor[2].getItem();
if(item instanceof ItemArmor)
{
System.out.println("armoritem in slot");
ItemArmor itemA = (ItemArmor) item;
if(itemA.getArmorMaterial() == CMStuff.WoolArmor)
{
ItemStack backpack = armor[2];
System.out.println("right item");
System.out.println("armor slot/Client");
return ID == 5 ? new GuiBackpack((ContainerBackpack) new ContainerBackpack(player, player.inventory, new InventoryBackpack(backpack))) : null;
}
}
}
}
}
return null;
}
}
If the spoiler doesnt seem to work:
http://pastebin.com/bRQw7En6
i also tried it with armor[2] instead of backpack, but it still not work. when i have it in my hands and press rightclick it works perfectly, its simply the key + slot problem :/ Hope someone can help me ^^
Well nvm. fixed it: http://www.minecraftforge.net/forum/index.php/topic,24013.0.html
Hmm, but how can I still remove duplicate messages, the method playerTick? Through the condition put isRemote nothing happens.Again, it is not necessary. The problem has solved itself.
Make high-quality models in the Techne. And do the model in Blender.