Jump to content

GuiScreen and Item?


godbaba

Recommended Posts

Hi I have a mod full of Guis and I had a problem with the guis crashing the server as soon as I added @SideOnly(Side.CLIENT) to the onItemRightClick command it fixed the problem but the new problem is that I used to have guibuttons that when you click drops item @SideOnly(Side.CLIENT) annotation brokes them!!

 

What can I do about this ? :(

Link to comment
Share on other sites

For example

 

BlockCode:

package netherfors.block;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.src.ModLoader;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
import netherfors.main;
import netherfors.gui.GuiLavaCollector;
import netherfors.tile.TileLavaCollector;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class LavaCollector extends BlockContainer{

private Icon top,bottom;

public LavaCollector(int id) {
	super(id, Material.rock);
	this.setStepSound(Block.soundStoneFootstep);
	this.setCreativeTab(main.nettab);
	this.setHardness(5f);
}

@SideOnly(Side.CLIENT)
    public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9)
    {
    	TileLavaCollector tile = (TileLavaCollector) world.getBlockTileEntity(x, y, z);
    	if(tile!=null){
    		Minecraft mc = ModLoader.getMinecraftInstance();
    		mc.displayGuiScreen(new GuiLavaCollector(player,world,tile));
    	}
    	return true;
    }
    
    public void onBlockClicked(World world, int x, int y, int z, EntityPlayer player) {
    	TileLavaCollector tile = (TileLavaCollector) world.getBlockTileEntity(x, y, z);
    	if(tile!=null){
    		if(tile.itemamount>0){
    			EntityItem it = new EntityItem(world, x, y, z, new ItemStack(main.craftingitems,tile.itemamount,0));
    			if(!world.isRemote){
    				world.spawnEntityInWorld(it);
    			}
    			tile.itemamount = 0;
    		}
    	}
    }
    
    public void onBlockAdded(World world, int x, int y, int z)
    {
    	TileLavaCollector t = (TileLavaCollector) world.getBlockTileEntity(x, y, z); 
    	if(t!=null){
    		t.itemamount = 0;
    		t.amount = 0;
    		t.interval = 0;
    		t.time = 0;
    	}

    }
    
    public void registerIcons(IconRegister r){
    	this.blockIcon = r.registerIcon("netherfors:lavaside");
    	this.top = r.registerIcon("netherfors:lavatop");
    	this.bottom = r.registerIcon("netherfors:lavabottom");
    }
    
    public Icon getIcon(int par1, int par2)
    {
        return par1 == 1 ? this.top : (par1 == 0 ? this.bottom : (par1 != par2 ? this.blockIcon : this.blockIcon));
    }

@Override
public TileEntity createNewTileEntity(World world) {
	return new TileLavaCollector();
}

}

 

GuiCode :

package netherfors.gui;

import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import netherfors.tile.TileLavaCollector;

import org.lwjgl.opengl.GL11;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class GuiLavaCollector extends GuiScreen{

private int wi,he;
private EntityPlayer player;
private World world;
private TileLavaCollector tile;

// 88 // 65

public GuiLavaCollector(EntityPlayer pla,World wor,TileLavaCollector ti){
	this.wi = 88;
	this.he = 90;
	this.world = wor;
	this.player = pla;
	this.tile = ti;
}

    public boolean doesGuiPauseGame()
    {
        return false;
    }

public void drawProgressBar(int i){

	if(i>65){
		i = 65;
	}

        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        this.mc.renderEngine.bindTexture("/mods/netherfors/textures/gui/lavacollector.png");;
        this.drawTexturedModalRect(width/2-35, (height/2-37)+(65-i), 88, 0, 20, i);
}

public void progressOverHundred(int o){

	if(o>100){
		o = 100;
	}

	int percent = (65*o)/100;
	drawProgressBar(percent);

}


public void initGui(){

}

@SideOnly(Side.CLIENT)
public void drawScreen(int par1, int par2, float par3)
{
        this.drawGuiContainerBackgroundLayer(par3, par2, par1);
        int t = tile.amount;
        progressOverHundred(t);
        this.fontRenderer.drawSplitString("Progress\n"+Integer.toString(tile.amount)+"%\n\nAmount\n"+Integer.toString(tile.itemamount), width/2-20, height/2-34, 54, 0);
        super.drawScreen(par1, par2, par3);
}	

@SideOnly(Side.CLIENT)
    protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
    {
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        this.mc.renderEngine.bindTexture("/mods/netherfors/textures/gui/lavacollector.png");
        int k = (this.width - this.wi) / 2;
        int l = (this.height - this.he) / 2;
        this.drawTexturedModalRect(k, l, 0, 0, this.wi, this.he);
    }

}

 

