Search in sources :

Example 1 with IRoutingNode

use of WayofTime.bloodmagic.routing.IRoutingNode in project BloodMagic by WayofTime.

the class ItemNodeRouter method onItemUseFirst.

@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
    ItemStack stack = player.getHeldItem(hand);
    if (world.isRemote) {
        return EnumActionResult.PASS;
    }
    TileEntity tileHit = world.getTileEntity(pos);
    if (!(tileHit instanceof IRoutingNode)) {
        // TODO: Remove contained position?
        BlockPos containedPos = getBlockPos(stack);
        if (!containedPos.equals(BlockPos.ORIGIN)) {
            this.setBlockPos(stack, BlockPos.ORIGIN);
            player.sendStatusMessage(new TextComponentTranslation("chat.bloodmagic.routing.remove"), true);
            return EnumActionResult.FAIL;
        }
        return EnumActionResult.FAIL;
    }
    IRoutingNode node = (IRoutingNode) tileHit;
    BlockPos containedPos = getBlockPos(stack);
    if (containedPos.equals(BlockPos.ORIGIN)) {
        this.setBlockPos(stack, pos);
        player.sendStatusMessage(new TextComponentTranslation("chat.bloodmagic.routing.set"), true);
        return EnumActionResult.SUCCESS;
    } else {
        TileEntity pastTile = world.getTileEntity(containedPos);
        if (pastTile instanceof IRoutingNode) {
            IRoutingNode pastNode = (IRoutingNode) pastTile;
            if (pastNode instanceof IMasterRoutingNode) {
                IMasterRoutingNode master = (IMasterRoutingNode) pastNode;
                if (!node.isMaster(master)) {
                    if (// If the node is not the master and it is receptive
                    node.getMasterPos().equals(BlockPos.ORIGIN)) {
                        node.connectMasterToRemainingNode(world, new LinkedList<>(), master);
                        master.addConnection(pos, containedPos);
                        master.addNodeToList(node);
                        node.addConnection(containedPos);
                        player.sendStatusMessage(new TextComponentTranslation("chat.bloodmagic.routing.link.master"), true);
                        this.setBlockPos(stack, BlockPos.ORIGIN);
                        return EnumActionResult.SUCCESS;
                    }
                } else {
                    master.addConnection(pos, containedPos);
                    node.addConnection(containedPos);
                    player.sendStatusMessage(new TextComponentTranslation("chat.bloodmagic.routing.link.master"), true);
                    this.setBlockPos(stack, BlockPos.ORIGIN);
                    return EnumActionResult.SUCCESS;
                }
            } else if (node instanceof IMasterRoutingNode) {
                IMasterRoutingNode master = (IMasterRoutingNode) node;
                if (!pastNode.isMaster(master)) {
                    if (// TODO: This is where the issue is
                    pastNode.getMasterPos().equals(BlockPos.ORIGIN)) {
                        pastNode.connectMasterToRemainingNode(world, new LinkedList<>(), master);
                        master.addConnection(pos, containedPos);
                        pastNode.addConnection(pos);
                        master.addNodeToList(pastNode);
                        player.sendStatusMessage(new TextComponentTranslation("chat.bloodmagic.routing.link.master"), true);
                        this.setBlockPos(stack, BlockPos.ORIGIN);
                        return EnumActionResult.SUCCESS;
                    }
                } else {
                    master.addConnection(pos, containedPos);
                    pastNode.addConnection(pos);
                    player.sendStatusMessage(new TextComponentTranslation("chat.bloodmagic.routing.link.master"), true);
                    this.setBlockPos(stack, BlockPos.ORIGIN);
                    return EnumActionResult.SUCCESS;
                }
            } else {
                // Both nodes are not master nodes, so normal linking
                if (pastNode.getMasterPos().equals(node.getMasterPos())) {
                    if (!pastNode.getMasterPos().equals(BlockPos.ORIGIN)) {
                        TileEntity testTile = world.getTileEntity(pastNode.getMasterPos());
                        if (testTile instanceof IMasterRoutingNode) {
                            IMasterRoutingNode master = (IMasterRoutingNode) testTile;
                            master.addConnection(pos, containedPos);
                        }
                    }
                    pastNode.addConnection(pos);
                    node.addConnection(containedPos);
                    player.sendStatusMessage(new TextComponentTranslation("chat.bloodmagic.routing.link.master"), true);
                    this.setBlockPos(stack, BlockPos.ORIGIN);
                    return EnumActionResult.SUCCESS;
                } else if (// pastNode is not connected to a master, but node is
                pastNode.getMasterPos().equals(BlockPos.ORIGIN)) {
                    TileEntity tile = world.getTileEntity(node.getMasterPos());
                    if (tile instanceof IMasterRoutingNode) {
                        IMasterRoutingNode master = (IMasterRoutingNode) tile;
                        master.addConnection(pos, containedPos);
                        master.addNodeToList(pastNode);
                        pastNode.connectMasterToRemainingNode(world, new LinkedList<>(), master);
                    }
                    pastNode.addConnection(pos);
                    node.addConnection(containedPos);
                    player.sendStatusMessage(new TextComponentTranslation("chat.bloodmagic.routing.link"), true);
                    this.setBlockPos(stack, BlockPos.ORIGIN);
                    return EnumActionResult.SUCCESS;
                } else if (// node is not connected to a master, but pastNode is
                node.getMasterPos().equals(BlockPos.ORIGIN)) {
                    TileEntity tile = world.getTileEntity(pastNode.getMasterPos());
                    if (tile instanceof IMasterRoutingNode) {
                        IMasterRoutingNode master = (IMasterRoutingNode) tile;
                        master.addConnection(pos, containedPos);
                        master.addNodeToList(node);
                        node.connectMasterToRemainingNode(world, new LinkedList<>(), master);
                    }
                    pastNode.addConnection(pos);
                    node.addConnection(containedPos);
                    player.sendStatusMessage(new TextComponentTranslation("chat.bloodmagic.routing.link"), true);
                    this.setBlockPos(stack, BlockPos.ORIGIN);
                    return EnumActionResult.SUCCESS;
                } else {
                    this.setBlockPos(stack, BlockPos.ORIGIN);
                    return EnumActionResult.SUCCESS;
                }
            }
        }
    }
    return EnumActionResult.FAIL;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) IMasterRoutingNode(WayofTime.bloodmagic.routing.IMasterRoutingNode) BlockPos(net.minecraft.util.math.BlockPos) IRoutingNode(WayofTime.bloodmagic.routing.IRoutingNode) ItemStack(net.minecraft.item.ItemStack) LinkedList(java.util.LinkedList)

