Jump to content

Recommended Posts

Posted

Im lost trying to fix my entityclass. When i spawn the entity, the game crashes, sometimes the entity is being removed after one tick (F3+B so i saw the boundingbox dissappear). Im trying to make the movement client/server correct by 'simulating' it on the client and then updating it for the server. Diesieben07 told me that this was the right way. Well anyway, i can't see if it is correct, cuz my entity doesn't even spawn.

 

So here is the spawn code:

 

     			@Override
		public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn) {
			System.out.println("Placing " + f.vehicleName);
			BlockPos pos = Minecraft.getMinecraft().objectMouseOver.getBlockPos();
			if (!worldIn.isRemote && worldIn.getBlockState(pos).getBlock() != Blocks.air) {
				EntityVehicle vehicle = new EntityVehicle(worldIn, f, pos.getX(), pos.getY() + 1, pos.getZ());
				worldIn.spawnEntityInWorld(vehicle);
			}
			return itemStackIn;
		}

 

And here is the entity code:

 

 

  Reveal hidden contents

 

 

And here is the error that i get:

 

  Reveal hidden contents

 

  • Replies 60
  • Created
  • Last Reply

Top Posters In This Topic

Posted
  On 9/6/2015 at 4:38 PM, Failender said:

Well.. U should seriously clean up your workspace. Its like the first one hundred lines are errors that arent even related to this problem

 

I know, im waiting for a possibility to render objmodels as items. And i tried having a 2d texture for my block but somehow the model became invisible now, But thats another problem - any idea how i can fix that crash?

Posted

Okay - removed your name from the title and managed to spawn the entity. I found out that the VehicleFile (The file that defines how fast i tcan be, how to render it etc) is null. But i am setting it in the constructor. So - maybe im doing something wrong there?

 

Posted

public EntityVehicle(World world) {
	super(world);
	this.isEmpty = true;
	this.preventEntitySpawning = true;
	this.ignoreFrustumCheck = true;
	this.setSize(0.9999F, 1.5f);

}

 

So. Where are u setting file?

Posted

Im trying to fix that problem for over two weeks now. The spawning stuff was just a bug that appeard along the process. If you found the problem, please tell me i really have run out of possible fixing ideas. Even the mounting with pressing enter won't work(Well, thats because i don't know how to propperly send the entityvehicle that i want to mount in a packet).

 

Posted
  On 9/6/2015 at 5:14 PM, ItsAMysteriousYT said:

In that double constructor EntityVehicle(World w, VehicleFile f, double x, double y, double z)

 

More than one constructor: more than one place that the file needs to be specified.  The EntityVehicle(World) constructor will be called at some point.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

I think this method should normally work - as it does for the EntityBoat class too.

public boolean interactFirst(EntityPlayer player) {
	if (this.riddenByEntity != null && this.riddenByEntity instanceof EntityPlayer
			&& this.riddenByEntity != player) {
		return true;
	} else {
		if (!this.worldObj.isRemote) {
			player.mountEntity(this);
		}

		return true;
	}
}

I also looked if i probably cancel a PlayInteractWithEntityEvent or EntityInteractEvent somewhere, but didn't find anything.

 

 

EDIT:

 

There seam to be this error now, but it does not crash the game:

 

  Reveal hidden contents

 

Posted

Okay - can you help me mounting the entity with pressing enter? I know that ill have to send a packet, but not what to send in the packet. The player that should mount i have, but how can i get the entity that should be mounted/how can i send it?

Posted
  On 9/6/2015 at 6:31 PM, Failender said:

use the id of the entity, they are synced between server and client.

 

Correction:

Use the UUID.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
  On 9/6/2015 at 7:13 PM, diesieben07 said:

  Quote

use the id of the entity, they are synced between server and client.

 

Oh - didn't see that post from Failender, thank you :D

 

ALso - does anybody have an idea for that righclick problem? I checked every method, but found nothing that would explain that weird bug. Maybe im just blind :/

Posted

Okay - i wrote the packet, handler& stuff and now i call network.sendToServer() when the RETURN key is pressed, but somehow the vehicleEntity that i get from the id is null.

 

This is my packetHandler Code:

 

package itsamysterious.mods.reallifemod.core.packets;

import java.util.UUID;

import itsamysterious.mods.reallifemod.RealLifeMod;
import itsamysterious.mods.reallifemod.core.lifesystem.RLMPlayerProps;
import itsamysterious.mods.reallifemod.core.vehicles.EntityVehicle;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.IThreadListener;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;

public class MountHandler implements IMessageHandler<MountVehicleMessage, MountVehicleMessage>{

	@Override
	public MountVehicleMessage onMessage(final MountVehicleMessage message, final MessageContext ctx) {
		final EntityPlayer player = ctx.getServerHandler().playerEntity;
        IThreadListener mainThread = (WorldServer) ctx.getServerHandler().playerEntity.worldObj; // or Minecraft.getMinecraft() on the client
        mainThread.addScheduledTask(
        		new Runnable() {
            @Override
            public void run() {
    			World world = Minecraft.getMinecraft().theWorld;
    			
    			EntityVehicle v=(EntityVehicle)world.getEntityByID(message.vehicleId);
    			if(v!=null){
    				v.interactFirst(ctx.getServerHandler().playerEntity);
    			}
            }
        });
		return null;
	}

}

 

and this is my packet:

 

package itsamysterious.mods.reallifemod.core.packets;

import java.util.UUID;

import io.netty.buffer.ByteBuf;
import itsamysterious.mods.reallifemod.core.vehicles.EntityVehicle;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.registry.EntityRegistry;
import sun.awt.image.ByteBandedRaster;

public class MountVehicleMessage implements IMessage {
public int vehicleId;

public MountVehicleMessage(int id){
	this.vehicleId=id;
}

@Override
public void fromBytes(ByteBuf buf) {
	vehicleId = buf.readInt();
}

@Override
public void toBytes(ByteBuf buf) {
	buf.writeInt(vehicleId);
}

}

Posted

This happens:

 

  Reveal hidden contents

 

Posted

Heres is the updated packetCode:

 

package itsamysterious.mods.reallifemod.core.packets;

import java.util.UUID;

import io.netty.buffer.ByteBuf;
import itsamysterious.mods.reallifemod.core.vehicles.EntityVehicle;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.registry.EntityRegistry;
import sun.awt.image.ByteBandedRaster;

public class MountVehicleMessage implements IMessage {
public int vehicleId;

public MountVehicleMessage(){
}

public MountVehicleMessage(int id){
	this.vehicleId=id;
}

@Override
public void fromBytes(ByteBuf buf) {
	this.vehicleId = buf.readInt();
}

@Override
public void toBytes(ByteBuf buf) {
	buf.writeInt(this.vehicleId);
}

}

I created a keybinding now and registered it. I get the nearest entity from the client world(is that ok?) and then send the packet to mount the entity on the server. Anything wrong about this? Since you can't enter the vehicle while its driving, the client and server pos should be different right?

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.