public void trySetNetwork(long networkId, BlockFacing localFacing) { if (hasConnectorAt(localFacing)) { this.networkId = networkId; IMechanicalPowerDevice device = getNeighbourDevice(localFacing, true); if (device != null) { if (getNetwork(localFacing).getDirection() != 0) { clockwise = device.isClockWiseDirection(localFacing.GetOpposite()); setDirectionFromFacing(localFacing.GetOpposite()); } } else { throw new Exception("Eh, a network coming from " + localFacing + ", but there is no device, instead " + api.World.BlockAccessor.GetBlock(pos.AddCopy(localFacing)) + "?!"); } getNetwork(localFacing).register(this); api.World.BlockAccessor.MarkBlockEntityDirty(pos); } else { directionFromFacing = null; this.networkId = 0; } }
public override void Initialize(ICoreAPI api) { base.Initialize(api); RegisterGameTickListener(OnTick, 25); RegisterGameTickListener(OnSlowTick, 1000); fireBlock = api.World.GetBlock(new AssetLocation("fire")); if (fireBlock == null) { fireBlock = new Block(); } neibBlock = api.World.BlockAccessor.GetBlock(pos.AddCopy(fromFacing.GetOpposite())); if (ambientSound == null && api.Side == EnumAppSide.Client) { RegisterDelayedCallback((dt) => { // When the world loads with a lot of fire they'll all start at the same millisecond, so lets delay a bit ambientSound = ((IClientWorldAccessor)api.World).LoadSound(new SoundParams() { Location = new AssetLocation("sounds/environment/fire.ogg"), ShouldLoop = true, Position = pos.ToVec3f().Add(0.5f, 0.25f, 0.5f), DisposeOnFinish = false, Volume = 1f }); ambientSound?.Start(); }, api.World.Rand.Next(200)); } }
public static IMechanicalPowerDevice getNeighbourDevice(IWorldAccessor world, BlockPos pos, BlockFacing facing, bool connected) { if (facing == null) { return(null); } BlockEntity te = world.BlockAccessor.GetBlockEntity(pos.Offset(facing)); if (te is IMechanicalPowerDevice) { IMechanicalPowerDevice mechdevice = (IMechanicalPowerDevice)te; if (!mechdevice.exists()) { return(null); } if (!connected && mechdevice.hasConnectorAt(facing.GetOpposite())) { return(mechdevice); } if (connected && mechdevice.isConnectedAt(facing.GetOpposite())) { return(mechdevice); } } return(null); }
public void propagateNetworkToNeighbours(int propagationId, int networkId, BlockFacing remoteFacing) { // Already propagated if (this.propagationId == propagationId) { return; } this.propagationId = propagationId; trySetNetwork(networkId, remoteFacing.GetOpposite()); getNetwork(remoteFacing.GetOpposite()).register(this); sendNetworkToNeighbours(propagationId, networkId, remoteFacing); }
public override void OnBlockRemoved(IWorldAccessor world, BlockPos pos) { string headfoot = LastCodePart(1); BlockFacing facing = BlockFacing.FromCode(LastCodePart()); if (LastCodePart(1) == "feet") { facing = facing.GetOpposite(); } else { BlockEntityBed beBed = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityBed; beBed?.MountedBy?.TryUnmount(); } Block secondPlock = world.BlockAccessor.GetBlock(pos.AddCopy(facing)); if (secondPlock is BlockBed && secondPlock.LastCodePart(1) != headfoot) { world.BlockAccessor.SetBlock(0, pos.AddCopy(facing)); } base.OnBlockRemoved(world, pos); }
public void Init(BlockFacing fromFacing) { this.fromFacing = fromFacing; neibBlock = api.World.BlockAccessor.GetBlock(pos.AddCopy(fromFacing.GetOpposite())); if (neibBlock?.CombustibleProps == null || neibBlock.CombustibleProps.BurnDuration <= 0) { foreach (BlockFacing facing in BlockFacing.ALLFACES) { neibBlock = api.World.BlockAccessor.GetBlock(pos.AddCopy(facing)); if (neibBlock?.CombustibleProps != null && neibBlock.CombustibleProps.BurnDuration > 0) { this.fromFacing = facing.GetOpposite(); startDuration = remainingBurnDuration = neibBlock.CombustibleProps.BurnDuration; return; } } startDuration = 1; remainingBurnDuration = 1; } else { startDuration = remainingBurnDuration = neibBlock.CombustibleProps.BurnDuration; } }
public void propagateDirectionToNeightbours(int propagationId, BlockFacing remoteFacing, bool clockwise) { // Already propagated if (this.propagationId == propagationId) { return; } this.propagationId = propagationId; this.clockwise = clockwise; setDirectionFromFacing(remoteFacing); api.World.BlockAccessor.MarkBlockEntityDirty(pos); Dictionary <BlockFacing, IMechanicalPowerDevice> connectibleNeighbours = getNeighbourDevices(true); foreach (BlockFacing localFacing in connectibleNeighbours.Keys) { if (remoteFacing.GetOpposite() != localFacing) { bool remoteClockwise = isClockWiseDirection(localFacing); connectibleNeighbours[localFacing].propagateDirectionToNeightbours(propagationId, localFacing, remoteClockwise); } } }
public override void OnClientGameTick(IWorldAccessor world, BlockPos pos, float secondsTicking) { if (ParticleProperties != null && ParticleProperties.Length > 0) { for (int i = 0; i < 4; i++) { if (world.Rand.NextDouble() > particleQuantity) { continue; } BlockFacing facing = BlockFacing.HORIZONTALS[i]; Block block = world.BlockAccessor.GetBlock(pos.X + facing.Normali.X, pos.Y, pos.Z + facing.Normali.Z); if (block.IsLiquid() || block.SideSolid[facing.GetOpposite().Index]) { continue; } AdvancedParticleProperties bps = ParticleProperties[i]; bps.basePos.X = pos.X + TopMiddlePos.X; bps.basePos.Y = pos.Y; bps.basePos.Z = pos.Z + TopMiddlePos.Z; bps.HsvaColor[3].avg = 180 * Math.Min(1, secondsTicking / 7f); bps.Quantity.avg = 1; bps.Velocity[1].avg = -0.4f; world.SpawnParticles(bps); } } }
public void Init(BlockFacing fromFacing, string startedByPlayerUid) { this.fromFacing = fromFacing; this.startedByPlayerUid = startedByPlayerUid; BlockPos neibPos = pos.AddCopy(fromFacing.GetOpposite()); neibBlock = api.World.BlockAccessor.GetBlock(neibPos); if (!canBurn(neibBlock, neibPos)) { foreach (BlockFacing facing in BlockFacing.ALLFACES) { BlockPos nnpos = pos.AddCopy(facing); neibBlock = api.World.BlockAccessor.GetBlock(nnpos); if (canBurn(neibBlock, nnpos)) { this.fromFacing = facing.GetOpposite(); startDuration = remainingBurnDuration = neibBlock.CombustibleProps.BurnDuration; return; } } startDuration = 1; remainingBurnDuration = 1; } else { startDuration = remainingBurnDuration = neibBlock.CombustibleProps.BurnDuration; } }
public override AssetLocation GetVerticallyFlippedBlockCode(ref EnumHandling handling) { handling = EnumHandling.PreventDefault; BlockFacing curFacing = BlockFacing.FromCode(block.LastCodePart()); if (curFacing.IsVertical) { return(block.CodeWithParts(curFacing.GetOpposite().Code)); } curFacing = BlockFacing.FromCode(block.LastCodePart(1)); if (curFacing != null && curFacing.IsVertical) { return(block.CodeWithParts(curFacing.GetOpposite().Code, block.LastCodePart())); } return(block.Code); }
public bool ShouldConnectAt(IWorldAccessor world, BlockPos ownPos, BlockFacing side) { Block block = world.BlockAccessor.GetBlock(ownPos.AddCopy(side)); return ((block.FirstCodePart() == FirstCodePart() || block.FirstCodePart() == FirstCodePart() + "gate") || block.SideSolid[side.GetOpposite().Index]); ; }
public BlockFacing OtherPartPos() { BlockFacing facing = BlockFacing.FromCode(LastCodePart()); if (LastCodePart(1) == "feet") { facing = facing.GetOpposite(); } return(facing); }
bool CanBlockStay(IWorldAccessor world, BlockPos pos) { string[] parts = Code.Path.Split('-'); BlockFacing facing = BlockFacing.FromCode(parts[parts.Length - 1]); int blockId = world.BlockAccessor.GetBlockId(pos.AddCopy(facing)); Block block = world.BlockAccessor.GetBlock(blockId); return(block.CanAttachBlockAt(world.BlockAccessor, this, pos, facing.GetOpposite())); }
public bool ShouldConnectAt(IWorldAccessor world, BlockPos ownPos, BlockFacing side) { Block block = world.BlockAccessor.GetBlock(ownPos.AddCopy(side)); if (ownFirstCodePart == block.FirstCodePart()) { return(true); } return(block.SideSolid[side.GetOpposite().Index]); //test if neighbor face is solid }
public override AssetLocation GetHorizontallyFlippedBlockCode(EnumAxis axis) { BlockFacing facing = BlockFacing.FromCode(LastCodePart()); if (facing.Axis == axis) { return(CodeWithParts(facing.GetOpposite().Code)); } return(Code); }
public BlockPos OtherPartPos(IWorldAccessor world, BlockPos pos) { BlockFacing facing = BlockFacing.FromCode(LastCodePart()); if (LastCodePart(1) == "feet") { facing = facing.GetOpposite(); } return(pos.AddCopy(facing)); }
public void sendNetworkToNeighbours(int propagationId, int networkId, BlockFacing remoteFacing) { Dictionary <BlockFacing, IMechanicalPowerDevice> connectibleNeighbours = getNeighbourDevices(true); foreach (BlockFacing localFacing in connectibleNeighbours.Keys) { if (remoteFacing.GetOpposite() != localFacing) { connectibleNeighbours[localFacing].propagateNetworkToNeighbours(propagationId, networkId, localFacing); } } }
public override AssetLocation GetHorizontallyFlippedBlockCode(EnumAxis axis, ref EnumHandling handling) { handling = EnumHandling.PreventDefault; BlockFacing facing = BlockFacing.FromCode(block.FirstCodePart(facingPos)); if (facing.Axis == axis) { return(block.CodeWithPart(facing.GetOpposite().Code, facingPos)); } return(block.Code); }
bool TryAttachTo(IBlockAccessor blockAccessor, BlockPos blockpos, BlockFacing onBlockFace) { BlockPos attachingBlockPos = blockpos.AddCopy(onBlockFace.GetOpposite()); Block block = blockAccessor.GetBlock(blockAccessor.GetBlockId(attachingBlockPos)); if (block.CanAttachBlockAt(blockAccessor, this, attachingBlockPos, onBlockFace)) { ushort blockId = blockAccessor.GetBlock(CodeWithParts(onBlockFace.Code)).BlockId; blockAccessor.SetBlock(blockId, blockpos); return(true); } return(false); }
internal virtual bool IsAttached(IBlockAccessor blockAccessor, BlockPos pos) { for (int i = 0; i < AttachedToFaces.Length; i++) { BlockFacing face = AttachedToFaces[i]; Block block = blockAccessor.GetBlock(pos.AddCopy(face)); if (block.CanAttachBlockAt(blockAccessor, block, pos.AddCopy(face), face.GetOpposite())) { return(true); } } return(false); }
private Block GetOrientedBlock(IWorldAccessor world, BlockSelection blockSel) { BlockFacing onBlockFace = blockSel.Face; Vec3d hitPosition = blockSel.HitPosition; //hitPosition projected on the onBlockFace to determine block orientation Vec3d normal = onBlockFace.Normalf.NormalizedCopy().ToVec3d(); normal.Mul((float)hitPosition.SubCopy(0.5, 0.5, 0.5).Dot(normal)); Vec3d projVector = hitPosition.SubCopy(normal).Sub(0.5, 0.5, 0.5); BlockFacing orientation = BlockFacing.FromVector(projVector.X, projVector.Y, projVector.Z); BlockFacing oppositeFace = onBlockFace.GetOpposite(); return(world.BlockAccessor.GetBlock(block.CodeWithParts(orientation.Code, oppositeFace.Code))); }
bool TryAttachTo(IWorldAccessor world, BlockPos blockpos, BlockFacing onBlockFace) { BlockFacing oppositeFace = onBlockFace.GetOpposite(); BlockPos attachingBlockPos = blockpos.AddCopy(oppositeFace); Block attachingBlock = world.BlockAccessor.GetBlock(world.BlockAccessor.GetBlockId(attachingBlockPos)); Block orientedBlock = world.BlockAccessor.GetBlock(block.CodeWithParts(oppositeFace.Code)); if (attachingBlock.CanAttachBlockAt(world.BlockAccessor, block, attachingBlockPos, onBlockFace) && orientedBlock.IsSuitablePosition(world, blockpos)) { orientedBlock.DoPlaceBlock(world, blockpos, onBlockFace, null); return(true); } return(false); }
bool TryAttachTo(IWorldAccessor world, BlockPos blockpos, BlockFacing onBlockFace) { BlockFacing oppositeFace = onBlockFace.GetOpposite(); BlockPos attachingBlockPos = blockpos.AddCopy(oppositeFace); Block block = world.BlockAccessor.GetBlock(world.BlockAccessor.GetBlockId(attachingBlockPos)); if (block.CanAttachBlockAt(world.BlockAccessor, this, attachingBlockPos, onBlockFace)) { int blockId = world.BlockAccessor.GetBlock(CodeWithParts(oppositeFace.Code)).BlockId; world.BlockAccessor.SetBlock(blockId, blockpos); return(true); } return(false); }
public bool ShouldConnectAt(IWorldAccessor world, BlockPos ownPos, BlockFacing side) { Block block = world.BlockAccessor.GetBlock(ownPos.AddCopy(side)); bool attrexists = block.Attributes?["fenceConnect"][side.Code].Exists == true; if (attrexists) { return(block.Attributes["fenceConnect"][side.Code].AsBool(true)); } return ((block.FirstCodePart() == FirstCodePart() || block.FirstCodePart() == FirstCodePart() + "gate") || block.SideSolid[side.GetOpposite().Index]); ; }
public bool ShouldConnectAt(IWorldAccessor world, BlockPos ownPos, BlockFacing side) { Block block = world.BlockAccessor.GetBlock(ownPos.AddCopy(side)); Block B1 = refBlock; String s1 = block.FirstCodePart(); String s2 = B1.Code.FirstPathPart(); if (block.BlockId != null) {//test same base block if (refBlock.FirstCodePart() == block.FirstCodePart()) { return(true); } } return((bool)block.SideSolid[side.GetOpposite().Index]); //test if neighbor face is solid }
bool TryAttachTo(IWorldAccessor world, BlockPos blockpos, BlockFacing onBlockFace) { BlockFacing onFace = onBlockFace; //if (onFace.IsHorizontal) onFace = onFace.GetOpposite(); - why is this here? Breaks attachment BlockPos attachingBlockPos = blockpos.AddCopy(onBlockFace.GetOpposite()); Block block = world.BlockAccessor.GetBlock(world.BlockAccessor.GetBlockId(attachingBlockPos)); if (block.CanAttachBlockAt(world.BlockAccessor, this, attachingBlockPos, onFace)) { ushort blockId = world.BlockAccessor.GetBlock(CodeWithParts(onBlockFace.Code)).BlockId; world.BlockAccessor.SetBlock(blockId, blockpos); return(true); } return(false); }
bool TryAttachTo(IWorldAccessor world, BlockPos blockpos, BlockFacing onBlockFace, ItemStack itemstack) { BlockPos attachingBlockPos = blockpos.AddCopy(onBlockFace.GetOpposite()); Block attachingBlock = world.BlockAccessor.GetBlock(world.BlockAccessor.GetBlockId(attachingBlockPos)); BlockFacing onFace = onBlockFace; ///if (onFace.IsHorizontal) onFace = onFace.GetOpposite(); - why is this here? Breaks attachment if (attachingBlock.CanAttachBlockAt(world.BlockAccessor, block, attachingBlockPos, onFace)) { Block orientedBlock = world.BlockAccessor.GetBlock(block.CodeWithPart(onBlockFace.Code, facingPos)); orientedBlock.DoPlaceBlock(world, blockpos, onBlockFace, itemstack); return(true); } return(false); }
private bool TryAttachPlaceToHoriontal(IWorldAccessor world, IPlayer byPlayer, BlockPos position, BlockFacing toFacing, BlockFacing targetFacing) { Block neibBlock = world.BlockAccessor.GetBlock(position.AddCopy(toFacing)); if (!(neibBlock is BlockRails)) { return(false); } BlockFacing fromFacing = toFacing.GetOpposite(); BlockFacing[] neibDirFacings = getFacingsFromType(neibBlock.Variant["type"]); // Already attached, do default placement behavior if (neibDirFacings[0] == fromFacing || neibDirFacings[1] == fromFacing) { 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_", fromFacing, targetFacing); if (blockToPlace != null) { if (!placeIfSuitable(blockToPlace, world, position)) { return(false); } } 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); block.DoPlaceBlock(world, position.AddCopy(toFacing), BlockFacing.UP, null); return(false); }
public void WasPlaced(IWorldAccessor world, BlockPos ownPos, BlockFacing connectedOnFacing = null, IMechanicalPowerBlock connectedToBlock = null) { BEMPBase beMechBase = (world.BlockAccessor.GetBlockEntity(ownPos) as BEMPBase); MechanicalNetwork network; if (connectedOnFacing == null) { network = mechPower.CreateNetwork(); } else { network = connectedToBlock.GetNetwork(world, ownPos.AddCopy(connectedOnFacing)); IMechanicalPowerNode node = world.BlockAccessor.GetBlockEntity(ownPos.AddCopy(connectedOnFacing)) as IMechanicalPowerNode; beMechBase?.SetBaseTurnDirection(node.GetTurnDirection(connectedOnFacing.GetOpposite()), connectedOnFacing.GetOpposite()); } beMechBase?.JoinNetwork(network); }
public override void OnBlockRemoved(IWorldAccessor world, BlockPos pos) { string headfoot = LastCodePart(1); BlockFacing facing = BlockFacing.FromCode(LastCodePart()); if (LastCodePart(1) == "feet") { facing = facing.GetOpposite(); } Block secondPlock = world.BlockAccessor.GetBlock(pos.AddCopy(facing)); if (secondPlock is BlockTroughDoubleBlock && secondPlock.LastCodePart(1) != headfoot) { if (LastCodePart(1) == "feet") { (world.BlockAccessor.GetBlockEntity(pos.AddCopy(facing)) as BlockEntityTrough)?.OnBlockBroken(); } world.BlockAccessor.SetBlock(0, pos.AddCopy(facing)); } base.OnBlockRemoved(world, pos); }