still more work on getting the addon working client

Still haven't got the pipe addons to work client side. I think it has
something to do with a packet handling issue but i can't tell yet. As
well some method are not getting called right in the sub tiles.
This commit is contained in:
Rseifert 2013-04-02 03:06:30 -04:00
parent 2270d67495
commit da813ace2d
5 changed files with 76 additions and 16 deletions

View file

@ -21,8 +21,6 @@ import fluidmech.common.machines.mech.BlockRod;
import fluidmech.common.machines.mech.TileEntityGenerator;
import fluidmech.common.machines.mech.TileEntityRod;
import fluidmech.common.machines.pipes.BlockPipe;
import fluidmech.common.machines.pipes.BlockPipe;
import fluidmech.common.machines.pipes.TileEntityPipe;
import fluidmech.common.machines.pipes.TileEntityPipe;
import fluidmech.common.machines.pipes.TileEntityPipeWindow;
import hydraulic.api.ColorCode;
@ -41,6 +39,10 @@ import net.minecraftforge.liquids.LiquidDictionary;
import net.minecraftforge.liquids.LiquidStack;
import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.oredict.ShapedOreRecipe;
import org.modstats.ModstatInfo;
import org.modstats.Modstats;
import universalelectricity.prefab.TranslationHelper;
import universalelectricity.prefab.network.PacketManager;
import cpw.mods.fml.common.DummyModContainer;
@ -63,6 +65,7 @@ import cpw.mods.fml.common.registry.GameRegistry;
*
* @author Rseifert
*/
@ModstatInfo(prefix="MyPrefix")
@Mod(modid = FluidMech.NAME, name = FluidMech.NAME, version = FluidMech.VERSION, dependencies = "after:BasicComponents")
@NetworkMod(channels = { FluidMech.CHANNEL }, clientSideRequired = true, serverSideRequired = false, packetHandler = PacketManager.class)
public class FluidMech extends DummyModContainer
@ -124,6 +127,7 @@ public class FluidMech extends DummyModContainer
MinecraftForge.EVENT_BUS.register(new FluidHelper());
instance = this;
Modstats.instance().getReporter().registerMod(this);
CONFIGURATION.load();
// Blocks

View file

@ -1,13 +1,14 @@
package fluidmech.common.machines.pipes;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.ForgeDirection;
import fluidmech.client.render.RenderPipeWindow;
import fluidmech.client.render.pipeextentions.IPipeExtentionRender;
import universalelectricity.prefab.network.IPacketReceiver;
public interface IPipeExtention extends IPacketReceiver
{
public boolean canBePlacedOnPipe(TileEntityPipe pipe);
public boolean canBePlacedOnPipe(TileEntityPipe pipe, int side);
public TileEntityPipe getPipe();
@ -33,5 +34,9 @@ public interface IPipeExtention extends IPacketReceiver
* render class to be used to render this pipe extension of the face of the main pipe
*/
public Class<?> getExtentionRenderClass();
public void setDirection(ForgeDirection dir);
public ForgeDirection getDirection();
}

View file

