Jump to content

shouldConnectTo tileentity


FatalEU

Recommended Posts

So I have a a class called Pipes that I have;


import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import com.fataleu.mod.helpers.ModEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;

public class TileEntityPipe extends ModEntity {

public Map<ForgeDirection, TileEntity> getConnectedSides() {
	Map<ForgeDirection, TileEntity> connect = new HashMap<ForgeDirection, TileEntity>();

	connect.put(ForgeDirection.WEST,
			getBlockTileEntity(xCoord + 1, yCoord, zCoord));
	connect.put(ForgeDirection.EAST,
			getBlockTileEntity(xCoord - 1, yCoord, zCoord));

	connect.put(ForgeDirection.UP,
			getBlockTileEntity(xCoord, yCoord + 1, zCoord));
	connect.put(ForgeDirection.DOWN,
			getBlockTileEntity(xCoord, yCoord - 1, zCoord));

	connect.put(ForgeDirection.NORTH,
			getBlockTileEntity(xCoord, yCoord, zCoord + 1));
	connect.put(ForgeDirection.SOUTH,
			getBlockTileEntity(xCoord, yCoord, zCoord - 1));

	Map<ForgeDirection, TileEntity> _Map = new HashMap<ForgeDirection, TileEntity>();

	for (Map.Entry<ForgeDirection, TileEntity> entry : connect.entrySet()) {
		if (shouldConnectTo(entry.getValue())) {
			_Map .put(entry.getKey(), entry.getValue());
		}
	}

	return _Map ;
}

private boolean shouldConnectTo(TileEntity entity) {
	if(entity instanceof ModEntity){ 
		return true;
	}
	return false;
}

}

 

This works good if you only want to connect to any side of a given entity but I want to have it so that you can only connect to certain sides depending on the entity. For instance a containerEntity would only connect at the top side but a pipe would bee all sides. Does anyone have any suggestions on how to go about this

Link to comment
Share on other sites

Never mind everyone I did it;

width=800 height=449020vSdM.png?1 [/img]

 

I added this into the ModEntity class;

public ArrayList<ForgeDirection> directions = new ArrayList();

 

and in each of my tileentity classes I added directions

public TileEntityContainer() {
	directions.add(ForgeDirection.DOWN);
}

 

then for the pipes I changed the shouldConnectTo function to take both the entity and the direction

private boolean shouldConnectTo(TileEntity entity, ForgeDirection forgeDirection) {
	if(entity instanceof ModEntity && ((ModEntity) entity).directions.contains(forgeDirection)){
		return true;
	}
	return false;
}

 

Link to comment
Share on other sites

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.