Jump to content

Recommended Posts

Posted

Hey, everytime I try to run my mod on the server, where the server need to use PacketHandler for send packets from the client to the server in a KeyHandler class, it crashes, the game doesn't close because it's a Server Crash not a Client Crash... D:

 

ServerPacketHandler:

 

package mods.exoworld.handler;

import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;

import mods.exoworld.event.ExoArmorPowerup;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet250CustomPayload;
import cpw.mods.fml.common.network.IPacketHandler;
import cpw.mods.fml.common.network.Player;

public class ExoServerPacketHandler implements IPacketHandler {

public static String[] Chanels;

public static final String ARMORPOWERUP = "ExoArmorPowerup";

// Before adding it remember to add it also in chanels, in network mod
// attribute

@Override
public void onPacketData(INetworkManager manager,
		Packet250CustomPayload packet, Player player) {

	if (packet.channel.equals(ARMORPOWERUP)) {
		ExoArmorPowerup.handlePacket(packet, (EntityPlayer) player);

	}

}

}

 

KeyHandler:

 

package mods.exoworld.handler;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.util.EnumSet;
import java.util.Random;

import mods.exoworld.event.ExoArmorPowerup;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.packet.Packet250CustomPayload;

import org.lwjgl.input.Keyboard;

import cpw.mods.fml.client.registry.KeyBindingRegistry.KeyHandler;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.TickType;
import cpw.mods.fml.relauncher.Side;

public class ExoServerKeyHandler extends KeyHandler {

public ExoArmorPowerup eventArmorPowerup;
public EntityPlayer player;

public static KeyBinding armorPowerup = new KeyBinding("Armor's Powerup",
		Keyboard.KEY_F);

public static KeyBinding[] arrayOfKeys = new KeyBinding[] { armorPowerup };
public static boolean[] areRepeating = new boolean[] { false };

public ExoServerKeyHandler() {
	super(arrayOfKeys, areRepeating);
}

@Override
public String getLabel() {
	return "ExotiumWorld's ServerKeyHandler";
}

@Override
public void keyDown(EnumSet<TickType> types, KeyBinding kb,
		boolean tickEnd, boolean isRepeat) {
	if(kb.keyCode == armorPowerup.keyCode) {
		if(tickEnd)
		 {
			 System.out.println("Key up");
			 eventArmorPowerup.sendPacket();
		 }
	}
}

@Override
public void keyUp(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd) {
}

// FireModeHandler.switchFireMode();
@Override
public EnumSet<TickType> ticks() {
	return EnumSet.of(TickType.CLIENT);
}

}

 

EventHandler:

 

package mods.exoworld.event;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.util.Random;

import mods.exoworld.handler.ExoServerPacketHandler;
import mods.exoworld.handler.ExoServerTickHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.world.World;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;

public class ExoArmorPowerup {

public static ExoServerTickHandler event;
public static EntityPlayer player;
public static World world;

public static void sendPacket() {
	EntityPlayer player = Minecraft.getMinecraft().thePlayer;
	ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
	DataOutputStream dataOutputStream = new DataOutputStream(
			byteOutputStream);
	try {
		dataOutputStream.writeInt(player.entityId);
	} catch (Exception e) {
		e.printStackTrace();
	}
	Packet250CustomPayload packet = new Packet250CustomPayload(
			ExoServerPacketHandler.ARMORPOWERUP,
			byteOutputStream.toByteArray());

	FMLClientHandler.instance().sendPacket(packet);
}

public static void handlePacket(Packet250CustomPayload packet,
		EntityPlayer player2) {
	// TODO Auto-generated method stub
	if (event.powerupIsAvailable == true) {
		world.createExplosion(null, player.posX + 5, player.posY,
				player.posZ, 5.0F, false);
		world.createExplosion(null, player.posX - 5, player.posY,
				player.posZ, 5.0F, false);
		world.createExplosion(null, player.posX, player.posY,
				player.posZ + 5, 5.0F, false);
		world.createExplosion(null, player.posX, player.posY,
				player.posZ - 5, 5.0F, false);
		event.powerupIsAvailable = false;
	}
}
}

 