If I dont put sideonly to the onBlockActivated it crashes the server :)

Link to comment
Share on other sites

yeah make sens

mc.displayGuiScreen(new GuiLavaCollector(player,world,tile));

 

this is wrong, you need a IGuiHandler and call this instead

 

@Override
public boolean onBlockActivated(World world, int x, int y, int z,
		EntityPlayer player, int a, float b, float c, float d) {
	TileEntity te = world.getBlockTileEntity(x, y, z);
	if(te != null){
		TileEntityPlot tep = (TileEntityPlot)te;
		if(tep.isBought()){
			return false;
		}
		if(player.username.equals(tep.owner)){
		player.openGui(TheMod.instance, PlotSellerGui.GUI_ID, world, x, y, z);
		}else{
			player.openGui(TheMod.instance, PlotBuyerGui.GUI_ID, world, x, y, z);
		}
	}
	return true;
}

example from one of my block ^^

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

yeah make sens

mc.displayGuiScreen(new GuiLavaCollector(player,world,tile));

 

this is wrong, you need a IGuiHandler and call this instead

 

@Override
public boolean onBlockActivated(World world, int x, int y, int z,
		EntityPlayer player, int a, float b, float c, float d) {
	TileEntity te = world.getBlockTileEntity(x, y, z);
	if(te != null){
		TileEntityPlot tep = (TileEntityPlot)te;
		if(tep.isBought()){
			return false;
		}
		if(player.username.equals(tep.owner)){
		player.openGui(TheMod.instance, PlotSellerGui.GUI_ID, world, x, y, z);
		}else{
			player.openGui(TheMod.instance, PlotBuyerGui.GUI_ID, world, x, y, z);
		}
	}
	return true;
}

example from one of my block ^^

 

I converted all of my code into IGuiHandler but now world.spawnEntityInWorld() spawns fake items as well :)

Still have the problem...

Link to comment
Share on other sites

Don't.Use.SideOnly.Annotation.

never use @sideonly its only causing more confusion then anything

NEVER

 

You cant depent on packets because players easily can exploit them :) And they are actually complicated :)

with this logic the mod is un-codable, the thing you must understand is that packet are good but you MUST filter them, dont accept anything "just because"

IRL example:

in my mod people have a skill tree that they can buy spell from, but player dont tell the server "hey im now max level" when they want to buy a new skill they send a packet to the server saying "can i buy this ?" and the server will decide yes or no, so theres no way around usign a hacked client on this

 

And they are actually complicated

you feed stuff in a stream on one side and collect it on the other ....

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

