Jump to content

Recommended Posts

Posted

Im trying to spawn entities using a gui for my laser designator

 

When i click the button, the entity appears, but it doesnt react  with anything.  I tried adding the if(par2World.isRemote) and if(!par2World.isRemote) statements but it didnt work.

 

GUI Code

package lazerman47.weaponsplus.GUI;

import lazerman47.weaponsplus.Entity.EntityLaserDesignation;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;

import org.lwjgl.opengl.GL11;

public class GUILaserDesignator extends GuiScreen
{

public GUILaserDesignator(EntityPlayer par1EntityPlayer)
{

}

public final int xSizeOfTexture = 176;
public final int ySizeOfTexture = 180;
protected int type = 0;
@Override
public void drawScreen(int x, int y, float f)
{
	drawDefaultBackground();

	GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

	int posX = (this.width - xSizeOfTexture) / 2;
	int posY = (this.height - ySizeOfTexture) / 2;

	this.mc.renderEngine.bindTexture(new ResourceLocation("weaponsplus:textures/gui/guiLaserDesg.png"));

	drawTexturedModalRect(posX, posY, 0, 0, xSizeOfTexture, ySizeOfTexture);

	drawString(fontRendererObj, "Type: " + type, posX + 15, posY + 30, 0xFF0000);

	this.initGui();

	super.drawScreen(x, y, f);
}
public void initGui()
{
	int posX = (this.width - xSizeOfTexture) / 2;
	int posY = (this.height - ySizeOfTexture) / 2;

	this.buttonList.add(new GuiButton(0, posX + 15, posY + 60, 150, 20, "Send Conventional Missile"));
	this.buttonList.add(new GuiButton(1, posX + 15, posY + 100, 150, 20, "Send Incindeary Missile"));
	this.buttonList.add(new GuiButton(2, posX + 15, posY + 140, 150, 20, "Send Nuclear Missile"));
}

public void actionPerformed(GuiButton button)
{
	switch(button.id)
	{
	case 0:  
		this.type = 0;
		this.mc.theWorld.spawnEntityInWorld(new EntityLaserDesignation(this.mc.theWorld, this.mc.thePlayer.posX, this.mc.thePlayer.posY, this.mc.thePlayer.posZ));
		this.mc.thePlayer.closeScreen();
		break;
	case 1:
		this.type = 1;
		this.mc.thePlayer.closeScreen();
		break;
	case 2:
		this.type = 2;
		this.mc.thePlayer.closeScreen();
		break;
	}
}
@Override
public boolean doesGuiPauseGame()
{
	return false;
}
}

Creator Of Weapons+ Mod & Sword Art Online HUD Mod

Posted

I checked the tutorials and made these 2 classes

 

AbstractPacket

 

  Reveal hidden contents

Creator Of Weapons+ Mod & Sword Art Online HUD Mod

Posted

Ive figured out packets!!!  ;D

 

I am now able to use them to call the addChatMessage() method, but there is no world variable

 

public void handleServerSide(EntityPlayer player)  <<---- There is no World par2World in there

 

 

My Custom Packet Class:

package lazerman47.weaponsplus.PacketHandling;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ChatComponentText;

public class PacketGUI extends AbstractPacket
{

@Override
public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
	// TODO Auto-generated method stub

}

@Override
public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
	// TODO Auto-generated method stub

}

@Override
public void handleClientSide(EntityPlayer player) {
	// TODO Auto-generated method stub

}

@Override
public void handleServerSide(EntityPlayer player) 
{
	player.addChatMessage(new ChatComponentText("PACKETS WORK!!!"));
}

}

Creator Of Weapons+ Mod & Sword Art Online HUD Mod

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



×
×
  • Create New...

Important Information

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