The ServerPacketHandler is registered in the MainMod class like this:

 

@NetworkMod(clientSideRequired = true, serverSideRequired = false, channels = { ExoServerPacketHandler.ARMORPOWERUP
}, packetHandler = ExoServerPacketHandler.class)

 

Any help? Thanks to all!

Posted

ServerKeyHandler doesn't really make sense as a name.  :P

Anyway, most errors are here:

public class ExoArmorPowerup {

public static ExoServerTickHandler event;
public static EntityPlayer player;
public static World world;// i don't see the initialization of this field, but it is useless anyway

public static void sendPacket() {
	EntityPlayer player = Minecraft.getMinecraft().thePlayer;//This is client side only method, meaning player field is now client side only
//prefer using this method in your keyhandler, and passing the argument in the method
	ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
	DataOutputStream dataOutputStream = new DataOutputStream(
			byteOutputStream);
	try {
		dataOutputStream.writeInt(player.entityId);//this info is unused when handling the packet ??
	} catch (Exception e) {
		e.printStackTrace();
	}
	Packet250CustomPayload packet = new Packet250CustomPayload(
			ExoServerPacketHandler.ARMORPOWERUP,
			byteOutputStream.toByteArray());

	FMLClientHandler.instance().sendPacket(packet);
}

public static void handlePacket(Packet250CustomPayload packet,
		EntityPlayer player2) {
	// TODO Auto-generated method stub
	if (event.powerupIsAvailable == true) {//you are using client-only player field while being on server side -> crash
//instead use the player argument from the method
//prefer using player.worldObj instead of your world field
		world.createExplosion(null, player.posX + 5, player.posY,
				player.posZ, 5.0F, false);
		world.createExplosion(null, player.posX - 5, player.posY,
				player.posZ, 5.0F, false);
		world.createExplosion(null, player.posX, player.posY,
				player.posZ + 5, 5.0F, false);
		world.createExplosion(null, player.posX, player.posY,
				player.posZ - 5, 5.0F, false);
		event.powerupIsAvailable = false;
	}
}
}

Posted

ServerKeyHandler doesn't really make sense as a name.  :P

Anyway, most errors are here:

public class ExoArmorPowerup {

public static ExoServerTickHandler event;
public static EntityPlayer player;
public static World world;// i don't see the initialization of this field, but it is useless anyway

public static void sendPacket() {
	EntityPlayer player = Minecraft.getMinecraft().thePlayer;//This is client side only method, meaning player field is now client side only
//prefer using this method in your keyhandler, and passing the argument in the method
	ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
	DataOutputStream dataOutputStream = new DataOutputStream(
			byteOutputStream);
	try {
		dataOutputStream.writeInt(player.entityId);//this info is unused when handling the packet ??
	} catch (Exception e) {
		e.printStackTrace();
	}
	Packet250CustomPayload packet = new Packet250CustomPayload(
			ExoServerPacketHandler.ARMORPOWERUP,
			byteOutputStream.toByteArray());

	FMLClientHandler.instance().sendPacket(packet);
}

public static void handlePacket(Packet250CustomPayload packet,
		EntityPlayer player2) {
	// TODO Auto-generated method stub
	if (event.powerupIsAvailable == true) {//you are using client-only player field while being on server side -> crash
//instead use the player argument from the method
//prefer using player.worldObj instead of your world field
		world.createExplosion(null, player.posX + 5, player.posY,
				player.posZ, 5.0F, false);
		world.createExplosion(null, player.posX - 5, player.posY,
				player.posZ, 5.0F, false);
		world.createExplosion(null, player.posX, player.posY,
				player.posZ + 5, 5.0F, false);
		world.createExplosion(null, player.posX, player.posY,
				player.posZ - 5, 5.0F, false);
		event.powerupIsAvailable = false;
	}
}
}

 

I tried doing this, but I have no idea on how to do that, I tried using EntityPlayerMP in each class, EntityPlayer and EntityPlayerMP both but nothing D: can you try to fix it at your own?

