public override void Initialize(JsonObject properties) { string[] sidenames = properties["sides"].AsArray <string>(new string[0]); sides = new BlockFacing[sidenames.Length]; for (int i = 0; i < sidenames.Length; i++) { if (sidenames[i] == null) { continue; } sides[i] = BlockFacing.FromFirstLetter(sidenames[i][0]); } sidedVariants = properties["sidedVariants"].AsBool(); nwOrientable = properties["nwOrientable"].AsBool(); if (properties["drawIfCulled"].AsBool(false)) { block.decorBehaviorFlags |= DecorFlags.DrawIfCulled; } if (properties["alternateZOffset"].AsBool(false)) { block.decorBehaviorFlags |= DecorFlags.AlternateZOffset; } if (properties["notFullFace"].AsBool(false)) { block.decorBehaviorFlags |= DecorFlags.NotFullFace; } if (properties["removable"].AsBool(false)) { block.decorBehaviorFlags |= DecorFlags.Removable; } block.DecorThickness = properties["thickness"].AsFloat(0.03125f); base.Initialize(properties); }
private void SelectSimilarBlocksAround(BlockLogSection[] around, string rotation) { int f1 = BlockFacing.FromFirstLetter(rotation[0]).Index; int f2 = BlockFacing.FromFirstLetter(rotation[1]).Index; for (int i = 0; i < 6; i++) { BlockLogSection neib = around[i]; if (neib == null) { continue; } if (neib.LastCodePart() != rotation) { around[i] = null; continue; } if (i != f1 && i != f2) { if (!neib.IsBarkFace(i)) { around[i] = null; } } } }
public override void DidConnectAt(IWorldAccessor world, BlockPos pos, BlockFacing face) { if (IsDeadEnd()) { BlockFacing nowFace = BlockFacing.FromFirstLetter(LastCodePart()[0]); if (nowFace.IsAdjacent(face)) { AssetLocation loc = new AssetLocation(FirstCodePart() + "-" + LastCodePart() + face.Code[0]); Block toPlaceBlock = world.GetBlock(loc); if (toPlaceBlock == null) { loc = new AssetLocation(FirstCodePart() + "-" + face.Code[0] + LastCodePart()); toPlaceBlock = world.GetBlock(loc); } MechanicalNetwork nw = GetNetwork(world, pos); world.BlockAccessor.SetBlock(toPlaceBlock.BlockId, pos); BEMPBase be = (world.BlockAccessor.GetBlockEntity(pos) as BEMPBase); be.JoinNetwork(nw); } } }
public override void OnLoaded(ICoreAPI api) { base.OnLoaded(api); this.Orientation = BlockFacing.FromFirstLetter(Variant["type"].Substring(0, 1)); this.Frame = Variant["wood"] is string w?string.Intern(w) : null; this.GlassType = Variant["glass"] is string g?string.Intern(g) : null; }
public override void OnNeighbourBlockChange(IWorldAccessor world, BlockPos pos, BlockPos neibpos) { string orients = Orientation; if (orients.Length == 2 && orients[0] == orients[1]) { orients = "" + orients[0]; } BlockFacing[] facings; facings = orients.Length == 1 ? new BlockFacing[] { BlockFacing.FromFirstLetter(orients[0]) } : new BlockFacing[] { BlockFacing.FromFirstLetter(orients[0]), BlockFacing.FromFirstLetter(orients[1]) }; List <BlockFacing> lostFacings = new List <BlockFacing>(); foreach (BlockFacing facing in facings) { BlockPos npos = pos.AddCopy(facing); IMechanicalPowerBlock nblock = world.BlockAccessor.GetBlock(npos) as IMechanicalPowerBlock; if (nblock == null || !nblock.HasMechPowerConnectorAt(world, npos, facing.Opposite) || world.BlockAccessor.GetBlockEntity(pos)?.GetBehavior <BEBehaviorMPBase>()?.disconnected == true) { lostFacings.Add(facing); } } if (lostFacings.Count == orients.Length) { world.BlockAccessor.BreakBlock(pos, null); return; } if (lostFacings.Count > 0) { MechanicalNetwork nw = GetNetwork(world, pos); orients = orients.Replace("" + lostFacings[0].Code[0], ""); Block toPlaceBlock = world.GetBlock(new AssetLocation(FirstCodePart() + "-" + orients)); (toPlaceBlock as BlockMPBase).ExchangeBlockAt(world, pos); BlockEntity be = world.BlockAccessor.GetBlockEntity(pos); BEBehaviorMPBase bemp = be.GetBehavior <BEBehaviorMPBase>(); bemp.LeaveNetwork(); //check for connect to adjacent valid facings, similar to TryPlaceBlock BlockFacing firstFace = BlockFacing.FromFirstLetter(orients[0]); BlockPos firstPos = pos.AddCopy(firstFace); BlockEntity beNeib = world.BlockAccessor.GetBlockEntity(firstPos); IMechanicalPowerBlock neighbour = beNeib?.Block as IMechanicalPowerBlock; BEBehaviorMPAxle bempaxle = beNeib?.GetBehavior <BEBehaviorMPAxle>(); if (bempaxle != null && !BEBehaviorMPAxle.IsAttachedToBlock(world.BlockAccessor, neighbour as Block, firstPos)) { return; } neighbour?.DidConnectAt(world, firstPos, firstFace.Opposite); WasPlaced(world, pos, firstFace); } }
private bool TryAttachPlaceToHoriontal(IWorldAccessor world, IPlayer byPlayer, BlockPos position, BlockFacing toFacing, BlockFacing targetFacing) { BlockPos neibPos = position.AddCopy(toFacing); Block neibBlock = world.BlockAccessor.GetBlock(neibPos); if (!(neibBlock is BlockRails)) { return(false); } BlockFacing fromFacing = toFacing.Opposite; BlockFacing[] neibDirFacings = getFacingsFromType(neibBlock.Variant["type"]); // Already attached, do default placement behavior if (world.BlockAccessor.GetBlock(neibPos.AddCopy(neibDirFacings[0])) is BlockRails && world.BlockAccessor.GetBlock(neibPos.AddCopy(neibDirFacings[1])) is BlockRails) { return(false); } BlockFacing neibFreeFace = getOpenedEndedFace(neibDirFacings, world, position.AddCopy(toFacing)); // Already fully attached, don't bend rail if (neibFreeFace == null) { return(false); } Block blockToPlace = getRailBlock(world, "curved_", toFacing, targetFacing); if (blockToPlace != null) { if (!placeIfSuitable(world, byPlayer, blockToPlace, position)) { return(false); } return(true); } string dirs = neibBlock.Variant["type"].Split('_')[1]; BlockFacing neibKeepFace = (dirs[0] == neibFreeFace.Code[0]) ? BlockFacing.FromFirstLetter(dirs[1]) : BlockFacing.FromFirstLetter(dirs[0]); Block block = getRailBlock(world, "curved_", neibKeepFace, fromFacing); if (block == null) { return(false); } block.DoPlaceBlock(world, byPlayer, new BlockSelection() { Position = position.AddCopy(toFacing), Face = BlockFacing.UP }, null); return(false); }
public override void OnLoaded(ICoreAPI api) { base.OnLoaded(api); this.Orientation = BlockFacing.FromFirstLetter(Variant["facing"][0]); this.random = new Random(); if (api is ICoreClientAPI capi) { this.weatherSystem = capi.ModLoader.GetModSystem <WeatherSystemClient>(); } }
public override void DidConnectAt(IWorldAccessor world, BlockPos pos, BlockFacing face) { if (IsDeadEnd()) { BlockFacing nowFace = BlockFacing.FromFirstLetter(Orientation[0]); if (nowFace.IsAdjacent(face)) { Block toPlaceBlock = getGearBlock(world, false, Facings[0], face); (toPlaceBlock as BlockMPBase).ExchangeBlockAt(world, pos); } } }
public override bool HasMechPowerConnectorAt(IWorldAccessor world, BlockPos pos, BlockFacing face) { if (IsDeadEnd()) { BlockFacing nowFace = BlockFacing.FromFirstLetter(Orientation[0]); if (nowFace.IsAdjacent(face)) { return(true); } } return(IsOrientedTo(face)); }
public override AssetLocation GetRotatedBlockCode(int angle) { BlockFacing nowFacing = BlockFacing.FromFirstLetter(LastCodePart(2)); BlockFacing rotatedFacing = BlockFacing.HORIZONTALS_ANGLEORDER[(nowFacing.HorizontalAngleIndex + angle / 90) % 4]; string part = LastCodePart(2); if (nowFacing.Axis != rotatedFacing.Axis) { part = (part == "n" ? "w" : "n"); } return(CodeWithParts(part, IsOpened() ? "opened" : "closed", GetKnobOrientation())); }
public override AssetLocation GetRotatedBlockCode(int angle) { BlockFacing nowFacing = BlockFacing.FromFirstLetter(Variant["type"]); BlockFacing rotatedFacing = BlockFacing.HORIZONTALS_ANGLEORDER[(nowFacing.HorizontalAngleIndex + angle / 90) % 4]; string type = Variant["type"]; if (nowFacing.Axis != rotatedFacing.Axis) { type = (type == "n" ? "w" : "n"); } return(CodeWithVariant("type", type)); }
public override void DidConnectAt(IWorldAccessor world, BlockPos pos, BlockFacing face) { if (IsDeadEnd()) { BlockFacing nowFace = BlockFacing.FromFirstLetter(Orientation[0]); if (nowFace.IsAdjacent(face)) { Block toPlaceBlock = getGearBlock(world, false, Facings[0], face); MechanicalNetwork nw = GetNetwork(world, pos); (toPlaceBlock as BlockMPBase).ExchangeBlockAt(world, pos); BEBehaviorMPBase bemp = world.BlockAccessor.GetBlockEntity(pos)?.GetBehavior <BEBehaviorMPBase>(); } } }
public override void OnLoaded(ICoreAPI api) { base.OnLoaded(api); string rotation = Variant["rotation"] is string r?string.Intern(r) : null; string segment = Variant["segment"] is string t?string.Intern(t) : null; if (segment != null && segment.Length == 2) { if (rotation == "ud") { barkFace1 = BlockFacing.FromFirstLetter(segment[0])?.Index ?? 0; barkFace2 = BlockFacing.FromFirstLetter(segment[1])?.Index ?? 1; alternatingVOffset = true; alternatingVOffsetFaces = 0x30; } else if (rotation == "we") { switch (segment) { case "ne": barkFace1 = 4; barkFace2 = 0; break; case "se": barkFace1 = 5; barkFace2 = 0; break; case "nw": barkFace1 = 4; barkFace2 = 2; break; case "sw": barkFace1 = 5; barkFace2 = 2; break; } alternatingVOffset = true; alternatingVOffsetFaces = 0x0A; } else if (rotation == "ns") { switch (segment) { case "ne": barkFace1 = 4; barkFace2 = 1; break; case "se": barkFace1 = 5; barkFace2 = 1; break; case "nw": barkFace1 = 4; barkFace2 = 3; break; case "sw": barkFace1 = 5; barkFace2 = 3; break; } alternatingVOffset = true; alternatingVOffsetFaces = 0x05; } } }
public override void OnLoaded(ICoreAPI api) { base.OnLoaded(api); string facingletters = Variant["coating"]; ownFacings = new BlockFacing[facingletters.Length]; selectionBoxes = new Cuboidf[ownFacings.Length]; for (int i = 0; i < facingletters.Length; i++) { ownFacings[i] = BlockFacing.FromFirstLetter(facingletters[i]); switch (facingletters[i]) { case 'n': selectionBoxes[i] = new Cuboidf(0, 0, 0, 1, 1, 0.0625f); break; case 'e': selectionBoxes[i] = new Cuboidf(0, 0, 0, 1, 1, 0.0625f).RotatedCopy(0, 270, 0, new Vec3d(0.5, 0.5, 0.5)); break; case 's': selectionBoxes[i] = new Cuboidf(0, 0, 0, 1, 1, 0.0625f).RotatedCopy(0, 180, 0, new Vec3d(0.5, 0.5, 0.5)); break; case 'w': selectionBoxes[i] = new Cuboidf(0, 0, 0, 1, 1, 0.0625f).RotatedCopy(0, 90, 0, new Vec3d(0.5, 0.5, 0.5)); break; case 'u': selectionBoxes[i] = new Cuboidf(0, 0, 0, 1, 0.0625f, 1).RotatedCopy(180, 0, 0, new Vec3d(0.5, 0.5, 0.5)); break; case 'd': selectionBoxes[i] = new Cuboidf(0, 0, 0, 1, 0.0625f, 1); break; } } }
public override void OnNeighourBlockChange(IWorldAccessor world, BlockPos pos, BlockPos neibpos) { string orients = LastCodePart(); BlockFacing[] facings; facings = orients.Length == 1 ? new BlockFacing[] { BlockFacing.FromFirstLetter(orients[0]) } : new BlockFacing[] { BlockFacing.FromFirstLetter(orients[0]), BlockFacing.FromFirstLetter(orients[1]) }; List <BlockFacing> lostFacings = new List <BlockFacing>(); foreach (BlockFacing facing in facings) { BlockPos npos = pos.AddCopy(facing); IMechanicalPowerBlock nblock = world.BlockAccessor.GetBlock(npos) as IMechanicalPowerBlock; if (nblock == null || !nblock.HasConnectorAt(world, npos, facing.GetOpposite())) { lostFacings.Add(facing); } } if (lostFacings.Count == orients.Length) { world.BlockAccessor.BreakBlock(pos, null); return; } if (lostFacings.Count > 0) { MechanicalNetwork nw = GetNetwork(world, pos); orients = orients.Replace("" + lostFacings[0].Code[0], ""); Block toPlaceBlock = world.GetBlock(new AssetLocation(FirstCodePart() + "-" + orients)); world.BlockAccessor.SetBlock(toPlaceBlock.BlockId, pos); BEMPBase be = (world.BlockAccessor.GetBlockEntity(pos) as BEMPBase); be.JoinNetwork(nw); } }
public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel, ref string failureCode) { BlockLogSection[] around = new BlockLogSection[6]; string rotation = GetBlocksAround(around, world.BlockAccessor, blockSel.Position.Copy()); if (rotation == null || byPlayer?.Entity.Controls.Sneak == true) { switch (blockSel.Face.Axis) { case EnumAxis.X: rotation = "we"; break; case EnumAxis.Y: rotation = "ud"; break; case EnumAxis.Z: rotation = "ns"; break; } } SelectSimilarBlocksAround(around, rotation); int normal0 = 0; int normal1 = 1; int normal2 = 2; int normal3 = 3; int normal4 = 4; int normal5 = 5; if (rotation == "we") { normal0 = 4; normal1 = 0; normal2 = 5; normal3 = 2; normal4 = 3; normal5 = 1; } else if (rotation == "ns") { normal0 = 4; normal1 = 1; normal2 = 5; normal3 = 3; normal4 = 0; normal5 = 2; } string seg = null; if (around[normal0] != null && around[normal2] == null) { seg = "s" + BlockFacing.FromFirstLetter(around[normal0].LastCodePart(1)[1]).Code.ToLower()[0]; } if (around[normal2] != null && around[normal0] == null) { seg = "n" + BlockFacing.FromFirstLetter(around[normal2].LastCodePart(1)[1]).Code.ToLower()[0]; } if (around[normal1] != null && around[normal3] == null) { seg = BlockFacing.FromFirstLetter(around[normal1].LastCodePart(1)[0]).Code.ToLower()[0] + "w"; } if (around[normal3] != null && around[normal1] == null) { seg = BlockFacing.FromFirstLetter(around[normal3].LastCodePart(1)[0]).Code.ToLower()[0] + "e"; } if (seg == null) { seg = around[normal5]?.LastCodePart(1) ?? around[normal4]?.LastCodePart(1) ?? "ne"; } Block orientedBlock = world.BlockAccessor.GetBlock(CodeWithParts(seg, rotation)); if (orientedBlock == null) { orientedBlock = world.BlockAccessor.GetBlock(CodeWithParts(rotation)); } if (orientedBlock.CanPlaceBlock(world, byPlayer, blockSel, ref failureCode)) { orientedBlock.DoPlaceBlock(world, byPlayer, blockSel, itemstack); return(true); } return(false); }
public override BlockFacing GetDirection() { return(BlockFacing.FromFirstLetter(Variant["type"])); }
public override void OnLoaded(ICoreAPI api) { base.OnLoaded(api); this.orientation = BlockFacing.FromFirstLetter(Variant["side"][0]); InvertPoundersOnRender = orientation == BlockFacing.WEST || orientation == BlockFacing.SOUTH; }
public override BlockFacing GetDirection() { string[] parts = Code.Path.Split('-'); return(BlockFacing.FromFirstLetter(parts[2])); }
public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel, ref string failureCode) { List <BlockPos> smallGears = new List <BlockPos>(); if (!CanPlaceBlock(world, byPlayer, blockSel, ref failureCode, smallGears)) { return(false); } bool ok = base.DoPlaceBlock(world, byPlayer, blockSel, itemstack); if (ok) { int dx, dz; BlockEntity beOwn = world.BlockAccessor.GetBlockEntity(blockSel.Position); List <BlockFacing> connections = new List <BlockFacing>(); foreach (var smallGear in smallGears) { dx = smallGear.X - blockSel.Position.X; dz = smallGear.Z - blockSel.Position.Z; char orient = 'n'; if (dx == 1) { orient = 'e'; } else if (dx == -1) { orient = 'w'; } else if (dz == 1) { orient = 's'; } BlockMPBase toPlaceBlock = world.GetBlock(new AssetLocation("angledgears-" + orient + orient)) as BlockMPBase; BlockFacing bf = BlockFacing.FromFirstLetter(orient); toPlaceBlock.ExchangeBlockAt(world, smallGear); toPlaceBlock.DidConnectAt(world, smallGear, bf.Opposite); connections.Add(bf); //IGearAcceptor beg = beOwn as IGearAcceptor; //if (beg == null) world.Logger.Error("large gear wrong block entity type - not a gear acceptor"); //beg?.AddGear(smallGear); } PlaceFakeBlocks(world, blockSel.Position, smallGears); BEBehaviorMPBase beMechBase = beOwn?.GetBehavior <BEBehaviorMPBase>(); BlockPos pos = blockSel.Position.DownCopy(); if (world.BlockAccessor.GetBlock(pos) is IMechanicalPowerBlock block && block.HasMechPowerConnectorAt(world, pos, BlockFacing.UP)) { block.DidConnectAt(world, pos, BlockFacing.UP); connections.Add(BlockFacing.DOWN); } else { pos = blockSel.Position.UpCopy(); block = world.BlockAccessor.GetBlock(pos) as IMechanicalPowerBlock; if (block != null && block.HasMechPowerConnectorAt(world, pos, BlockFacing.DOWN)) { block.DidConnectAt(world, pos, BlockFacing.DOWN); connections.Add(BlockFacing.UP); } } foreach (BlockFacing face in connections) { beMechBase?.WasPlaced(face); } }
private BlockFacing[] getFacingsFromType(string type) { string codes = type.Split('_')[1]; return(new BlockFacing[] { BlockFacing.FromFirstLetter(codes[0]), BlockFacing.FromFirstLetter(codes[1]) }); }