public override AssetLocation GetHorizontallyFlippedBlockCode(EnumAxis axis) { BlockFacing facing = BlockFacing.FromCode(LastCodePart()); if (facing.Axis == axis) { return(CodeWithParts(facing.GetOpposite().Code)); } return(Code); }
public override AssetLocation GetRotatedBlockCode(int angle, ref EnumHandling handled) { handled = EnumHandling.PreventDefault; BlockFacing beforeFacing = BlockFacing.FromCode(block.LastCodePart()); int rotatedIndex = GameMath.Mod(beforeFacing.HorizontalAngleIndex - angle / 90, 4); BlockFacing nowFacing = BlockFacing.HORIZONTALS_ANGLEORDER[rotatedIndex]; return(block.CodeWithParts(nowFacing.Code)); }
public static IMountable GetMountable(IWorldAccessor world, TreeAttribute tree) { BlockPos pos = new BlockPos(tree.GetInt("posx"), tree.GetInt("posy"), tree.GetInt("posz")); Block block = world.BlockAccessor.GetBlock(pos); BlockFacing facing = BlockFacing.FromCode(block.LastCodePart()); BlockEntityBed beBed = world.BlockAccessor.GetBlockEntity(block.LastCodePart(1) == "feet" ? pos.AddCopy(facing) : pos) as BlockEntityBed; return(beBed); }
bool CanBlockStay(IWorldAccessor world, BlockPos pos) { string[] parts = block.Code.Path.Split('-'); BlockFacing facing = BlockFacing.FromCode(parts[parts.Length - 1]); int blockId = world.BlockAccessor.GetBlockId(pos.AddCopy(facing)); Block attachingblock = world.BlockAccessor.GetBlock(blockId); return(attachingblock.CanAttachBlockAt(world.BlockAccessor, block, pos, facing.GetOpposite())); }
public BlockPos OtherPartPos(BlockPos pos) { BlockFacing facing = BlockFacing.FromCode(LastCodePart()); if (LastCodePart(1) == "feet") { facing = facing.Opposite; } return(pos.AddCopy(facing)); }
bool CanStay(IWorldAccessor world, BlockPos pos) { BlockFacing facing = BlockFacing.FromCode(block.FirstCodePart(facingPos)); Block attachedblock = world.BlockAccessor.GetBlock(world.BlockAccessor.GetBlockId(pos.AddCopy(facing.GetOpposite()))); BlockFacing onFace = facing; //if (onFace.IsHorizontal) onFace = onFace.GetOpposite(); - why is this here? Breaks attachment return(attachedblock.CanAttachBlockAt(world.BlockAccessor, block, pos, onFace)); }
public BEBehaviorMPRotor(BlockEntity blockentity) : base(blockentity) { Blockentity = blockentity; string orientation = blockentity.Block.Variant["side"]; ownFacing = BlockFacing.FromCode(orientation); OutFacingForNetworkDiscovery = ownFacing.Opposite; //inTurnDir.Rot = ownFacing == BlockFacing.WEST || ownFacing == BlockFacing.NORTH ? EnumRotDirection.Counterclockwise : EnumRotDirection.Clockwise; }
public override void Initialize(ICoreAPI api, JsonObject properties) { base.Initialize(api, properties); if (api.Side.IsServer()) { face = BlockFacing.FromCode(Block.Variant["side"]); CheckWater(0); Blockentity.RegisterGameTickListener(CheckWater, 1000); } }
public override AssetLocation GetHorizontallyFlippedBlockCode(EnumAxis axis) { BlockFacing facing = BlockFacing.FromCode(Variant["horizontalorientation"]); if (facing.Axis == axis) { return(CodeWithVariant("horizontalorientation", facing.Opposite.Code)); } return(Code); }
public override void OnLoaded(ICoreAPI api) { if (LastCodePart(1) == "feet") { BlockFacing facing = BlockFacing.FromCode(LastCodePart()).Opposite; RootOffset = new BlockPos(facing.Normali); } base.OnLoaded(api); init(); }
public BlockPos OtherPartPos(IWorldAccessor world, BlockPos pos) { BlockFacing facing = BlockFacing.FromCode(LastCodePart()); if (LastCodePart(1) == "feet") { facing = facing.GetOpposite(); } return(pos.AddCopy(facing)); }
public override AssetLocation GetHorizontallyFlippedBlockCode(EnumAxis axis, ref EnumHandling handling) { handling = EnumHandling.PreventDefault; BlockFacing facing = BlockFacing.FromCode(block.LastCodePart()); if (facing.Axis == axis) { return(block.CodeWithParts(facing.Opposite.Code)); } return(block.Code); }
public bool HasSupportUp(Block forBlock, IBlockAccessor blockAccess, BlockPos pos) { BlockFacing ownFacing = BlockFacing.FromCode(forBlock.LastCodePart()); BlockPos upPos = pos.UpCopy(); return (SideSolid(blockAccess, pos, ownFacing) || SideSolid(blockAccess, upPos, BlockFacing.UP) || (pos.Y < blockAccess.MapSizeY - 1 && blockAccess.GetBlock(upPos) == forBlock && HasSupportUp(forBlock, blockAccess, upPos)) ); }
private void InitInventory() { if (Block?.Attributes != null) { if (Block.Attributes["pullFaces"].Exists) { string[] faces = Block.Attributes["pullFaces"].AsArray <string>(null); PullFaces = new BlockFacing[faces.Length]; for (int i = 0; i < faces.Length; i++) { PullFaces[i] = BlockFacing.FromCode(faces[i]); } } if (Block.Attributes["pushFaces"].Exists) { string[] faces = Block.Attributes["pushFaces"].AsArray <string>(null); PushFaces = new BlockFacing[faces.Length]; for (int i = 0; i < faces.Length; i++) { PushFaces[i] = BlockFacing.FromCode(faces[i]); } } if (Block.Attributes["acceptFromFaces"].Exists) { string[] faces = Block.Attributes["acceptFromFaces"].AsArray <string>(null); AcceptFromFaces = new BlockFacing[faces.Length]; for (int i = 0; i < faces.Length; i++) { AcceptFromFaces[i] = BlockFacing.FromCode(faces[i]); } } itemFlowRate = Block.Attributes["item-flowrate"].AsFloat(itemFlowRate); checkRateMs = Block.Attributes["item-checkrateMs"].AsInt(200); inventoryClassName = Block.Attributes["inventoryClassName"].AsString(inventoryClassName); ItemFlowObjectLangCode = Block.Attributes["itemFlowObjectLangCode"].AsString(ItemFlowObjectLangCode); QuantitySlots = Block.Attributes["quantitySlots"].AsInt(QuantitySlots); } if (inventory == null) { inventory = new InventoryGeneric(QuantitySlots, null, null, null); inventory.OnInventoryClosed += OnInvClosed; inventory.OnInventoryOpened += OnInvOpened; inventory.SlotModified += OnSlotModifid; inventory.OnGetAutoPushIntoSlot = GetAutoPushIntoSlot; inventory.OnGetAutoPullFromSlot = GetAutoPullFromSlot; } }
public override AssetLocation GetRotatedBlockCode(int angle) { if (Variant["orientation"] == "up") { return(Code); } BlockFacing oldFacing = BlockFacing.FromCode(Variant["orientation"]); BlockFacing newFacing = BlockFacing.HORIZONTALS_ANGLEORDER[((360 - angle) / 90 + oldFacing.HorizontalAngleIndex) % 4]; return(CodeWithParts(newFacing.Code)); }
public bool HasSupportDown(Block forBlock, IBlockAccessor blockAccess, BlockPos pos) { BlockFacing ownFacing = BlockFacing.FromCode(forBlock.LastCodePart()); BlockPos downPos = pos.DownCopy(); return (SideSolid(blockAccess, pos, ownFacing) || SideSolid(blockAccess, downPos, BlockFacing.DOWN) || (pos.Y > 0 && blockAccess.GetBlock(downPos) == forBlock && HasSupportDown(forBlock, blockAccess, downPos)) ); }
public override void Initialize(ICoreAPI api) { base.Initialize(api); powerOutFacing = BlockFacing.FromCode(Block.Variant["side"]); if (api.World.Side == EnumAppSide.Server) { InitializeEnergyPoint(api); RegisterGameTickListener(tick, 250); } }
bool CanStay(IBlockAccessor blockAccessor, BlockPos pos) { BlockFacing facing = BlockFacing.FromCode(Variant["orientation"]); BlockPos attachingBlockPos = pos.AddCopy(facing.Opposite); Block block = blockAccessor.GetBlock(attachingBlockPos); Cuboidi attachmentArea = null; attachmentAreas?.TryGetValue(facing.Opposite.Code, out attachmentArea); return(block.CanAttachBlockAt(blockAccessor, this, attachingBlockPos, facing, attachmentArea)); }
public override AssetLocation GetHorizontallyFlippedBlockCode(EnumAxis axis, ref EnumHandling handling) { handling = EnumHandling.PreventDefault; BlockFacing curFacing = BlockFacing.FromCode(block.Variant["rot"]); if (curFacing.Axis == axis) { return(block.CodeWithVariant("rot", curFacing.Opposite.Code)); } return(block.Code); }
bool CanStay(IWorldAccessor world, BlockPos pos) { BlockFacing facing = BlockFacing.FromCode(block.Variant[facingCode]); BlockPos attachingBlockPos = pos.AddCopy(facing.Opposite); Block attachedblock = world.BlockAccessor.GetBlock(world.BlockAccessor.GetBlockId(attachingBlockPos)); BlockFacing onFace = facing; Cuboidi attachmentArea = null; attachmentAreas?.TryGetValue(facing.Code, out attachmentArea); return(attachedblock.CanAttachBlockAt(world.BlockAccessor, block, attachingBlockPos, onFace, attachmentArea)); }
public override AssetLocation GetRotatedBlockCode(int angle, ref EnumHandling handling) { BlockFacing curFacing = BlockFacing.FromCode(block.Variant["rot"]); if (curFacing.IsVertical) { return(block.Code); } handling = EnumHandling.PreventDefault; BlockFacing newFacing = BlockFacing.HORIZONTALS_ANGLEORDER[((360 - angle) / 90 + curFacing.HorizontalAngleIndex) % 4]; return(block.CodeWithVariant("rot", newFacing.Code)); }
public override void Initialize(ICoreAPI api) { base.Initialize(api); Api = api; face = BlockFacing.FromCode(Block.Variant["side"]); if (api.World.Side == EnumAppSide.Server) { RegisterGameTickListener(tick, 250); } if (energyStorage == null) { energyStorage = new FluxStorage(MyMiniLib.GetAttributeInt(Block, "transfer", 10000), MyMiniLib.GetAttributeInt(Block, "transfer", 10000), MyMiniLib.GetAttributeInt(Block, "transfer", 10000)); } if (sideConfig.Count == 0) { string[] splitedPath = Block.Code.ToString().Split('-'); if (splitedPath.Length >= 6) { foreach (BlockFacing f in BlockFacing.ALLFACES) { if (splitedPath[splitedPath.Length - 6 + f.Index] == IOEnergySideConfig.INPUT.toString()) { sideConfig.Add(f, IOEnergySideConfig.INPUT); } else if (splitedPath[splitedPath.Length - 6 + f.Index] == IOEnergySideConfig.OUTPUT.toString()) { sideConfig.Add(f, IOEnergySideConfig.OUTPUT); } else { sideConfig.Add(f, IOEnergySideConfig.NONE); } } } else { foreach (BlockFacing f in BlockFacing.ALLFACES) { sideConfig.Add(f, IOEnergySideConfig.NONE); } } } if (face != null) { sideConfig[face] = IOEnergySideConfig.NONE; } }
public override void Initialize(JsonObject properties) { base.Initialize(properties); attachableFaces = new BlockFacing[] { BlockFacing.DOWN }; if (properties["attachableFaces"].Exists) { string[] faces = properties["attachableFaces"].AsArray <string>(); attachableFaces = new BlockFacing[faces.Length]; for (int i = 0; i < faces.Length; i++) { attachableFaces[i] = BlockFacing.FromCode(faces[i]); } } var areas = properties["attachmentAreas"].AsObject <Dictionary <string, RotatableCube> >(null); attachmentAreas = new Dictionary <string, Cuboidi>(); if (areas != null) { foreach (var val in areas) { val.Value.Origin.Set(8, 8, 8); attachmentAreas[val.Key] = val.Value.RotatedCopy().ConvertToCuboidi(); } } else { attachmentAreas["up"] = properties["attachmentArea"].AsObject <Cuboidi>(null); } ignorePlaceTest = properties["ignorePlaceTest"].AsBool(false); exceptions = properties["exceptions"].AsObject(new AssetLocation[0], block.Code.Domain); fallSideways = properties["fallSideways"].AsBool(false); dustIntensity = properties["dustIntensity"].AsFloat(0); fallSidewaysChance = properties["fallSidewaysChance"].AsFloat(0.3f); string sound = properties["fallSound"].AsString(null); if (sound != null) { fallSound = AssetLocation.Create(sound, block.Code.Domain); } impactDamageMul = properties["impactDamageMul"].AsFloat(1f); }
public override void Initialize(JsonObject properties) { AttachedToFaces = new BlockFacing[] { BlockFacing.DOWN }; if (properties["attachedToFaces"].Exists) { string[] faces = properties["attachedToFaces"].AsArray <string>(); AttachedToFaces = new BlockFacing[faces.Length]; for (int i = 0; i < faces.Length; i++) { AttachedToFaces[i] = BlockFacing.FromCode(faces[i]); } } }
public override void Initialize(ICoreAPI api) { base.Initialize(api); if (Block.Attributes != null) { genAmps = Block.Attributes["genAmps"].AsInt(genAmps); fuelHopperFace = BlockFacing.FromCode(Block.Attributes["fuelHopperFace"].AsString("up")); fuelHopperFace = OrientFace(Block.Code.ToString(), fuelHopperFace); string[] fc = Block.Attributes["fuelCodes"].AsArray <string>(); if (fc != null) { fuelCodes = fc.ToList <string>(); } fuelTicks = Block.Attributes["fuelTicks"].AsInt(1); usesFuel = Block.Attributes["usesFuel"].AsBool(false); usesFuelWhileOn = Block.Attributes["usesFuelWhileOn"].AsBool(false); requiredHeat = Block.Attributes["requiredHeat"].AsFloat(requiredHeat); if (requiredHeat > 0) { requiresHeat = true; } heatFace = BlockFacing.FromCode(Block.Attributes["heatFace"].AsString("down")); heatFace = OrientFace(Block.Code.ToShortString(), heatFace); waterUsage = Block.Attributes["waterUsage"].AsInt(waterUsage); if (waterUsage > 0) { requiresWater = true; } waterUsePeriod = Block.Attributes["waterUsePeriod"].AsFloat(waterUsePeriod); overloadIfNoWater = Block.Attributes["overloadIfNoWater"].AsBool(overloadIfNoWater); waterFace = BlockFacing.FromCode(Block.Attributes["waterFace"].AsString("up")); fuelCounter = 0; if (lastwaterused == 0) { lastwaterused = Api.World.Calendar.TotalHours; } } if (api.World.Side == EnumAppSide.Client && animUtil != null && !blockgone) { float rotY = Block.Shape.rotateY; animUtil.InitializeAnimator(Pos.ToString() + "run", new Vec3f(0, rotY, 0)); animUtil.StartAnimation(new AnimationMetaData() { Animation = "run", Code = "run", AnimationSpeed = 1, EaseInSpeed = 4, EaseOutSpeed = 8, Weight = 1, BlendMode = EnumAnimationBlendMode.Average }); animInit = true; } }
public override bool OnWorldEditCommand(WorldEdit worldEdit, CmdArgs args) { string cmd = args.PopWord(); switch (cmd) { case "tm": { EnumMoveToolMode mode = EnumMoveToolMode.MoveBlocks; if (args.Length > 0) { int index; int.TryParse(args[0], out index); if (Enum.IsDefined(typeof(EnumMoveToolMode), index)) { mode = (EnumMoveToolMode)index; } } MoveRepeatMode = mode; worldEdit.Good(Lang.Get("Tool mode now set to {0}", mode)); return(true); } case "am": { Amount = (int)args.PopInt(1); worldEdit.Good(Lang.Get("Amount set to {0}", Amount)); return(true); } case "north": case "east": case "west": case "south": case "up": case "down": { BlockFacing facing = BlockFacing.FromCode(cmd); Handle(worldEdit, facing.Normali); return(true); } } return(false); }
public override bool OnTesselation(ITerrainMeshPool mesher, ITesselatorAPI tesselator) { ICoreClientAPI capi = Api as ICoreClientAPI; Shape shape = capi.Assets.TryGet("temporalengineering:shapes/block/engine/body.json").ToObject <Shape>(); switch (BlockFacing.FromCode(Block.Variant["side"]).Index) { case 0: AxisSign = new int[] { 0, 0, -1 }; rotateY = 180; break; case 1: AxisSign = new int[] { -1, 0, 0 }; rotateY = 90; break; case 2: AxisSign = new int[] { 0, 0, -1 }; rotateY = 0; break; case 3: AxisSign = new int[] { -1, 0, 0 }; rotateY = 270; break; case 4: AxisSign = new int[] { 0, 1, 0 }; rotateZ = 270; break; case 5: AxisSign = new int[] { 0, 1, 0 }; rotateZ = 90; break; default: break; } MeshData mesh; capi.Tesselator.TesselateShape(Block, shape, out mesh, new Vec3f(rotateZ, rotateY, 0)); mesher.AddMeshData(mesh); return(true); }
public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel) { if (!world.Claims.TryAccess(byPlayer, blockSel.Position, EnumBlockAccessFlags.Use)) { return(false); } BlockFacing facing = BlockFacing.FromCode(LastCodePart()).Opposite; BlockEntityBed beBed = world.BlockAccessor.GetBlockEntity(LastCodePart(1) == "feet" ? blockSel.Position.AddCopy(facing) : blockSel.Position) as BlockEntityBed; if (beBed == null) { return(false); } if (beBed.MountedBy != null) { return(false); } EntityBehaviorTiredness ebt = byPlayer.Entity.GetBehavior("tiredness") as EntityBehaviorTiredness; if (ebt != null && ebt.Tiredness <= 8) { if (world.Side == EnumAppSide.Client) { (api as ICoreClientAPI).TriggerIngameError(this, "nottiredenough", Lang.Get("not-tired-enough")); } return(false); } int tempStormSleep = api.World.Config.GetString("temporalStormSleeping", "0").ToInt(); if (tempStormSleep == 0 && api.ModLoader.GetModSystem <SystemTemporalStability>().StormStrength > 0) { if (world.Side == EnumAppSide.Client) { (api as ICoreClientAPI).TriggerIngameError(this, "cantsleep-tempstorm", Lang.Get("cantsleep-tempstorm")); } return(false); } return(byPlayer.Entity.TryMount(beBed)); }
public override void OnLoaded(ICoreAPI api) { base.OnLoaded(api); capi = api as ICoreClientAPI; rot = BlockFacing.FromCode(Variant["rot"]); testGroundSnowRemoval = Variant["cover"] == "snow" && (Variant["rot"] == "north" || Variant["rot"] == "east" || Variant["rot"] == "south" || Variant["rot"] == "west") ; testGroundSnowAdd = Variant["cover"] == "free" && (Variant["rot"] == "north" || Variant["rot"] == "east" || Variant["rot"] == "south" || Variant["rot"] == "west") ; }
public override string GetPlacedBlockInfo(IWorldAccessor world, BlockPos pos, IPlayer forPlayer) { if (LastCodePart(1) == "feet") { BlockFacing facing = BlockFacing.FromCode(LastCodePart()).GetOpposite(); pos = pos.AddCopy(facing); } BlockEntityTrough betr = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityTrough; if (betr != null) { return(betr.GetBlockInfo(forPlayer)); } return(base.GetPlacedBlockInfo(world, pos, forPlayer)); }