Posted

public class ExoArmorPowerup {

public static ExoServerTickHandler event;

public static void sendPacket(EntityPlayer player) {
	ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
	DataOutputStream dataOutputStream = new DataOutputStream(
			byteOutputStream);
	try {
		dataOutputStream.writeInt(player.entityId);//this info is unused when handling the packet ??
	} catch (Exception e) {
		e.printStackTrace();
	}
	Packet250CustomPayload packet = new Packet250CustomPayload(
			ExoServerPacketHandler.ARMORPOWERUP,
			byteOutputStream.toByteArray());

	FMLClientHandler.instance().sendPacket(packet);
}

public static void handlePacket(Packet250CustomPayload packet,
		EntityPlayer player) {
	// TODO Auto-generated method stub
	if (event.powerupIsAvailable == true) {
		player.worldObj.createExplosion(null, player.posX + 5, player.posY,
				player.posZ, 5.0F, false);
		player.worldObj.createExplosion(null, player.posX - 5, player.posY,
				player.posZ, 5.0F, false);
		player.worldObj.createExplosion(null, player.posX, player.posY,
				player.posZ + 5, 5.0F, false);
		player.worldObj.createExplosion(null, player.posX, player.posY,
				player.posZ - 5, 5.0F, false);
		event.powerupIsAvailable = false;
	}
}
}

public class ExoServerKeyHandler extends KeyHandler {

public static KeyBinding armorPowerup = new KeyBinding("Armor's Powerup",
		Keyboard.KEY_F);

public static KeyBinding[] arrayOfKeys = new KeyBinding[] { armorPowerup };
public static boolean[] areRepeating = new boolean[] { false };

public ExoServerKeyHandler() {
	super(arrayOfKeys, areRepeating);
}

@Override
public String getLabel() {
	return "ExotiumWorld's ServerKeyHandler";
}

@Override
public void keyDown(EnumSet<TickType> types, KeyBinding kb,
		boolean tickEnd, boolean isRepeat) {
	if(kb.keyCode == armorPowerup.keyCode) {
		if(tickEnd)
		 {
			 System.out.println("Key up");
			 ExoArmorPowerup.sendPacket(Minecraft.getMinecraft().thePlayer);
		 }
	}
}

@Override
public void keyUp(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd) {
}

// FireModeHandler.switchFireMode();
@Override
public EnumSet<TickType> ticks() {
	return EnumSet.of(TickType.CLIENT);
}

}

Posted

public class ExoArmorPowerup {

public static ExoServerTickHandler event;

public static void sendPacket(EntityPlayer player) {
	ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
	DataOutputStream dataOutputStream = new DataOutputStream(
			byteOutputStream);
	try {
		dataOutputStream.writeInt(player.entityId);//this info is unused when handling the packet ??
	} catch (Exception e) {
		e.printStackTrace();
	}
	Packet250CustomPayload packet = new Packet250CustomPayload(
			ExoServerPacketHandler.ARMORPOWERUP,
			byteOutputStream.toByteArray());

	FMLClientHandler.instance().sendPacket(packet);
}

public static void handlePacket(Packet250CustomPayload packet,
		EntityPlayer player) {
	// TODO Auto-generated method stub
	if (event.powerupIsAvailable == true) {
		player.worldObj.createExplosion(null, player.posX + 5, player.posY,
				player.posZ, 5.0F, false);
		player.worldObj.createExplosion(null, player.posX - 5, player.posY,
				player.posZ, 5.0F, false);
		player.worldObj.createExplosion(null, player.posX, player.posY,
				player.posZ + 5, 5.0F, false);
		player.worldObj.createExplosion(null, player.posX, player.posY,
				player.posZ - 5, 5.0F, false);
		event.powerupIsAvailable = false;
	}
}
}

