Exemplo n.º 1
0
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            HangingWiresMod mod = api.ModLoader.GetModSystem <HangingWiresMod>();

            if (mod == null)
            {
                api.Logger.Error("HangingWiresMod mod system not found");
            }
            else
            {
                NodePos pos = GetNodePosForWire(world, blockSel, mod.GetPendingNode());
                if (CanAttachWire(world, pos, mod.GetPendingNode()))
                {
                    if (pos != null)
                    {
                        mod.SetPendingNode(GetNodePosForWire(world, blockSel));
                    }
                    return(true);
                }
            }



            return(base.OnBlockInteractStart(world, byPlayer, blockSel));
        }
Exemplo n.º 2
0
        public override void OnBlockRemoved(IWorldAccessor world, BlockPos pos)
        {
            base.OnBlockRemoved(world, pos);
            HangingWiresMod mod = api.ModLoader.GetModSystem <HangingWiresMod>();

            mod.RemoveAllNodesAtBlockPos(pos);
        }
Exemplo n.º 3
0
        public override void Initialize(ICoreAPI api, JsonObject properties)
        {
            base.Initialize(api, properties);
            api.Logger.Debug("Initializing device at {0}", this.Blockentity.Pos);
            wireMod   = api.ModLoader.GetModSystem <HangingWiresMod>();
            signalMod = api.ModLoader.GetModSystem <SignalNetworkMod>();

            Pos = this.Blockentity?.Pos;
            //TODO, test if nodes have already been initialized via TreeAttributes
            JsonObject[] nodesTree = properties["signalNodes"]?.AsArray();
            if (nodesTree != null)
            {
                //TODO check duplicated index
                foreach (JsonObject json in nodesTree)
                {
                    int      index    = json["index"].AsInt();
                    bool     isSource = json.KeyExists("isSource") ? json["isSource"].AsBool(): false;
                    BaseNode newNode  = new BaseNode();
                    newNode.output = isSource ? (byte)15 : (byte)0;
                    newNode.Pos    = new NodePos(this.Blockentity.Pos, index);

                    newNode.Connections.AddRange(wireMod.GetWireConnectionsFrom(newNode.Pos));
                    //TODO add internal connections
                    nodes.Add(newNode);
                }
            }
            signalMod.OnDeviceInitialized(this);
        }
Exemplo n.º 4
0
        public override void Start(ICoreAPI api)
        {
            base.Start(api);
            this.Api     = api;
            this.wireMod = api.ModLoader.GetModSystem <HangingWiresMod>();

            if (api.World is IClientWorldAccessor)
            {
                //(api as ICoreClientAPI).Event.RegisterRenderer(this, EnumRenderStage.Before, "signalnetworktick");
                clientNetworkChannel =
                    ((ICoreClientAPI)api).Network.RegisterChannel("signalnetwork");
                //.RegisterMessageType(typeof(MechNetworkPacket))
                //.RegisterMessageType(typeof(NetworkRemovedPacket))
                //.RegisterMessageType(typeof(MechClientRequestPacket))
                //.SetMessageHandler<MechNetworkPacket>(OnPacket)
                //.SetMessageHandler<NetworkRemovedPacket>(OnNetworkRemovePacket);
            }
            else
            {
                api.World.RegisterGameTickListener(OnServerGameTick, 20);
                serverNetworkChannel =
                    ((ICoreServerAPI)api).Network.RegisterChannel("signalnetwork");
                //.RegisterMessageType(typeof(MechNetworkPacket))
                //.RegisterMessageType(typeof(NetworkRemovedPacket))
                //.RegisterMessageType(typeof(MechClientRequestPacket))
                //.SetMessageHandler<MechClientRequestPacket>(OnClientRequestPacket);
            }
        }
Exemplo n.º 5
0
        //Detects when the player interacts with right click, usually to place a component
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            HangingWiresMod mod = api.ModLoader.GetModSystem <HangingWiresMod>();

            if (mod != null && api.Side == EnumAppSide.Client)
            {
                NodePos pos = GetNodePosForWire(world, blockSel);
                if (pos != null)
                {
                    mod.SetPendingNode(GetNodePosForWire(world, blockSel));
                }
            }

            base.OnBlockInteractStart(world, byPlayer, blockSel);
            if (api.Side == EnumAppSide.Client)
            {
                BlockEntity entity = world.BlockAccessor.GetBlockEntity(blockSel.Position);
                entity?.GetBehavior <BEBehaviorCircuitHolder>()?.OnUseOver(byPlayer, blockSel, false);
            }

            return(true);
        }