public override void OnBlockBroken(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, float dropQuantityMultiplier = 1f) { BEMPMultiblockBase be = world.BlockAccessor.GetBlockEntity(pos) as BEMPMultiblockBase; if (be == null || be.Principal == null) { // being broken by other game code (including on breaking the center large gear): standard block breaking treatment base.OnBlockBroken(world, pos, byPlayer, dropQuantityMultiplier); return; } // being broken by player: break the center block instead BlockPos centerPos = be.Principal; Block centerBlock = world.BlockAccessor.GetBlock(centerPos); centerBlock.OnBlockBroken(world, centerPos, byPlayer, dropQuantityMultiplier); // Need to trigger neighbourchange on client side only (because it's normally in the player block breaking code) if (api.Side == EnumAppSide.Client) { foreach (BlockFacing facing in BlockFacing.VERTICALS) { BlockPos npos = centerPos.AddCopy(facing); world.BlockAccessor.GetBlock(npos).OnNeighbourBlockChange(world, npos, centerPos); } } }
private void PlaceFakeBlocks(IWorldAccessor world, BlockPos pos) { Block toPlaceBlock = world.GetBlock(new AssetLocation("temporalengineering:multiblockwood")); BlockPos tmpPos = new BlockPos(); for (int d1 = -1; d1 <= 1; d1++) { for (int d2 = -1; d2 <= 1; d2++) { if (d1 == 0 && d2 == 0) { continue; } if (powerOutFacing == BlockFacing.EAST || powerOutFacing == BlockFacing.WEST) { tmpPos.Set(pos.X, pos.Y + d1, pos.Z + d2); } else { tmpPos.Set(pos.X + d2, pos.Y + d1, pos.Z); } world.BlockAccessor.SetBlock(toPlaceBlock.BlockId, tmpPos); BEMPMultiblockBase be = world.BlockAccessor.GetBlockEntity(tmpPos) as BEMPMultiblockBase; if (be != null) { be.Principal = pos; } } } }
//Need to override because this fake block has no texture of its own (no texture gives black breaking particles) public override int GetRandomColor(ICoreClientAPI capi, BlockPos pos, BlockFacing facing) { IBlockAccessor blockAccess = capi.World.BlockAccessor; BEMPMultiblockBase be = blockAccess.GetBlockEntity(pos) as BEMPMultiblockBase; if (be == null || be.Principal == null) { return(0); } Block centerBlock = blockAccess.GetBlock(be.Principal); return(centerBlock.GetRandomColor(capi, be.Principal, facing)); }
public override Cuboidf GetParticleBreakBox(IBlockAccessor blockAccess, BlockPos pos, BlockFacing facing) { BEMPMultiblockBase be = blockAccess.GetBlockEntity(pos) as BEMPMultiblockBase; if (be == null || be.Principal == null) { return(base.GetParticleBreakBox(blockAccess, pos, facing)); } // being broken by player: break the center block instead Block centerBlock = blockAccess.GetBlock(be.Principal); return(centerBlock.GetParticleBreakBox(blockAccess, be.Principal, facing)); }
public override void OnBlockRemoved(IWorldAccessor world, BlockPos pos) { base.OnBlockRemoved(world, pos); BlockPos tmpPos = new BlockPos(); for (int d1 = -1; d1 <= 1; d1++) { for (int d2 = -1; d2 <= 1; d2++) { if (d1 == 0 && d2 == 0) { continue; } if (powerOutFacing == BlockFacing.EAST || powerOutFacing == BlockFacing.WEST) { tmpPos.Set(pos.X, pos.Y + d1, pos.Z + d2); } else { tmpPos.Set(pos.X + d2, pos.Y + d1, pos.Z); } //Destroy any fake blocks; revert small gears to their normal peg gear type BEMPMultiblockBase be = world.BlockAccessor.GetBlockEntity(tmpPos) as BEMPMultiblockBase; if (be != null && pos.Equals(be.Principal)) { be.Principal = null; //signal to BlockMPMultiblockWood that it can be broken normally without triggering this in a loop world.BlockAccessor.SetBlock(0, tmpPos); } else { //BlockAngledGears smallgear = world.BlockAccessor.GetBlock(tmpPos) as BlockAngledGears; //if (smallgear != null) smallgear.ToPegGear(world, tmpPos); } } } }
public override float OnGettingBroken(IPlayer player, BlockSelection blockSel, ItemSlot itemslot, float remainingResistance, float dt, int counter) { IWorldAccessor world = null; if (player == null && player.Entity == null) { world = player.Entity.World; } if (world == null) { world = api.World; } BEMPMultiblockBase be = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BEMPMultiblockBase; if (be == null || be.Principal == null) { return(1f); //never break } Block centerBlock = world.BlockAccessor.GetBlock(be.Principal); BlockSelection bs = blockSel.Clone(); bs.Position = be.Principal; return(centerBlock.OnGettingBroken(player, bs, itemslot, remainingResistance, dt, counter)); }