yes only if you dont mind using MY classes....(located: http://www.minecraftforge.net/wiki/Organising_packet_handlers)

 

//this code client side (in your gui ?) where the button was pressed or wtv
int spawnItemId = 55;
PacketWriteStream stream = new PacketWriteStream();
stream.put(spawnItemId);
PacketDispatcher.sendPacketToServer(stream.makePacket("channel");


server side in method 
public void onPacketData(INetworkManager manager,
                        Packet250CustomPayload packet, Player playerEntity) :

int spawnItemId = 55;
PacketReadStream stream = new PacketReadStream(packet);
int packetID = stream.readInt();
if(packetID == spawnItemId){
    //make check to see if its a valid state  
    //spawn item
    //to get a reference to the player that send this:
    EntityPlayer player = (EntityPlayer)playerEntity;
   //then player.doSomething() or player.worldObj.spawnItemInWorld(new EntityItem etc)
}

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

i actually looked into thsi class later, but these utility class were already done so wtv :P

and my like 500 different packet are all written with this class ... soooo i dont want to change all that xD

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Realizing I was a victim of a scam was a devastating blow. My initial investment of $89,000, driven by dreams of financial success and the buzz surrounding a new cryptocurrency project, turned into a nightmare. The project promised high returns and rapid gains, attracting many eager investors like myself. However, as time passed and inconsistencies began to surface, it became evident that I had made a grave mistake by not thoroughly vetting the brokerage company handling the investment. Feeling anxious and betrayed, I desperately searched for a way to recover my funds. During this frantic search, I stumbled upon the Brigadia Tech Recovery tool through a Facebook post. With little left to lose, I reached out to their team for help. To my relief, they were quick to respond and immediately started recovering my compromised email and regaining access to my cryptocurrency wallets. The team at Brigadia Tech Recovery was incredibly professional and transparent throughout the process. They meticulously traced the digital footprints left by the scammers, employing advanced technological methods to unravel the complex network that had ensnared my funds. Their expertise in cybersecurity and recovery strategies gradually began to turn the tide in my favor. Although the scammers had already siphoned off $30,000 worth of Bitcoin, Brigadia Tech Recovery was relentless in their pursuit. They managed to expose the fraudulent activities of the scam operators, revealing their identities and the mechanisms they used to lure investors. This exposure was crucial not only for my case but also as a warning to the wider community about the perils of unverified investment schemes. As we progressed, it became a race against time to retrieve the remaining $59,000 before the scammers could vanish completely. Each step forward was met with new challenges, as these criminals constantly shifted tactics and moved their digital assets to evade capture. Nonetheless, the determination and skill of the recovery team kept us hopeful. Throughout this ordeal, I learned the hard value of caution and due diligence in investment, especially within the volatile world of cryptocurrency. The experience has been incredibly taxing, both emotionally and financially, but the support and results provided by Brigadia Tech Recovery have been indispensable. Currently, the recovery process is ongoing and I have already received 50% of my money, and while the outcome remains uncertain, the progress made so far gives me hope. The battle to recover the full amount of my investment continues, and with the expertise of Brigadia Tech Recovery, I remain optimistic about the eventual recovery of my funds. Their commitment to their clients and proficiency in handling such complex cases truly sets them apart in the field of cyber recovery.I share this testimony because i am sure someone out there is going through the same issue and devastated mentally by all these fake brokers all around the world,This is the main contact information incase you are interested to recover your lost investments  Email:(Brigadiatechremikeable (@) Proton.Me) Telegram +1 (323) 910-1605)  
    • So I finally downloaded forge for my girl and I, I got hers working no problem but when I did it, I load up and get a black screen with the narration with these codes, I've tried to figure it out but I give up after 3 days, ZERO mods or anything, help would be greatly appreciated. [18:14:48] [main/WARN] [os.ut.FileUtil/]: Configuration conflict: there is more than one oshi.properties file on the classpath: [jar:file:///C:/Users/Night/Desktop/Minecraft%20Modded%20Server/libraries/com/github/oshi/oshi-core/6.4.10/oshi-core-6.4.10.jar!/oshi.properties, jar:file:/C:/Users/Night/Desktop/Minecraft%20Modded%20Server/libraries/com/github/oshi/oshi-core/6.4.10/oshi-core-6.4.10.jar!/oshi.properties, jar:file:///C:/Users/Night/Desktop/Minecraft%20Modded%20Server/libraries/com/github/oshi/oshi-core/6.4.10/oshi-core-6.4.10.jar!/oshi.properties, jar:file:/C:/Users/Night/Desktop/Minecraft%20Modded%20Server/libraries/com/github/oshi/oshi-core/6.4.10/oshi-core-6.4.10.jar!/oshi.properties] [18:14:49] [main/WARN] [os.ut.FileUtil/]: Configuration conflict: there is more than one oshi.architecture.properties file on the classpath: [jar:file:///C:/Users/Night/Desktop/Minecraft%20Modded%20Server/libraries/com/github/oshi/oshi-core/6.4.10/oshi-core-6.4.10.jar!/oshi.architecture.properties, jar:file:/C:/Users/Night/Desktop/Minecraft%20Modded%20Server/libraries/com/github/oshi/oshi-core/6.4.10/oshi-core-6.4.10.jar!/oshi.architecture.properties, jar:file:///C:/Users/Night/Desktop/Minecraft%20Modded%20Server/libraries/com/github/oshi/oshi-core/6.4.10/oshi-core-6.4.10.jar!/oshi.architecture.properties, jar:file:/C:/Users/Night/Desktop/Minecraft%20Modded%20Server/libraries/com/github/oshi/oshi-core/6.4.10/oshi-core-6.4.10.jar!/oshi.architecture.properties] [18:14:49] [main/WARN] [os.dr.wi.pe.PerfmonDisabled/]: Invalid registry value type detected for PerfOS counters. Should be REG_DWORD. Ignoring: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\PerfOS\Performance\Disable Performance Counters.
    • Somewhat recently, I wanted to try to get into mod development. I've been following the videos by Kaupenjoe, and the mod has been coming along well... until I tried to add the Create mod as an API for my mod. I followed the guide on Create's Github, but no matter what I tried, it corrupted everything, and either the build failed or Minecraft crashed on startup. I have found absolutely nothing relevant online about the issue, and I don't know what to try next. How do I add Create as dependency? Here is the Github page for my mod.
    • Hello 44STEFAN444
    • I am currently watching a YouTube series. After a few episodes they started adding some custom effects. One of them Is called "Paranoia", and It moves your camera around every few seconds, and another called "Anxiety" where, when you move your camera, It adds a blurred effect to the camera. Another One, called "Fear", moves you randomly. Does anybody have any clue what this mod Is called? (also, as a descriptions for the icons, Paranoia is a pair of eyes looking away, Anxiety Is a Blue Eye, and Fear Is a Ghost).
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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