Search in sources :

Example 1 with Node

use of ValkyrienWarfareControl.GraphTheory.Node in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class PhysicsObject method loadClaimedChunks.

public void loadClaimedChunks() {
    ArrayList<TileEntity> nodeTileEntitiesToUpdate = new ArrayList<TileEntity>();
    claimedChunks = new Chunk[(ownedChunks.radius * 2) + 1][(ownedChunks.radius * 2) + 1];
    claimedChunksEntries = new PlayerChunkMapEntry[(ownedChunks.radius * 2) + 1][(ownedChunks.radius * 2) + 1];
    for (int x = ownedChunks.minX; x <= ownedChunks.maxX; x++) {
        for (int z = ownedChunks.minZ; z <= ownedChunks.maxZ; z++) {
            Chunk chunk = worldObj.getChunkFromChunkCoords(x, z);
            if (chunk == null) {
                System.out.println("Just a loaded a null chunk");
                chunk = new Chunk(worldObj, x, z);
            }
            // Do this to get it re-integrated into the world
            if (!worldObj.isRemote) {
                injectChunkIntoWorld(chunk, x, z, false);
            }
            for (Entry<BlockPos, TileEntity> entry : chunk.chunkTileEntityMap.entrySet()) {
                TileEntity tile = entry.getValue();
                if (tile instanceof INodeProvider) {
                    nodeTileEntitiesToUpdate.add(tile);
                }
            }
            claimedChunks[x - ownedChunks.minX][z - ownedChunks.minZ] = chunk;
        }
    }
    VKChunkCache = new VWChunkCache(worldObj, claimedChunks);
    refrenceBlockPos = getRegionCenter();
    coordTransform = new CoordTransformObject(this);
    if (!worldObj.isRemote) {
        createPhysicsCalculations();
    }
    detectBlockPositions();
    for (TileEntity tile : nodeTileEntitiesToUpdate) {
        Node node = ((INodeProvider) tile).getNode();
        if (node != null) {
            node.updateBuildState();
        } else {
            System.err.println("How the fuck did we get a null node?");
        }
    }
    coordTransform.updateAllTransforms();
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) VWChunkCache(ValkyrienWarfareBase.Relocation.VWChunkCache) Node(ValkyrienWarfareControl.GraphTheory.Node) ArrayList(java.util.ArrayList) INodeProvider(ValkyrienWarfareControl.GraphTheory.INodeProvider) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) BlockPos(net.minecraft.util.math.BlockPos) SPacketUnloadChunk(net.minecraft.network.play.server.SPacketUnloadChunk) Chunk(net.minecraft.world.chunk.Chunk)

Example 2 with Node

use of ValkyrienWarfareControl.GraphTheory.Node in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class BasicNodeTileEntity method invalidate.

@Override
public void invalidate() {
    //		System.out.println("Please RNGesus!");
    //The Node just got destroyed
    this.tileEntityInvalid = true;
    Node toInvalidate = getNode();
    toInvalidate.destroyNode();
}
Also used : Node(ValkyrienWarfareControl.GraphTheory.Node)

Example 3 with Node

use of ValkyrienWarfareControl.GraphTheory.Node in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class ItemRelayWire method onItemUse.

@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    IBlockState clickedState = worldIn.getBlockState(pos);
    Block block = clickedState.getBlock();
    TileEntity currentTile = worldIn.getTileEntity(pos);
    if (currentTile instanceof INodeProvider && !worldIn.isRemote) {
        ICapabilityLastRelay inst = stack.getCapability(ValkyrienWarfareControlMod.lastRelayCapability, null);
        if (inst != null) {
            if (!inst.hasLastRelay()) {
                inst.setLastRelay(pos);
            //Draw a wire in the player's hand after this
            } else {
                BlockPos lastPos = inst.getLastRelay();
                double distance = lastPos.distanceSq(pos);
                TileEntity lastPosTile = worldIn.getTileEntity(lastPos);
                if (!lastPos.equals(pos) && lastPosTile != null && currentTile != null) {
                    if (distance < range * range) {
                        Node lastPosNode = ((INodeProvider) lastPosTile).getNode();
                        Node currentPosNode = ((INodeProvider) currentTile).getNode();
                        //Connect the two bastards
                        //							inst.setLastRelay(pos);
                        inst.setLastRelay(null);
                        if (lastPosNode != null && currentPosNode != null) {
                            currentPosNode.linkNode(lastPosNode);
                        }
                        //							System.out.println("Success");
                        stack.damageItem(1, playerIn);
                    } else {
                        playerIn.addChatComponentMessage(new TextComponentString("Nodes are too far away, try better wire"));
                        inst.setLastRelay(null);
                    }
                } else {
                    inst.setLastRelay(pos);
                }
            }
        }
    }
    return EnumActionResult.FAIL;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) Node(ValkyrienWarfareControl.GraphTheory.Node) Block(net.minecraft.block.Block) INodeProvider(ValkyrienWarfareControl.GraphTheory.INodeProvider) ICapabilityLastRelay(ValkyrienWarfareControl.Capability.ICapabilityLastRelay) BlockPos(net.minecraft.util.math.BlockPos) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

Node (ValkyrienWarfareControl.GraphTheory.Node)3 INodeProvider (ValkyrienWarfareControl.GraphTheory.INodeProvider)2 TileEntity (net.minecraft.tileentity.TileEntity)2 BlockPos (net.minecraft.util.math.BlockPos)2 VWChunkCache (ValkyrienWarfareBase.Relocation.VWChunkCache)1 ICapabilityLastRelay (ValkyrienWarfareControl.Capability.ICapabilityLastRelay)1 ArrayList (java.util.ArrayList)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 SPacketUnloadChunk (net.minecraft.network.play.server.SPacketUnloadChunk)1 MutableBlockPos (net.minecraft.util.math.BlockPos.MutableBlockPos)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 Chunk (net.minecraft.world.chunk.Chunk)1