Thanks will check it out, the entity being spawned on the client side is called by forge not my code yet the ID's are still different. As for my networking code, I used Jebelar's Minecrfat Forge tutorials for that, on his post it said 1.7.2, but that proballty changed with 1.7.10, Thanks, you've been very helpful and nice!
EDIT:
Forge is calling my custom constructor instead of the default world one when spawning client side, is that normal?
Thanks for the hint, will help a lot. The entity id being different is probally the reason the entity can't mount/attack the damn thing, the id difference wasn't always there it happened after I cahnged something in the GenericVehicleEntity & GenericVehiclePartEntity and I can't remember what it was, my packets don't actually send a request to spawn the entity with this Id, my item does that on the server world and then it automatically spawns on client side with the public Classname(World world) constructor.
public class ProcessPacketClientSide {
@SideOnly(Side.CLIENT)
public static void processPacketOnClient(ByteBuf parBB, Side parSide) throws IOException {
if (parSide == Side.CLIENT)
{
World theWorld = FMLClientHandler.instance().getWorldClient();
ByteBufInputStream bbis = new ByteBufInputStream(parBB);
int packetTypeID = bbis.readInt();
switch (packetTypeID)
{
case McVehicleMain.PACKET_ENTITY_SYNC:
{
int entityID = bbis.readInt();
Entity foundEntity = getEntityByID(entityID, theWorld);
EDIT:
Investigated my code, since you said the entity id's are supposed to be the same, and I have gotten closer, I realized, that spawing the children entities in the constructor messed with it, but the entity id's are still not the same, they are now 1 appart from eachother.
EDIT 2:
Here is what happens when I spawn the entity:
19:57:25] [Client thread/INFO] [STDOUT]: [com.marko5049.mcvehicle.entity.GenericVehicleEntity:<init>:154]: Is net.minecraft.client.multiplayer.WorldClient@2010f649a remote world? true, My id equals: 13701
[19:57:25] [Server thread/INFO] [STDOUT]: [com.marko5049.mcvehicle.entity.GenericVehicleEntity:<init>:154]: Is net.minecraft.world.WorldServer@28f3fbd9a remote world? false, My id equals: 13802
Sorry about the layout, it's been a couple of years since I last made a post here and things have changed a lot. I have tried to send packets to the server and sync the server and client world that way, and it works except I cant actually refrence the entity on the server because the entity id is always different that the client entity id, to be exact the server id is always 2 higher than the client id, I could just add 2 to the id, but it doesn't seem reliable and from experience is bad practise. Is there some way that i'm missing?
Hey Guys,
I've been working on a new mod with a fellow coder who has been doing the weapons part, and he seems to know hwta he's doing, I however am responsible for the vehicles and because I've never really fiddled around with entities other than projectiles I can't figuire out what the problem is, ok here's the scenario; I have an entity being spawned in using an item (basicly ItemBoat with my entity) that acts like a wrapper from it's child entities that are spawned in it's constructor when it's spawned. The children call method in the parent class like forward, back, left, right etc to handle movment and so forth, but for some reason when ever the player ineract with the entity in any way 'this.worldObj.isRemote' always returns true, even though before spawing the entity I have the 'world.isRemote' check, and when doing some profiling I've concluded that; The item spawns a server side entity and then minecraft forge spawns a client one using the default 'public EntityWhatever(World world)' constructor, and whenever that player interacts with the entity (Keys pressed, attacking it, trying to mount etc) it is only on the client world, but when cross checking with EntityBoat.class the code is effectivly the same and I cannot figuire this one out after 2 days of debuging, also before I show you guys the code, I do use my ownkey input handler, my own event handler and my own FMLEventChannel.
McVehicleMain.class:
Mod(modid=McVehicleMain.modid, version="0.1", guiFactory="com.marko5049.mcvehicle.main.ModGuiFactory")
public class McVehicleMain extends GenericVehicleMod {
private File CPD;
public static final String modid = "marko5049_MCV";
public static final String networkChannelName = "MCV";
public static Configuration config;
public static final String creativeTabIcon = "test";
public static float fuelEffeciency = 1.0f;
public static FMLEventChannel eventChannel;
public static final int PACKET_ENTITY_SYNC = 1;
public static final int PACKET_C2S_TEST = 1;
@Mod.Instance(modid)
public static McVehicleMain Instance;
@SidedProxy(clientSide="com.marko5049.mcvehicle.main.ClientProxy", serverSide="com.marko5049.mcvehicle.main.CommonProxy")
public static CommonProxy proxy;
public McVehicleMain() {
super();
}
public static GenericVehicle vehicle1;
@EventHandler
public void preInit(FMLPreInitializationEvent e) {
super.create("TestPack");
this.eventChannel = NetworkRegistry.INSTANCE.newEventDrivenChannel(networkChannelName);
proxy.init(this.eventChannel);
FMLCommonHandler.instance().bus().register(new KeyInputHandler());
this.config = new Configuration(e.getSuggestedConfigurationFile());
syncConfig();
}
@EventHandler
public void init(FMLInitializationEvent e) {
Item CreativeTabIcon = new Item().setUnlocalizedName("creativeTabIcon" + modid).setTextureName(modid+":"+creativeTabIcon);
GameRegistry.registerItem(CreativeTabIcon, "creativeTabIcon" + modid);
super.init(CreativeTabIcon);
ArrayList<GenericVehiclePart> vehicle1Parts = new ArrayList<GenericVehiclePart>();
vehicle1Parts.add(new GenericSeat(SeatType.Driver, new ResourceLocation("textures/entity/minecart.png"), new ModelCar()).setOffset(new Vector3f(0, 0, 0)));
vehicle1 = new GenericVehicle(this, new GenericVehicleEntityHandler(vehicle1Parts, new GenericVehicleEntityRenderer()), "Test Vehicle", modid+":" + "test");
proxy.load();
}
@EventHandler
public void postInit(FMLPostInitializationEvent e) {
}
@SubscribeEvent
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent e) {
if(e.modID.equals(modid))
syncConfig();
}
private void syncConfig() {
fuelEffeciency = this.config.getFloat("Fuel Effeciency", "general", 1.0f, 0.1f, 2.0f, "A multiplier(Vehicle's Fuel Effeciency = Default Fuel Effeciency * Fuel Effeciency) that affects how long fuel lasts.");
if(this.config.hasChanged()) {
this.config.save();
}
}
public void setVariables(ArrayList<GenericVehiclePart> vehicleParts, GenericVehicleEntityHandler handler, GenericVehicleEntityRenderer renderer) {
this.handler = handler;
this.renderer = renderer;
this.vehicleParts = vehicleParts;
}/**
* returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
* prevent them from trampling crops
*/
protected boolean canTriggerWalking()
{
return false;
}
protected void entityInit()
{
this.dataWatcher.addObject(30, new Integer(0));
this.dataWatcher.addObject(31, new Integer(1));
this.dataWatcher.addObject(26, new Float(0.0F));
}
/**
* Returns a boundingBox used to collide the entity with other entities and blocks. This enables the entity to be
* pushable on contact, like moveables or minecarts.
*/
public AxisAlignedBB getCollisionBox(Entity par1Entity)
{
return par1Entity.boundingBox;
}
/**
* returns the bounding box for this entity
*/
public AxisAlignedBB getBoundingBox()
{
return this.boundingBox;
}
/**
* Returns true if this entity should push and be pushed by other entities when colliding.
*/
public boolean canBePushed()
{
return false;
}
public GenericVehicleEntity(World par1World, double par2, double par4, double par6, ArrayList<GenericVehiclePart> vehicleParts, GenericVehicleEntityHandler handler, GenericVehicleEntityRenderer renderer)
{
super(par1World);
this.setPosition(par2, par4, par6);
this.motionX = 0.0D;
this.motionY = 0.0D;
this.motionZ = 0.0D;
this.prevPosX = par2;
this.prevPosY = par4;
this.prevPosZ = par6;
this.handler = handler;
this.setSize(0.0f, 0.0f);
System.out.println("Is " + par1World + "a remote world? " + par1World.isRemote + ", My id equals: " + this.getEntityId());
this.renderer = renderer;
this.vehicleParts = vehicleParts;
this.vehiclePartEntities = new ArrayList<GenericVehiclePartEntity>();
for(GenericVehiclePart part : this.vehicleParts) {
switch(part.getType()) {
case Invalid:
break;
case FrontWheel:
GenericVehiclePartEntity fEntity = new GenericVehiclePartEntity(par1World, ((GenericFrontWheel)part), this);
this.vehiclePartEntities.add(fEntity);
par1World.spawnEntityInWorld(fEntity);
break;
case BackWheel:
GenericVehiclePartEntity bEntity = new GenericVehiclePartEntity(par1World, ((GenericBackWheel)part), this);
this.vehiclePartEntities.add(bEntity);
par1World.spawnEntityInWorld(bEntity);
break;
case Door:
GenericVehiclePartEntity dEntity = new GenericVehiclePartEntity(par1World, ((GenericDoor)part), this);
this.vehiclePartEntities.add(dEntity);
par1World.spawnEntityInWorld(dEntity);
break;
case Window:
GenericVehiclePartEntity wEntity = new GenericVehiclePartEntity(par1World, ((GenericWindow)part), this);
this.vehiclePartEntities.add(wEntity);
par1World.spawnEntityInWorld(wEntity);
break;
case Chasis:
GenericVehiclePartEntity chEntity = new GenericVehiclePartEntity(par1World, ((GenericChasis)part), this);
this.vehiclePartEntities.add(chEntity);
par1World.spawnEntityInWorld(chEntity);
break;
case Seat:
GenericVehiclePartEntity sEntity = new GenericVehiclePartEntity(par1World, ((GenericSeat)part), this);
this.vehiclePartEntities.add(sEntity);
par1World.spawnEntityInWorld(sEntity);
break;
case Connector:
GenericVehiclePartEntity cEntity = new GenericVehiclePartEntity(par1World, ((GenericConnector)part), this);
this.vehiclePartEntities.add(cEntity);
par1World.spawnEntityInWorld(cEntity);
break;
case Gunner:
GenericVehiclePartEntity gEntity = new GenericVehiclePartEntity(par1World, ((GenericGunner)part), this);
this.vehiclePartEntities.add(gEntity);
par1World.spawnEntityInWorld(gEntity);
break;
case Light:
GenericVehiclePartEntity lEntity = new GenericVehiclePartEntity(par1World, ((GenericLight)part), this);
this.vehiclePartEntities.add(lEntity);
par1World.spawnEntityInWorld(lEntity);
break;
}
}
sync();
}
/**
* Called when the entity is attacked.
*/
public boolean shouldDie = false;
public boolean attackEntityFrom(DamageSource par1DamageSource, float par2)
{
if (!this.worldObj.isRemote && !this.isDead)
{
this.setForwardDirection(-this.getForwardDirection());
this.setTimeSinceHit(10);
this.setDamageTaken(this.getDamageTaken() + par2 * 10.0F);
this.setBeenAttacked();
boolean flag = par1DamageSource.getEntity() instanceof EntityPlayer && ((EntityPlayer)par1DamageSource.getEntity()).capabilities.isCreativeMode;
if (flag || this.getDamageTaken() > 40.0F)
{
if (this.riddenByEntity != null)
{
this.riddenByEntity.mountEntity(this);
}
//this.die();
this.shouldDie = true;
sync();
}
return true;
}
else
{
return true;
}
}
@SideOnly(Side.CLIENT)
/**
* Setups the entity to do the hurt animation. Only used by packets in multiplayer.
*/
public void performHurtAnimation()
{
for(GenericVehiclePartEntity part : vehiclePartEntities) {
part.doHurtAnimation();
}
}
@Override
public boolean canBeCollidedWith() {
return true;
}
@SideOnly(Side.CLIENT)
/**
* Sets the position and rotation. Only difference from the other one is no bounding on the rotation. Args: posX,
* posY, posZ, yaw, pitch
*/
public void setPositionAndRotation2(double par1, double par3, double par5, float par7, float par8, int par9, float par10)
{
if (this.field_70279_a)
{
this.moveablePosRotationIncrements = par9 + 5;
}
else
{
double d3 = par1 - this.posX;
double d4 = par3 - this.posY;
double d5 = par5 - this.posZ;
double d6 = d3 * d3 + d4 * d4 + d5 * d5;
if (d6 <= 1.0D)
{
return;
}
this.moveablePosRotationIncrements = 3;
}
this.moveableX = par1;
this.moveableY = par3;
this.moveableZ = par5;
this.moveableYaw = (double)par7;
this.moveablePitch = (double)par8;
this.moveableRoll = (double)par10;
this.motionX = this.velocityX;
this.motionY = this.velocityY;
this.motionZ = this.velocityZ;
}
@SideOnly(Side.CLIENT)
/**
* Sets the velocity to the args. Args: x, y, z
*/
public void setVelocity(double par1, double par3, double par5)
{
this.velocityX = this.motionX = par1;
this.velocityY = this.motionY = par3;
this.velocityZ = this.motionZ = par5;
}
/**
* Called to update the entity's position/logic.
*/
public void onUpdate()
{
super.onUpdate();
if (this.getTimeSinceHit() > 0)
{
this.setTimeSinceHit(this.getTimeSinceHit() - 1);
}
if (this.getDamageTaken() > 0.0F)
{
this.setDamageTaken(this.getDamageTaken() - 1.0F);
}
protected void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) {}
@SideOnly(Side.CLIENT)
public float getShadowSize()
{
return 0.5F;
}
/**
* Sets the damage taken from the last hit.
*/
public void setDamageTaken(float par1)
{
this.dataWatcher.updateObject(26, Float.valueOf(par1));
}
/**
* Gets the damage taken from the last hit.
*/
public float getDamageTaken()
{
return this.dataWatcher.getWatchableObjectFloat(26);
}
/**
* Sets the time to count down from since the last time entity was hit.
*/
public void setTimeSinceHit(int par1)
{
this.dataWatcher.updateObject(30, Integer.valueOf(par1));
}
/**
* Gets the time since the last hit.
*/
public int getTimeSinceHit()
{
return this.dataWatcher.getWatchableObjectInt(30);
}
/**
* Sets the forward direction of the entity.
*/
public void setForwardDirection(int par1)
{
this.dataWatcher.updateObject(31, Integer.valueOf(par1));
}
/**
* Gets the forward direction of the entity.
*/
public int getForwardDirection()
{
return this.dataWatcher.getWatchableObjectInt(31);
}
@SideOnly(Side.CLIENT)
public void func_70270_d(boolean par1)
{
this.field_70279_a = par1;
}
public GenericVehiclePart getVehiclePart() {
return this.part;
}
/**
* returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
* prevent them from trampling crops
*/
protected boolean canTriggerWalking()
{
return false;
}protected void entityInit()
{
this.dataWatcher.addObject(27, new Integer(0));
this.dataWatcher.addObject(28, new Integer(1));
this.dataWatcher.addObject(29, new Float(0.0F));
}
/**
* Returns a boundingBox used to collide the entity with other entities and blocks. This enables the entity to be
* pushable on contact, like moveables or minecarts.
*/
public AxisAlignedBB getCollisionBox(Entity par1Entity)
{
return par1Entity.boundingBox;
}
/**
* returns the bounding box for this entity
*/
public AxisAlignedBB getBoundingBox()
{
return this.boundingBox;
}
/**
* Returns true if this entity should push and be pushed by other entities when colliding.
*/
public boolean canBePushed()
{
return false;
}
/**
* Returns the Y offset from the entity's position for any entity riding this one.
*/
public double getMountedYOffset()
{
return (double)this.height * 0.0D - 0.30000001192092896D + parent.yOffset;
}
/**
* Called when the entity is attacked.
*/
public boolean attackEntityFrom(DamageSource par1DamageSource, float par2)
{
return parent.attackEntityFrom(par1DamageSource, par2);
}
@SideOnly(Side.CLIENT)
/**
* Setups the entity to do the hurt animation. Only used by packets in multiplayer.
*/
public void performHurtAnimation()
{
this.parent.performHurtAnimation();
}
/**
* Sets the damage taken from the last hit.
*/
public void setDamageTaken(float par1)
{
this.dataWatcher.updateObject(29, Float.valueOf(par1));
}
/**
* Gets the damage taken from the last hit.
*/
public float getDamageTaken()
{
return this.dataWatcher.getWatchableObjectFloat(29);
}
/**
* Sets the time to count down from since the last time entity was hit.
*/
public void setTimeSinceHit(int par1)
{
this.dataWatcher.updateObject(27, Integer.valueOf(par1));
}
/**
* Gets the time since the last hit.
*/
public int getTimeSinceHit()
{
return this.dataWatcher.getWatchableObjectInt(27);
}
/**
* Sets the forward direction of the entity.
*/
public void setForwardDirection(int par1)
{
this.dataWatcher.updateObject(28, Integer.valueOf(par1));
}
/**
* Gets the forward direction of the entity.
*/
public int getForwardDirection()
{
return this.dataWatcher.getWatchableObjectInt(28);
}
@SideOnly(Side.CLIENT)
public void func_70270_d(boolean par1)
{
this.field_70279_a = par1;
}
Sorry guys, I barley ever check updates on this website it is supposed to email me but didn't until Leoz just posted.. I'll send you source code via skype, im MARKO5049. All that really needs to be done is;
- Generic Rendering Class (I have basic framework setup, you can do it if you want)
- Generic Entity Class (Constructor is made, lol great progress, this is something you might be intrested in)
- Generic Vehicle Physics
- Vehicle Crafting System (I can do this if you don't want to)
- And Vehicle Dev Kit for any content creators (i'll do this)
Just do whatever you feel like. Ok the basic idea of this mod is; This mod is a core mod that adds a generic vehicle system (physics & graphics) for other people to use. I plan on making a software suit that allows for simple creation of the vehicles.
Things I would like the mod to have:
For Players;
-Contents packs, hence core mod.
-SMP & SSP
-Proper Controls
-Proper Physics (Basicly the point of the mod, flans mod physics are, well meh)
-Lighting (Headlights and all that stuff actually work)
-Mountable Weapons
Code (Our job):
-Generic Physics (Proper controls, Proper collision detection & because every car mod needs it, detachable pivot points, basicly attach/detach gun to car at attach point or even attach a trailer at pivot point)
-Generic Rendering
-Generic Audio
-Generic Lighting
-Optimized Packet Handling
Also i'm using a component based architecture for the vehicles and That's it!
This mod is discontinued but if you want I could send you the code for the mod or if you wanted to code vehicles I'm making a new mod that focuses on just vehicles, any help would be appreciated.
0
EDIT:
Forge is calling my custom constructor instead of the default world one when spawning client side, is that normal?
0
Here is my networking code, now with spoilers!
import java.io.IOException;
import net.minecraft.entity.Entity;
import com.marko5049.mcvehicle.entity.GenericVehicleEntity;
import com.marko5049.mcvehicle.entity.GenericVehiclePartEntity;
import io.netty.buffer.ByteBufOutputStream;
import io.netty.buffer.Unpooled;
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
public class CreatePacketClientSide {
public static FMLProxyPacket createEntityPacket(Entity parEntity) throws IOException
{
ByteBufOutputStream bbos = new ByteBufOutputStream(Unpooled.buffer());
bbos.writeInt(McVehicleMain.PACKET_ENTITY_SYNC);
bbos.writeInt(parEntity.getEntityId());
if (parEntity instanceof GenericVehicleEntity) {
GenericVehicleEntity entity = (GenericVehicleEntity)parEntity;
bbos.writeDouble(entity.posX);
bbos.writeDouble(entity.posZ);
bbos.writeDouble(entity.posZ);
bbos.writeFloat(entity.rotationPitch);
bbos.writeFloat(entity.rotationYaw);
bbos.writeFloat(entity.rotationRoll);
bbos.writeBoolean(entity.shouldDie);
bbos.writeFloat(entity.wheelYaw);
} else if (parEntity instanceof GenericVehiclePartEntity) {
GenericVehiclePartEntity entity = (GenericVehiclePartEntity)parEntity;
bbos.writeDouble(entity.posX);
bbos.writeDouble(entity.posZ);
bbos.writeDouble(entity.posZ);
bbos.writeFloat(entity.rotationPitch);
bbos.writeFloat(entity.rotationYaw);
bbos.writeFloat(entity.rotationRoll);
bbos.writeBoolean(entity.getParent().shouldDie);
bbos.writeFloat(entity.getWheelYaw());
bbos.writeFloat(entity.getWheelSpin());
bbos.writeBoolean(entity.riddenByEntity != null);
if(entity.riddenByEntity != null) bbos.writeInt(entity.riddenByEntity.getEntityId());
}
FMLProxyPacket thePacket = new FMLProxyPacket(bbos.buffer(), McVehicleMain.networkChannelName);
bbos.close();
return thePacket;
}
public static void sendToServer(FMLProxyPacket parPacket)
{
McVehicleMain.eventChannel.sendToServer(parPacket);
}
public static void sendC2SEntitySync(Entity entity) {
try
{
sendToServer(createEntityPacket(entity));
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
import io.netty.buffer.ByteBufOutputStream;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import net.minecraft.entity.Entity;
import com.marko5049.mcvehicle.entity.GenericVehicleEntity;
import com.marko5049.mcvehicle.entity.GenericVehiclePartEntity;
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
public class CreatePacketServerSide {
public static FMLProxyPacket createEntityPacket(Entity parEntity) throws IOException
{
ByteBufOutputStream bbos = new ByteBufOutputStream(Unpooled.buffer());
bbos.writeInt(McVehicleMain.PACKET_ENTITY_SYNC);
bbos.writeInt(parEntity.getEntityId());
if (parEntity instanceof GenericVehicleEntity) {
GenericVehicleEntity entity = (GenericVehicleEntity)parEntity;
bbos.writeDouble(entity.posX);
bbos.writeDouble(entity.posZ);
bbos.writeDouble(entity.posZ);
bbos.writeFloat(entity.rotationPitch);
bbos.writeFloat(entity.rotationYaw);
bbos.writeFloat(entity.rotationRoll);
bbos.writeBoolean(entity.shouldDie);
bbos.writeFloat(entity.wheelYaw);
} else if (parEntity instanceof GenericVehiclePartEntity) {
GenericVehiclePartEntity entity = (GenericVehiclePartEntity)parEntity;
bbos.writeDouble(entity.posX);
bbos.writeDouble(entity.posZ);
bbos.writeDouble(entity.posZ);
bbos.writeFloat(entity.rotationPitch);
bbos.writeFloat(entity.rotationYaw);
bbos.writeFloat(entity.rotationRoll);
bbos.writeBoolean(entity.getParent().shouldDie);
bbos.writeFloat(entity.getWheelYaw());
bbos.writeFloat(entity.getWheelSpin());
bbos.writeBoolean(entity.riddenByEntity != null);
if(entity.riddenByEntity != null) bbos.writeInt(entity.riddenByEntity.getEntityId());
}
FMLProxyPacket thePacket = new FMLProxyPacket(bbos.buffer(), McVehicleMain.networkChannelName);
bbos.close();
return thePacket;
}
public static void sendToAll(FMLProxyPacket parPacket)
{
McVehicleMain.eventChannel.sendToAll(parPacket);
}
public static void sendS2CEntitySync(Entity parEntity)
{
try
{
sendToAll(createEntityPacket(parEntity));
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
import java.io.IOException;
import com.marko5049.mcvehicle.entity.GenericVehicleEntity;
import com.marko5049.mcvehicle.entity.GenericVehiclePartEntity;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufInputStream;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.world.World;
public class ProcessPacketClientSide {
@SideOnly(Side.CLIENT)
public static void processPacketOnClient(ByteBuf parBB, Side parSide) throws IOException {
if (parSide == Side.CLIENT)
{
World theWorld = FMLClientHandler.instance().getWorldClient();
ByteBufInputStream bbis = new ByteBufInputStream(parBB);
int packetTypeID = bbis.readInt();
switch (packetTypeID)
{
case McVehicleMain.PACKET_ENTITY_SYNC:
{
int entityID = bbis.readInt();
Entity foundEntity = getEntityByID(entityID, theWorld);
if (foundEntity instanceof GenericVehicleEntity) {
GenericVehicleEntity entity = (GenericVehicleEntity)foundEntity;
entity.posX = bbis.readDouble();
entity.posY = bbis.readDouble();
entity.posZ = bbis.readDouble();
entity.rotationPitch = bbis.readFloat();
entity.rotationYaw = bbis.readFloat();
entity.rotationRoll = bbis.readFloat();
if(bbis.readBoolean()) entity.die(theWorld);
entity.wheelYaw = bbis.readFloat();
} else if (foundEntity instanceof GenericVehiclePartEntity) {
GenericVehiclePartEntity entity = (GenericVehiclePartEntity)foundEntity;
entity.posX = bbis.readDouble();
entity.posY = bbis.readDouble();
entity.posZ = bbis.readDouble();
entity.rotationPitch = bbis.readFloat();
entity.rotationYaw = bbis.readFloat();
entity.rotationRoll = bbis.readFloat();
if(bbis.readBoolean()) entity.getParent().die(theWorld);
entity.setWheelYaw(bbis.readFloat());
entity.wheelSpin = bbis.readFloat();
if(bbis.readBoolean()) entity.riddenByEntity = getEntityByID(bbis.readInt(), FMLClientHandler.instance().getWorldClient());
else entity.riddenByEntity = null;
}
break;
}
}
bbis.close();
}
}
public static Entity getEntityByID(int entityID, World world)
{
for(Object o: world.getLoadedEntityList())
{
if(((Entity)o).getEntityId() == entityID)
{
return ((Entity)o);
}
}
return null;
}
}
import java.io.IOException;
import com.marko5049.mcvehicle.entity.GenericVehicleEntity;
import com.marko5049.mcvehicle.entity.GenericVehiclePartEntity;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.world.World;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.server.FMLServerHandler;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufInputStream;
public class ProcessPacketServerSide {
public static void processPacketOnServer(ByteBuf parBB, Side parSide, EntityPlayerMP parPlayer) throws IOException
{
if (parSide == Side.SERVER)
{
World theWorld;
if(Minecraft.getMinecraft().getIntegratedServer() != null && Minecraft.getMinecraft().getIntegratedServer().getEntityWorld() != null) {
theWorld = Minecraft.getMinecraft().getIntegratedServer().getEntityWorld();
} else if(FMLServerHandler.instance().getServer() != null && FMLServerHandler.instance().getServer().getEntityWorld() != null) {
theWorld = FMLServerHandler.instance().getServer().getEntityWorld();
} else {
theWorld = Minecraft.getMinecraft().theWorld;
}
ByteBufInputStream bbis = new ByteBufInputStream(parBB);
int packetTypeID = bbis.readInt();
switch (packetTypeID)
{
case McVehicleMain.PACKET_ENTITY_SYNC:
{
int entityID = bbis.readInt();
Entity foundEntity = getEntityByID(entityID, theWorld);
if (foundEntity instanceof GenericVehicleEntity) {
GenericVehicleEntity entity = (GenericVehicleEntity)foundEntity;
entity.posX = bbis.readDouble();
entity.posY = bbis.readDouble();
entity.posZ = bbis.readDouble();
entity.rotationPitch = bbis.readFloat();
entity.rotationYaw = bbis.readFloat();
entity.rotationRoll = bbis.readFloat();
if(bbis.readBoolean()) {
System.out.println("Told to die");
entity.die(theWorld);
}
entity.wheelYaw = bbis.readFloat();
} else if (foundEntity instanceof GenericVehiclePartEntity) {
GenericVehiclePartEntity entity = (GenericVehiclePartEntity)foundEntity;
entity.posX = bbis.readDouble();
entity.posY = bbis.readDouble();
entity.posZ = bbis.readDouble();
entity.rotationPitch = bbis.readFloat();
entity.rotationYaw = bbis.readFloat();
entity.rotationRoll = bbis.readFloat();
if(bbis.readBoolean()) {
System.out.println("Told to die");
entity.getParent().die(theWorld);
}
entity.setWheelYaw(bbis.readFloat());
entity.wheelSpin = bbis.readFloat();
if(bbis.readBoolean()) entity.riddenByEntity = getEntityByID(bbis.readInt(), theWorld);
else entity.riddenByEntity = null;
CreatePacketServerSide.sendS2CEntitySync(entity);
}
break;
}
}
bbis.close();
}
}
public static Entity getEntityByID(int entityID, World world)
{
for(Object o: world.getLoadedEntityList())
{
if(((Entity)o).getEntityId() == entityID)
{
return ((Entity)o);
}
}
return null;
}
}
Thanks So Much!
EDIT:
Investigated my code, since you said the entity id's are supposed to be the same, and I have gotten closer, I realized, that spawing the children entities in the constructor messed with it, but the entity id's are still not the same, they are now 1 appart from eachother.
EDIT 2:
Here is what happens when I spawn the entity:
0
0
I've been working on a new mod with a fellow coder who has been doing the weapons part, and he seems to know hwta he's doing, I however am responsible for the vehicles and because I've never really fiddled around with entities other than projectiles I can't figuire out what the problem is, ok here's the scenario; I have an entity being spawned in using an item (basicly ItemBoat with my entity) that acts like a wrapper from it's child entities that are spawned in it's constructor when it's spawned. The children call method in the parent class like forward, back, left, right etc to handle movment and so forth, but for some reason when ever the player ineract with the entity in any way 'this.worldObj.isRemote' always returns true, even though before spawing the entity I have the 'world.isRemote' check, and when doing some profiling I've concluded that; The item spawns a server side entity and then minecraft forge spawns a client one using the default 'public EntityWhatever(World world)' constructor, and whenever that player interacts with the entity (Keys pressed, attacking it, trying to mount etc) it is only on the client world, but when cross checking with EntityBoat.class the code is effectivly the same and I cannot figuire this one out after 2 days of debuging, also before I show you guys the code, I do use my ownkey input handler, my own event handler and my own FMLEventChannel.
McVehicleMain.class:
GenericVehicleEntity.class
GenericVehiclePartEntity.class:
And ClientProxy.class & CommomPoxy.class:
Thanks Guys!
0
0
0
- Generic Rendering Class (I have basic framework setup, you can do it if you want)
- Generic Entity Class (Constructor is made, lol great progress, this is something you might be intrested in)
- Generic Vehicle Physics
- Vehicle Crafting System (I can do this if you don't want to)
- And Vehicle Dev Kit for any content creators (i'll do this)
Just do whatever you feel like. Ok the basic idea of this mod is; This mod is a core mod that adds a generic vehicle system (physics & graphics) for other people to use. I plan on making a software suit that allows for simple creation of the vehicles.
Things I would like the mod to have:
For Players;
-Contents packs, hence core mod.
-SMP & SSP
-Proper Controls
-Proper Physics (Basicly the point of the mod, flans mod physics are, well meh)
-Lighting (Headlights and all that stuff actually work)
-Mountable Weapons
For Content Creators:
-Vehicle Creator Software (Lighting, physics, rendering, animation etc.)
-Flexible & in-depth options
-Minecraft Model & OBJ file formats
Code (Our job):
-Generic Physics (Proper controls, Proper collision detection & because every car mod needs it, detachable pivot points, basicly attach/detach gun to car at attach point or even attach a trailer at pivot point)
-Generic Rendering
-Generic Audio
-Generic Lighting
-Optimized Packet Handling
Also i'm using a component based architecture for the vehicles and That's it!
Btw I can host test server.
0
-Regards
marko5049
0
0
0
0
0
0
0