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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • So I'm using a mod that adds a "god sword" into the game. This sword is unfortunately not enchantable so I'm looking to change it. The only code that seems related is in the weapon's .class file which is here:  public int getItemEnchantability() { return this.tier.m_6601_(); }   The entire file is below: package blackwolf00.elementalswords.common; import blackwolf00.elementalswords.config.ConfigEffects; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Multimap; import com.mojang.blaze3d.platform.InputConstants; import java.util.List; import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.effect.MobEffects; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.ai.attributes.Attribute; import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Tier; import net.minecraft.world.item.TieredItem; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.Vanishable; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.common.ToolAction; import net.minecraftforge.common.ToolActions; public class FusionSword extends TieredItem implements Vanishable { private final float totalDamage; private final Tier tier; private final Multimap<Attribute, AttributeModifier> defaultModifiers; public FusionSword(Tier tierIn, int damage, float speed, Item.Properties builderIn) { super(tierIn, builderIn); this.tier = tierIn; this.totalDamage = damage + this.tier.m_6631_(); ImmutableMultimap.Builder<Attribute, AttributeModifier> builder = ImmutableMultimap.builder(); builder.put(Attributes.f_22281_, new AttributeModifier(f_41374_, "Weapon modifier", this.totalDamage, AttributeModifier.Operation.ADDITION)); builder.put(Attributes.f_22283_, new AttributeModifier(f_41375_, "Weapon modifier", speed, AttributeModifier.Operation.ADDITION)); this.defaultModifiers = (Multimap<Attribute, AttributeModifier>)builder.build(); } public int getItemEnchantability() { return this.tier.m_6601_(); } public boolean getIsRepairable(ItemStack toRepair, ItemStack repair) { return (this.tier.m_6282_().test(repair) || isRepairable(toRepair)); } public float getAttackDamage() { return this.totalDamage; } public boolean m_6777_(BlockState state, Level level, BlockPos pos, Player player) { return !player.m_7500_(); } public float m_8102_(ItemStack stack, BlockState state) { return 1.0F; } public boolean m_7579_(ItemStack stack, LivingEntity target, LivingEntity attacker) { stack.m_41622_(1, attacker, entity -> entity.m_21166_(EquipmentSlot.MAINHAND)); return true; } public boolean m_6813_(ItemStack stack, Level level, BlockState state, BlockPos pos, LivingEntity entityLiving) { if (state.m_60800_((BlockGetter)level, pos) != 0.0F) stack.m_41622_(2, entityLiving, entity -> entity.m_21166_(EquipmentSlot.MAINHAND)); return true; } public boolean m_8096_(BlockState blockIn) { return blockIn.m_60713_(Blocks.f_50033_); } public boolean m_5812_(ItemStack item) { return true; } public Multimap<Attribute, AttributeModifier> m_7167_(EquipmentSlot equipmentSlot) { return (equipmentSlot == EquipmentSlot.MAINHAND) ? this.defaultModifiers : super.m_7167_(equipmentSlot); } public boolean onLeftClickEntity(ItemStack stack, Player player, Entity entity) { return super.onLeftClickEntity(stack, player, entity); } @OnlyIn(Dist.CLIENT) public void m_7373_(ItemStack stack, Level level, List<Component> tooltip, TooltipFlag flag) { super.m_7373_(stack, level, tooltip, flag); if (InputConstants.m_84830_(Minecraft.m_91087_().m_91268_().m_85439_(), 340)) { tooltip.add(Component.m_237115_("tooltip.fusion_sword").m_130940_(ChatFormatting.GRAY)); } else { tooltip.add(Component.m_237115_("tooltip.hold_shift").m_130940_(ChatFormatting.GRAY)); } } public InteractionResultHolder<ItemStack> m_7203_(Level level, Player playerIn, InteractionHand handIn) { if (((Boolean)ConfigEffects.JUMP_F.get()).booleanValue()) playerIn.m_7292_(new MobEffectInstance(MobEffects.f_19603_, 10000, ((Integer)ConfigEffects.JUMP_F_LEVEL.get()).intValue() - 1)); if (((Boolean)ConfigEffects.MOVEMENT_SPEED_F.get()).booleanValue()) playerIn.m_7292_(new MobEffectInstance(MobEffects.f_19596_, 10000, ((Integer)ConfigEffects.MOVEMENT_SPEED_F_LEVEL.get()).intValue() - 1)); if (((Boolean)ConfigEffects.SLOW_FALLING_F.get()).booleanValue()) playerIn.m_7292_(new MobEffectInstance(MobEffects.f_19591_, 10000, ((Integer)ConfigEffects.SLOW_FALLING_F_LEVEL.get()).intValue() - 1)); if (((Boolean)ConfigEffects.ABSORPTION_F.get()).booleanValue()) playerIn.m_7292_(new MobEffectInstance(MobEffects.f_19617_, 10000, ((Integer)ConfigEffects.ABSORPTION_F_LEVEL.get()).intValue() - 1)); if (((Boolean)ConfigEffects.DAMAGE_RESISTANCE_F.get()).booleanValue()) playerIn.m_7292_(new MobEffectInstance(MobEffects.f_19606_, 10000, ((Integer)ConfigEffects.DAMAGE_RESISTANCE_F_LEVEL.get()).intValue() - 1)); if (((Boolean)ConfigEffects.DAMAGE_BOOST_F.get()).booleanValue()) playerIn.m_7292_(new MobEffectInstance(MobEffects.f_19600_, 10000, ((Integer)ConfigEffects.DAMAGE_BOOST_F_LEVEL.get()).intValue() - 1)); if (((Boolean)ConfigEffects.CONDUIT_POWER_F.get()).booleanValue()) playerIn.m_7292_(new MobEffectInstance(MobEffects.f_19592_, 10000, ((Integer)ConfigEffects.CONDUIT_POWER_F_LEVEL.get()).intValue() - 1)); if (((Boolean)ConfigEffects.DOLPHINS_GRACE_F.get()).booleanValue()) playerIn.m_7292_(new MobEffectInstance(MobEffects.f_19593_, 10000, ((Integer)ConfigEffects.DOLPHINS_GRACE_F_LEVEL.get()).intValue() - 1)); if (((Boolean)ConfigEffects.WATER_BREATHING_F.get()).booleanValue()) playerIn.m_7292_(new MobEffectInstance(MobEffects.f_19608_, 10000, ((Integer)ConfigEffects.WATER_BREATHING_F_LEVEL.get()).intValue() - 1)); if (((Boolean)ConfigEffects.FIRE_RESISTANCE_F.get()).booleanValue()) playerIn.m_7292_(new MobEffectInstance(MobEffects.f_19607_, 10000, ((Integer)ConfigEffects.FIRE_RESISTANCE_F_LEVEL.get()).intValue() - 1)); if (((Boolean)ConfigEffects.HEALTH_BOOST_F.get()).booleanValue()) playerIn.m_7292_(new MobEffectInstance(MobEffects.f_19616_, 10000, ((Integer)ConfigEffects.HEALTH_BOOST_F_LEVEL.get()).intValue() - 1)); if (((Boolean)ConfigEffects.REGENERATION_F.get()).booleanValue()) playerIn.m_7292_(new MobEffectInstance(MobEffects.f_19605_, 10000, ((Integer)ConfigEffects.REGENERATION_F_LEVEL.get()).intValue() - 1)); return InteractionResultHolder.m_19098_(playerIn.m_21120_(handIn)); } public boolean canPerformAction(ItemStack stack, ToolAction toolAction) { return ToolActions.DEFAULT_SWORD_ACTIONS.contains(toolAction); } } How do I make this thing enchantable?  
    • The mod I'm working on is in 1.19.2. The portal works correctly in Intellij but when I publish the jar, put it in the mods folder of the game it crashes with the following error whenever any entity collides with it: java.lang.IllegalAccessError: class com.github.warrentode.turtleblockacademy.blocks.TBAMiningPortalBlock tried to access protected field net.minecraft.world.entity.Entity.f_19819_ (com.github.warrentode.turtleblockacademy.blocks.TBAMiningPortalBlock is in module [email protected] of loader 'TRANSFORMER' @16c5b50a; net.minecraft.world.entity.Entity is in module [email protected] of loader 'TRANSFORMER' @16c5b50a)     at com.github.warrentode.turtleblockacademy.blocks.TBAMiningPortalBlock.m_7892_(TBAMiningPortalBlock.java:124) ~[turtleblockacademy-2024.2025-1.0.0.jar%23572!/:2024.2025-1.0.0] {re:classloading} The thing is, I have Entity.f_19819_ in my accessTransformer.cfg file in this line: public net.minecraft.world.entity.Entity f_19819_ # portalEntrancePos So what do I need to do to fix this error?
    • It will be about medeaival times
    • the mods are crashing and I'm not sure why so heres everything  crash log https://pastebin.com/RxLKbMNR  L2 Library (12library) has failed to load correctly java.lang.NoClassDefFoundError: org/antarcticgardens/newage/content/energiser/EnergiserBlock L2 Screen Tracker (12screentracker) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.12library.base.L2Registrate Create: Interiors (interiors) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.tterrag.registrate.AbstractRegistrate L2 Damage Tracker (12damagetracker) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.l2library.base.L2Registrate Create Enchantment Industry (create_enchantment_industry) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.simibubi.create.foundation.data.Createfiegistrate Create Crafts & Additions (createaddition) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.simibubi.create.foundation.data.CreateRegistrate Create Slice & Dice (sliceanddice) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.simibubi.create.foundation.data.CreateRegistrate L2 Tabs (12tabs) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.l2library.base.L2Registrate Modular Golems (modulargolems) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.l2library.base.L2Registrate Create: Steam 'n' FRails (railways) has failed to load correctly java.lang.NoClassDefFoundError : Could not initialize class com.simibubi.create.foundation.data.Createfregistrate Cuisine Delight (cuisinedelight) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.12library.base.L2Registrate Create (create) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.simibubi.create.Create Guardian Beam Defense (creategbd) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.simibubi.create.foundation.data.CreateRegistrate L2 Item Selector (12itemselector) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.l2library.base.L2Registrate
    • hey there, I have been using Forge for years without any problems, but for some time now I have been getting this error message when I click on “Installer” under the downloads. This happens on all versions. I have tried various things but have not gotten any results. If anyone has a solution, I would be very grateful!
  • Topics

×
×
  • Create New...

Important Information

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