public class ExoServerKeyHandler extends KeyHandler {

public static KeyBinding armorPowerup = new KeyBinding("Armor's Powerup",
		Keyboard.KEY_F);

public static KeyBinding[] arrayOfKeys = new KeyBinding[] { armorPowerup };
public static boolean[] areRepeating = new boolean[] { false };

public ExoServerKeyHandler() {
	super(arrayOfKeys, areRepeating);
}

@Override
public String getLabel() {
	return "ExotiumWorld's ServerKeyHandler";
}

@Override
public void keyDown(EnumSet<TickType> types, KeyBinding kb,
		boolean tickEnd, boolean isRepeat) {
	if(kb.keyCode == armorPowerup.keyCode) {
		if(tickEnd)
		 {
			 System.out.println("Key up");
			 ExoArmorPowerup.sendPacket(Minecraft.getMinecraft().thePlayer);
		 }
	}
}

@Override
public void keyUp(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd) {
}

// FireModeHandler.switchFireMode();
@Override
public EnumSet<TickType> ticks() {
	return EnumSet.of(TickType.CLIENT);
}

}

 

Error on this statement:

if (event.powerupIsAvailable == true) { //java.lang.NullPointerException
		player.worldObj.createExplosion(null, player.posX + 5, player.posY,
				player.posZ, 5.0F, false);
		player.worldObj.createExplosion(null, player.posX - 5, player.posY,
				player.posZ, 5.0F, false);
		player.worldObj.createExplosion(null, player.posX, player.posY,
				player.posZ + 5, 5.0F, false);
		player.worldObj.createExplosion(null, player.posX, player.posY,
				player.posZ - 5, 5.0F, false);
		event.powerupIsAvailable = false;
	}

And there:

ExoArmorPowerup.handlePacket(packet, (EntityPlayer) player); //java.lang.NullPointerException

Posted

You never showed that ExoServerTickHandler class. I assumed it was working.

Anyway, this is another issue, which is probably easy to fix for you.

 

There is it:

package mods.exoworld.handler;

import java.util.EnumSet;

import mods.exoworld.Main;
import mods.exoworld.event.ExoArmorPowerup;
import mods.exoworld.item.ExoTNTHelmet;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;

public class ExoServerTickHandler implements ITickHandler {

public float counter = 49.0F;
public boolean powerupIsAvailable = false;
public ExoKeyHandler keyHandler;

public void onPlayerTick(EntityPlayer player) {
	ItemStack helmet = player.inventory.armorItemInSlot(3);
	ItemStack chestplate = player.inventory.armorItemInSlot(2);
	ItemStack leggings = player.inventory.armorItemInSlot(1);
	ItemStack boots = player.inventory.armorItemInSlot(0);
	if (player.inventory.armorItemInSlot(2) != null
			&& player.inventory.armorItemInSlot(1) != null
			&& player.inventory.armorItemInSlot(0) != null
			&& helmet.itemID == Main.ExoTNTHelmet.itemID
			&& chestplate.itemID == Main.ExoTNTChestplate.itemID
			&& leggings.itemID == Main.ExoTNTLeggings.itemID
			&& boots.itemID == Main.ExoTNTBoots.itemID) {
		player.fallDistance = 0.0F;
		System.out.println(counter);
		counter += 0.021F;
		if (counter > 50F && powerupIsAvailable == false) {
			player.sendChatToPlayer("ExoModChat: La tua armatura è possente! Premi F per scatenare la tua furia!");
			powerupIsAvailable = true;
		}
		if (powerupIsAvailable == true) {
			counter -= 5F;
			if (counter < 0F) {
				counter = 0F;
			}
		}
	}
}

@Override
public void tickStart(EnumSet<TickType> type, Object... tickData) {
	// TODO Auto-generated method stub
	if (type.equals(EnumSet.of(TickType.PLAYER))) {
		onPlayerTick((EntityPlayer) tickData[0]);
	}

}

@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData) {
	// TODO Auto-generated method stub
}

@Override
public EnumSet<TickType> ticks() {
	// TODO Auto-generated method stub
	return EnumSet.of(TickType.PLAYER, TickType.SERVER);
}