@ -54,6 +54,8 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
/* NETWORK INSTANCE THAT THIS PIPE USES */
private HydraulicNetwork pipeNetwork;
private boolean shouldAutoDrain = false;
public enum PacketID
{
PIPE_CONNECTIONS, EXTENTION_CREATE, EXTENTION_UPDATE;
@ -100,6 +102,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
*/
private void updateSubEntities()
{
for (int i = 0; i < 6; i++)
{
if (subEntities[i] instanceof IPipeExtention && subEntities[i] instanceof TileEntity)
@ -107,6 +110,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
IPipeExtention extention = subEntities[i];
if (this.ticks % extention.updateTick() == 0)
{
System.out.println("Updating addon " + (worldObj.isRemote ? "Client" : "Server") + " on side " + i);
((TileEntity) extention).updateEntity();
if (extention.shouldSendPacket(!this.worldObj.isRemote) && extention.getExtentionPacketData(!this.worldObj.isRemote) != null)
{
@ -148,7 +152,9 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
}
else if (id == PacketID.EXTENTION_CREATE)
{
System.out.println("Packet for addon");
int side = dataStream.readInt();
this.loadOrCreateSubTile(side, PacketManager.readNBTTagCompound(dataStream));
}
@ -233,6 +239,10 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
{
System.out.println("Creating addon " + (worldObj.isRemote ? "Client" : "Server"));
}
else
{
System.out.println("Creating addon Unkown side");
}
}
}
}
@ -243,10 +253,12 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
{
TileEntity tile = (TileEntity) subEntities[side];
((IPipeExtention) tile).setPipe(this);
((IPipeExtention) tile).setDirection(ForgeDirection.getOrientation(side));
tile.worldObj = this.worldObj;
tile.xCoord = this.xCoord;
tile.yCoord = this.yCoord;
tile.zCoord = this.zCoord;
sendExtentionToClient(side);
}
}
@ -257,7 +269,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
{
NBTTagCompound tag = new NBTTagCompound();
((TileEntity) this.subEntities[side]).writeToNBT(tag);
if (tag != null && tag.getTags().size() != 0)
if (tag != null && tag.hasKey("id"))
{
System.out.println("Sending TileEntity to Client");
Packet packet = PacketManager.getPacket(FluidMech.CHANNEL, this, PacketID.EXTENTION_CREATE.ordinal(), ForgeDirection.getOrientation(side), tag);
@ -501,7 +513,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
@Override
public boolean canConnect(TileEntity entity, ForgeDirection dir)
{
return true;
return this.subEntities[dir.ordinal()] == null;
}
@Override

View file

@ -7,6 +7,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.prefab.network.IPacketReceiver;
import universalelectricity.prefab.tile.TileEntityAdvanced;
@ -20,7 +21,18 @@ import universalelectricity.prefab.tile.TileEntityAdvanced;
public abstract class TileEntityPipeExtention extends TileEntityAdvanced implements IPipeExtention, IPacketReceiver
{
private TileEntityPipe masterPipe = null;
private TileEntityPipe masterPipe = null;
public ForgeDirection direction = ForgeDirection.UNKNOWN;
@Override
public void initiate()
{
if (this.masterPipe != null)
{
System.out.println("Sending TileEntity to Client from extention.class");
masterPipe.sendExtentionToClient(direction.ordinal());
}
}
@Override
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
@ -41,6 +53,19 @@ public abstract class TileEntityPipeExtention extends TileEntityAdvanced impleme
this.masterPipe = pipe;
}
@Override
public void setDirection(ForgeDirection dir)
{
this.direction = dir;
}
@Override
public ForgeDirection getDirection()
{
return this.direction;
}
@Override
public String toString()
{

View file

@ -10,6 +10,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.LiquidStack;
public class TileEntityPipeWindow extends TileEntityPipeExtention
@ -24,11 +25,18 @@ public class TileEntityPipeWindow extends TileEntityPipeExtention
public void updateEntity()
{
super.updateEntity();
System.out.println("Updating side " + (worldObj.isRemote ? "Client" : "Server") );
if(!worldObj.isRemote && pipe != null)
{
stack = pipe.getNetwork().getTank().getLiquid();
worldObj.setBlockAndMetadataWithNotify(xCoord, yCoord+1, yCoord, 0, 0, 3);
if (!worldObj.isRemote)
{
if (pipe != null)
{
stack = pipe.getNetwork().getTank().getLiquid();
worldObj.setBlockAndMetadataWithNotify(xCoord, yCoord + 1, yCoord, 0, 0, 3);
}
}
else
{
System.out.println("Updating side Client");
}
}
@ -36,9 +44,9 @@ public class TileEntityPipeWindow extends TileEntityPipeExtention
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
{
if(pipe != null && worldObj.isRemote)
if (pipe != null && worldObj.isRemote)
{
}
}
@ -55,10 +63,15 @@ public class TileEntityPipeWindow extends TileEntityPipeExtention
// TODO Auto-generated method stub
return null;
}
@Override
public boolean canBePlacedOnPipe(TileEntityPipe pipe)
public boolean canBePlacedOnPipe(TileEntityPipe pipe, int side)
{
return true;
if(pipe != null && pipe.subEntities[side] == null)
{
return true;
}
return false;
}
@Override
@ -77,13 +90,14 @@ public class TileEntityPipeWindow extends TileEntityPipeExtention
public int updateTick()
{
return 20;
}
}
@Override
public Class<RenderPipeWindow> getExtentionRenderClass()
{
return RenderPipeWindow.class;
}
@Override
public String toString()
{