finally fixed minecart door crashes

Signed-off-by: StevenRS11 <stevenrs11@aol.com>
This commit is contained in:
StevenRS11
2013-04-30 20:52:57 -04:00
parent c3fda5abff
commit 103e674e83
3 changed files with 126 additions and 57 deletions

View File

@@ -8,12 +8,17 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.world.World;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteStreams;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.network.FMLNetworkHandler;
import cpw.mods.fml.common.network.IPacketHandler;
import cpw.mods.fml.common.network.PacketDispatcher;
import cpw.mods.fml.common.network.Player;
@@ -25,6 +30,7 @@ public class PacketHandler implements IPacketHandler
public static int removeLinkPacketID = 5;
public static int linkKeyPacketID = 7;
public static int dimPacketID = 6;
public static int updateRiderPacketID = 8;
public static int dimUpdatePacketID = 1;
@@ -143,6 +149,23 @@ public class PacketHandler implements IPacketHandler
dimHelper.instance.interDimLinkList.put(data.readInt(), link);
}
if(id==this.updateRiderPacketID)
{
int mountID=data.readInt();
EntityPlayer playerSP = FMLClientHandler.instance().getClient().thePlayer;
World world = playerSP.worldObj;
Entity mount = world.getEntityByID(mountID);
//playerSP.mountEntity(mount);
//playerSP.ridingEntity=mount;
//mount.riddenByEntity=playerSP;
playerSP.updateRiderPosition();
//mount.updateRidden();
}
}
@@ -410,6 +433,37 @@ public class PacketHandler implements IPacketHandler
}
}
public static Packet250CustomPayload sendUpdateRiderPacket(int id)
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dataOut = new DataOutputStream(bos);
try
{
dataOut.writeByte(PacketHandler.updateRiderPacketID);
dataOut.writeInt(id);
}
catch (IOException e)
{
e.printStackTrace();
}
Packet250CustomPayload packet= new Packet250CustomPayload();
packet.channel="DimDoorPackets";
packet.data = bos.toByteArray();
packet.length = bos.size();;
PacketDispatcher.sendPacketToAllPlayers(packet);
return packet;
}
}

View File

@@ -99,34 +99,31 @@ public class dimDoor extends BlockContainer
linkData= dimHelper.instance.getLinkDataFromCoords(par2, par3+1, par4, par1World);
}
if(!(par5Entity instanceof EntityPlayer)&&num>3)
{
this.onPoweredBlockChange(par1World, par2, par3, par4, false);
dimHelper.instance.teleportToPocket(par1World, linkData, par5Entity);
}
if(!par1World.isRemote&&(num==5||num==4||num==6||num==7)&&(num-4)==var12)
else if(!par1World.isRemote&&(num==5||num==4||num==6||num==7)&&(num-4)==var12)
{
//int destinationID= dimHelper.instance.getDestIDFromCoords(par2, par3, par4, par1World);
//if(par5Entity instanceof EntityLiving)
{
this.onPoweredBlockChange(par1World, par2, par3, par4, false);
}
dimHelper.instance.teleportToPocket(par1World, linkData, par5Entity);
}
else if (!(par5Entity instanceof EntityPlayer)&&num>3)
{
if(par5Entity instanceof EntityLiving)
{
this.onPoweredBlockChange(par1World, par2, par3, par4, false);
}
dimHelper.instance.teleportToPocket(par1World, linkData, par5Entity);
}

View File

@@ -25,6 +25,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet10Flying;
import net.minecraft.network.packet.Packet39AttachEntity;
import net.minecraft.network.packet.Packet41EntityEffect;
import net.minecraft.network.packet.Packet43Experience;
@@ -135,29 +136,26 @@ public class dimHelper extends DimensionManager
private Entity teleportEntity(World oldWorld, Entity entity, LinkData link) //this beautiful teleport method is based off of xCompWiz's teleport function.
{
Entity cart;
Entity cart=entity.ridingEntity;
if(entity.riddenByEntity!=null)
{
cart= entity;
entity=entity.riddenByEntity;
return this.teleportEntity(oldWorld,entity.riddenByEntity, link);
}
else
{
cart = entity.ridingEntity;
}
if (entity.ridingEntity != null)
{
entity.mountEntity(entity.ridingEntity);
entity.mountEntity(null);
cart = teleportEntity(oldWorld, cart, link);
}
WorldServer newWorld;
if(this.getWorld(link.destDimID)==null)
@@ -176,6 +174,7 @@ public class dimHelper extends DimensionManager
}
mod_pocketDim.teleporter.placeInPortal(entity, newWorld, link);
if ((entity instanceof EntityPlayerMP))
{
@@ -264,7 +263,7 @@ public class dimHelper extends DimensionManager
entity.worldObj.updateEntityWithOptionalForce(entity, false);
mod_pocketDim.teleporter.placeInPortal(entity, newWorld, link);
if ((entity != null) && (cart != null))
@@ -284,10 +283,14 @@ public class dimHelper extends DimensionManager
{
WorldServer.class.cast(newWorld).theChunkProviderServer.loadChunk(MathHelper.floor_double(entity.posX) >> 4, MathHelper.floor_double(entity.posZ) >> 4);
}
mod_pocketDim.teleporter.placeInPortal(entity, newWorld, link);
return entity;
}
/**
* Primary function used to teleport the player using doors. Performes numerous null checks, and also generates the destination door/pocket if it has not done so already.
@@ -306,6 +309,8 @@ public class dimHelper extends DimensionManager
if(linkData!=null)
{
int destinationID=linkData.destDimID;
int x=linkData.destXCoord;
@@ -334,15 +339,27 @@ public class dimHelper extends DimensionManager
entity = this.teleportEntity(world, entity, linkData);
this.teleportEntity(world, entity, linkData);
if(entity instanceof EntityPlayerMP&&world.provider.dimensionId!=linkData.destDimID)
if(entity instanceof EntityPlayerMP)
{
if(entity.ridingEntity!=null)
{
EntityPlayerMP.class.cast(entity).playerNetServerHandler.sendPacketToPlayer(PacketHandler.sendUpdateRiderPacket(entity.ridingEntity.entityId));
}
if(world.provider.dimensionId!=linkData.destDimID)
{
GameRegistry.onPlayerChangedDimension((EntityPlayer)entity);
}
System.out.println(entity.worldObj.getWorldInfo().getDimension());
System.out.println(entity.worldObj.provider.dimensionId);
}
entity.worldObj.playSoundEffect(entity.posX, entity.posY, entity.posZ, "mob.endermen.portal", 1.0F, 1.0F);
@@ -403,6 +420,7 @@ public class dimHelper extends DimensionManager
}
}
return;
}