@Override
public String getLabel() {
	// TODO Auto-generated method stub
	return "ExotiumWorld's ServerTickHandler";
}

}

 

I FIXED IT!

 

I just put "static" on the boolean variable and in the counter variable, I excepted that ahaha thanks! +1 for the rest help!

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

    • Hello, I have this same problem. Did you manage to find a solution? Any help would be appreciated. Thanks.
    • log: https://mclo.gs/QJg3wYX as stated in the title, my game freezes upon loading into the server after i used a far-away waystone in it. The modpack i'm using is better minecraft V18. Issue only comes up in this specific server, singleplayer and other servers are A-okay. i've already experimented with removing possible culprits like modernfix and various others to no effect. i've also attempted a full reinstall of the modpack profile. Issue occurs shortly after the 'cancel' button dissapears on the 'loading world' section of the loading screen.   thanks in advance.
    • You would have better results asking a more specific question. What have you done? What exactly do you need help with? Please also read the FAQ regarding posting logs.
    • Hi, this is my second post with the same content as no one answered this and it's been a long time since I made the last post, I want to make a client-only mod, everything is ok, but when I use shaders, none of the textures rendered in RenderLevelStageEvent nor the crow entity model are rendered, I want them to be visible, because it's a horror themed mod I've already tried it with different shaders, but it didn't work with any of them and I really want to add support for shaders Here is how i render the crow model in the CrowEntityRenderer<CrowEntity>, by the time i use this method, i know is not the right method but i don't think this is the cause of the problem, the renderType i'm using is entityCutout @Override public void render(CrowEntity p_entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) { super.render(p_entity, entityYaw, partialTick, poseStack, bufferSource, packedLight); ClientEventHandler.getClient().crow.renderToBuffer(poseStack, bufferSource.getBuffer(ClientEventHandler.getClient().crow .renderType(TEXTURE)), packedLight, OverlayTexture.NO_OVERLAY, Utils.rgb(255, 255, 255)); } Here renderLevelStage @Override public void renderWorld(RenderLevelStageEvent e) { horrorEvents.draw(e); } Here is how i render every event public void draw(RenderLevelStageEvent e) { for (HorrorEvent event : currentHorrorEvents) { event.tick(e.getPartialTick()); event.draw(e); } } Here is how i render the crow model on the event @Override public void draw(RenderLevelStageEvent e) { if(e.getStage() == RenderLevelStageEvent.Stage.AFTER_ENTITIES) { float arcProgress = getArcProgress(0.25f); int alpha = (int) Mth.lerp(arcProgress, 0, 255); int packedLight = LevelRenderer.getLightColor(Minecraft.getInstance().level, blockPos); VertexConsumer builder = ClientEventHandler.bufferSource.getBuffer(crow); Crow<CreepyBirdHorrorEvent> model = ClientEventHandler .getClient().crow; model.setupAnim(this); RenderHelper.renderModelInWorld(model, position, offset, e.getCamera(), e.getPoseStack(), builder, packedLight, OverlayTexture.NO_OVERLAY, alpha); builder = ClientEventHandler.bufferSource.getBuffer(eyes); RenderHelper.renderModelInWorld(model, position, offset, e.getCamera(), e.getPoseStack(), builder, 15728880, OverlayTexture.NO_OVERLAY, alpha); } } How i render the model public static void renderModelInWorld(Model model, Vector3f pos, Vector3f offset, Camera camera, PoseStack matrix, VertexConsumer builder, int light, int overlay, int alpha) { matrix.pushPose(); Vec3 cameraPos = camera.getPosition(); double finalX = pos.x - cameraPos.x + offset.x; double finalY = pos.y - cameraPos.y + offset.y; double finalZ = pos.z - cameraPos.z + offset.z; matrix.pushPose(); matrix.translate(finalX, finalY, finalZ); matrix.mulPose(Axis.XP.rotationDegrees(180f)); model.renderToBuffer(matrix, builder, light, overlay, Utils .rgba(255, 255, 255, alpha)); matrix.popPose(); matrix.popPose(); } Thanks in advance
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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