Example 2 with IRoutingNode

use of WayofTime.bloodmagic.routing.IRoutingNode in project BloodMagic by WayofTime.

the class TileRoutingNode method removeAllConnections.

@Override
public void removeAllConnections() {
    TileEntity testTile = getWorld().getTileEntity(getMasterPos());
    if (testTile instanceof IMasterRoutingNode) {
        // Remove this node from the master
        ((IMasterRoutingNode) testTile).removeConnection(pos);
    }
    for (BlockPos testPos : connectionList) {
        TileEntity tile = getWorld().getTileEntity(testPos);
        if (tile instanceof IRoutingNode) {
            ((IRoutingNode) tile).removeConnection(pos);
            getWorld().notifyBlockUpdate(getPos(), getWorld().getBlockState(testPos), getWorld().getBlockState(testPos), 3);
        }
    }
    connectionList.clear();
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IMasterRoutingNode(WayofTime.bloodmagic.routing.IMasterRoutingNode) BlockPos(net.minecraft.util.math.BlockPos) IRoutingNode(WayofTime.bloodmagic.routing.IRoutingNode)

Example 3 with IRoutingNode

use of WayofTime.bloodmagic.routing.IRoutingNode in project BloodMagic by WayofTime.

the class TileRoutingNode method connectMasterToRemainingNode.

@Override
public void connectMasterToRemainingNode(World world, List<BlockPos> alreadyChecked, IMasterRoutingNode master) {
    this.masterPos = master.getBlockPos();
    List<BlockPos> connectedList = this.getConnected();
    for (BlockPos testPos : connectedList) {
        if (alreadyChecked.contains(testPos)) {
            continue;
        }
        alreadyChecked.add(testPos);
        TileEntity tile = world.getTileEntity(testPos);
        if (!(tile instanceof IRoutingNode)) {
            continue;
        }
        IRoutingNode node = (IRoutingNode) tile;
        if (// If getMasterPos() returns the origin, the node is not connected to any master.
        node.getMasterPos().equals(BlockPos.ORIGIN)) {
            master.addNodeToList(node);
            node.connectMasterToRemainingNode(world, alreadyChecked, master);
        }
    }
    master.addConnections(this.getBlockPos(), connectedList);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.math.BlockPos) IRoutingNode(WayofTime.bloodmagic.routing.IRoutingNode)

Aggregations

IRoutingNode (WayofTime.bloodmagic.routing.IRoutingNode)3 TileEntity (net.minecraft.tileentity.TileEntity)3 BlockPos (net.minecraft.util.math.BlockPos)3 IMasterRoutingNode (WayofTime.bloodmagic.routing.IMasterRoutingNode)2 LinkedList (java.util.LinkedList)1 ItemStack (net.minecraft.item.ItemStack)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1