• 0

    posted a message on player kicked by clicking button in item gui

    Does anyone know how i can test an issue like this without compiling and using 2 computers?

    So more or less have my IDE simulate multiplayer mode where I am the guest player to a virtual host.


    I don't know how to trouble shoot in IDE and it works fine with me on my own compiled or in IDE so not sure how i might gather more info on why this is happening or how i might fix it.


    Thanks again if anyone can help with this

    Posted in: Modification Development
  • 0

    posted a message on Torch with durability

    those methods wont work for a block as the are inherited from the Item Class.


    Only Very Limited data can be stored in a blocks Metadata. there are some OK tutorials out there on blocks with metadata, i'm not overly familiar.


    Look in the source Block.Class for available vanilla methods blocks herniate.

    Posted in: Modification Development
  • 0

    posted a message on Torch with durability
    Quote from WolfieWaffle»

    OK, so I know that I can use metadata for the timer, because I've seen it done before, and I think it would be the easiest and least resource intensive. Secondly, I really would like to use different block for each state, since I'd have to use NBT data in recipes and stuff. I'll look into the max damage, because that sounds like what I'm looking for. It that what tools use for durability, and can it be used on blocks?


    I didn't say you couldn't use metadata, i imagine you would set the block to require random update ticks, then add to the metadata in the onUpdate method if the conditions are correct.

    Yes it is more or less what tools use to have a damage bar Items must have isDamagable true and maxStacksize = 1 the damage bar shows up once isDamaged returns true.

    Posted in: Modification Development
  • 0

    posted a message on Torch with durability

    OK, if you want a block(sits in the world) that lights up and has a timer and takes fuel of and ignition event, you might want to be looking into TileEntities as you may want the MetaData for positioning or at the very least on state and off state (have the tile entity store everything else and just switch the blocks metadata to change state from on off).

    If you want an Item you can carry round and that has a damage bar you might want to use NBTTagCompounds to store data (if it still requires fuel ect) otherwise just set a max damage and damage it onUpdateTick if its in the player current Itemslot

    Posted in: Modification Development
  • 1

    posted a message on [SOLVED] Block right click with item

    if(player.capabilities.isCreativeMode)

    Posted in: Modification Development
  • 0

    posted a message on [SOLVED] Block right click with item
    Quote from WolfieWaffle»

    Thanks, that works perfectly! I know I said only one more question, but, I realize that I forgot to ask in the OP how to remove the item from your hand when you right click the torch IF it is not another torch. I can't find the method (or whatever it's called) to handle the players inventory.


    Is there some place to find all of these events? Like a list or something?

    Anyways if anyone knows how to do that, I think my problem will be completely solved.


    It's all the the source which you can find in your IDE under Forge..... .jar


    Decrease Stack size - player.inventory.decrStackSize(inventory slot, amount);

    Get Current Items Inventory Slot - player.inventory.currentItem;


    Decrease your ItemStack size by 1

    player.inventory.decrStackSize(player.inventory.currentItem, 1);

    Posted in: Modification Development
  • 1

    posted a message on [1.7 & 1.8] TheXFactor117's Forge Modding Tutorials | 20+ Tutorials | Actually Learn How to Make Mods!
    Quote from cocorj070»

    Thanks for the help!


    Although the "ModName.instance" is still an error,

    ^ (I did replace my Modname in there)

    l

    Am I missing something? It feels like a I skipped a part of the tutorial :P


    Actually it looks like Brockstar01 is having the same issue as me, is the tutorial missing something?


    Points to a variable you have to set up in your Main Class like this


    @Mod(modid = Reference.MODID, name = Reference.NAME, version = Reference.VERSION)

    public class YourMainClassName{

    @Instance(Reference.MODID)
    public static YourMainClassName instance;

    @Mod.EventHandler
    public void preInit(FMLPreInitializationEvent event){//init events below

    Posted in: Mapping and Modding Tutorials
  • 1

    posted a message on [SOLVED] Block right click with item
    Quote from WolfieWaffle»

    2. If I wanted to check if the player is holding a certain block, how would I do that? getBlock()? This code gives me the error, "The method getBlock() is undefined for the type ItemStack"


    If you want to get a block from Item you should use if(Block.getBlockFromItem(player.inventory.getCurrentItem().getItem()) == Blocks.whatever_block)

    OR

    if(player.inventory.getCurrentItem().getItem() == Item.getItemFromBlock(Blocks.whatever_block)) to get Item from Block

    sorry not sure what the 3 floats are but the integer will be Block Metadata

    Posted in: Modification Development
  • 0

    posted a message on player kicked by clicking button in item gui

    Sure Tried to limit it to only relevant code

    -open GUI


    //In item class

    @Override
    public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player){
    if(player.isSneaking()){
    player.openGui(StructureMappingTool.instance, 219, player.worldObj, (int)player.posX, (int)player.posY, (int)player.posZ);
    }}

    //in Gui Handler getClientGuiElement

    if(ID == 219){
    NBTTagCompound tag = player.inventory.getCurrentItem().getTagCompound();
    if(tag != null){
    return new GuiBuildTool(tag);
    }}

    GUI Button Pressed


    //In Gui

    protected void actionPerformed(GuiButton button){
    boolean send = false;

    if (button.enabled){

    //example of more or less what all my buttons do

    if(button.id == 1){
    iheight += value;
    if(imode == 2 || imode == 3){
    iheight += value;
    iwidth += value;
    }
    send = true;
    }}

    if(send)PacketHandler.sendToServer(new BuildPacket(imode, iheight, iwidth, idir));

    }

    Packet Helper


    public class PacketHandler {
    private static byte packetId = 0;

    private static final SimpleNetworkWrapper dispatcher = NetworkRegistry.INSTANCE.newSimpleChannel(Reference.MODID);

    public static final void registerPackets(){
    PacketHandler.registerMessage(BPacketHandler.class, BuildPacket.class, Side.SERVER);
    }

    private static final void registerMessage(Class handlerClass, Class messageClass, Side side) {
    PacketHandler.dispatcher.registerMessage(handlerClass, messageClass, packetId++, side);
    }

    public static final void sendToServer(IMessage message) {
    PacketHandler.dispatcher.sendToServer(message);
    }

    }

    Packet/Handler


    //Inherited by ServerPacket

    @Override
    public IMessage onMessage(T message, MessageContext ctx) {
    if (ctx.side.isClient()) {
    return handleClientMessage(StructureMappingTool.modProxy.getPlayerEntity(ctx), message, ctx);
    } else {
    return handleServerMessage(StructureMappingTool.modProxy.getPlayerEntity(ctx), message, ctx);
    }}


    public class BuildPacket implements IMessage{
    int mode;
    int height;
    int width;
    boolean direction;

    public BuildPacket() {}

    public BuildPacket(int m, int h, int w, boolean dir) {
    this.mode = m;
    this.height = h;
    this.width = w;
    this.direction = dir;
    }

    @Override
    public void fromBytes(ByteBuf buf) {
    mode = buf.readInt();
    height = buf.readInt();
    width = buf.readInt();
    direction = buf.readBoolean();
    }

    @Override
    public void toBytes(ByteBuf buf) {
    buf.writeInt(mode);
    buf.writeInt(height);
    buf.writeInt(width);
    buf.writeBoolean(direction);
    }


    public static class BPacketHandler extends ServerPacket<BuildPacket> {

    @Override
    public IMessage handleServerMessage(EntityPlayer player,
    BuildPacket message, MessageContext ctx) {
    player.getCurrentEquippedItem().stackTagCompound.setInteger("Mode", message.mode);
    player.getCurrentEquippedItem().stackTagCompound.setInteger("Width", message.width);
    player.getCurrentEquippedItem().stackTagCompound.setInteger("Height", message.height);
    player.getCurrentEquippedItem().stackTagCompound.setBoolean("Direction", message.direction);
    return null;
    } }}

    Edit - Forgot to include Proxy Code


    public class CommonProxy {

    public EntityPlayer getPlayerEntity(MessageContext ctx) {
    return ctx.getServerHandler().playerEntity;
    }}

    public class ClientProxy extends CommonProxy{
    @Override
    public EntityPlayer getPlayerEntity(MessageContext ctx) {

    return (ctx.side.isClient() ? Minecraft.getMinecraft().thePlayer : super.getPlayerEntity(ctx));
    }}

    //In Main class

    @SidedProxy(clientSide= "com.Mergis.StructureMappingTool.proxies.ClientProxy", serverSide = "com.Mergis.StructureMappingTool.proxies.CommonProxy")
    public static CommonProxy modProxy;

    Posted in: Modification Development
  • 1

    posted a message on [SOLVED] Block right click with item

    player.inventory.getCurrentItem() returns an itemstack your checking for an item so you want to add .getItem() to get an Item from an ItemStack


    if(player.inventory.getCurrentItem().getItem() == items.flint)

    Posted in: Modification Development
  • 0

    posted a message on player kicked by clicking button in item gui

    I have an Item which opens a GUI. the player can then press buttons in the GUI to adjust values which are then sent in packets to the server to update the items NBTTag with the new variables.


    This works perfectly in single player mode but whenever in multiplayer only the hosting user can use the buttons on the GUI for anyone else they are kicked from the host and the host logs this


    [01:18:00] [Server thread/INFO]: gurgis lost connection: TranslatableComponent{key='disconnect.genericReason', args=[Internal Exception: io.netty.handler.codec.DecoderException: java.io.IOException: The received string length is longer than maximum allowed (25 > 20)], siblings=[], style=Style{hasParent=false, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null}}


    Thanks for any help you guys can offer

    Posted in: Modification Development
  • 0

    posted a message on [1.7 & 1.8] TheXFactor117's Forge Modding Tutorials | 20+ Tutorials | Actually Learn How to Make Mods!
    Quote from justkunas»

    I knew it was something blindingly obvious. Thank you.


    np

    Posted in: Mapping and Modding Tutorials
  • 0

    posted a message on [1.7 & 1.8] TheXFactor117's Forge Modding Tutorials | 20+ Tutorials | Actually Learn How to Make Mods!

    All of your initialization events are FMLInitializationEvent

    Posted in: Mapping and Modding Tutorials
  • 0

    posted a message on Item opens gui for all users in world

    Awesome thanks for the help guys

    Posted in: Modification Development
  • 0

    posted a message on Item opens gui for all users in world

    Thanks will try this out

    Posted in: Modification Development
  • To post a comment, please or register a new account.