public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel) { BlockEntityCrate be = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityCrate; if (be != null) { return(be.OnBlockInteractStart(byPlayer, blockSel)); } return(base.OnBlockInteractStart(world, byPlayer, blockSel)); }
public override Cuboidf[] GetCollisionBoxes(IBlockAccessor blockAccessor, BlockPos pos) { BlockEntityCrate be = blockAccessor.GetBlockEntity(pos) as BlockEntityCrate; if (be != null && be.LidState == "closed") { return(closedCollBoxes); } return(base.GetCollisionBoxes(blockAccessor, pos)); }
public override Cuboidf[] GetSelectionBoxes(IBlockAccessor blockAccessor, BlockPos pos) { BlockEntityCrate be = blockAccessor.GetBlockEntity(pos) as BlockEntityCrate; if (be != null) { return(be.GetSelectionBoxes()); } return(base.GetSelectionBoxes(blockAccessor, pos)); }
public override bool DoPlaceBlock(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ItemStack byItemStack) { bool val = base.DoPlaceBlock(world, byPlayer, blockSel, byItemStack); if (val) { BlockEntityCrate bect = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityCrate; if (bect != null) { BlockPos targetPos = blockSel.DidOffset ? blockSel.Position.AddCopy(blockSel.Face.Opposite) : blockSel.Position; double dx = byPlayer.Entity.Pos.X - (targetPos.X + blockSel.HitPosition.X); double dz = (float)byPlayer.Entity.Pos.Z - (targetPos.Z + blockSel.HitPosition.Z); float angleHor = (float)Math.Atan2(dx, dz); string type = bect.type; string rotatatableInterval = Props[type].RotatatableInterval; if (rotatatableInterval == "22.5degnot45deg") { float rounded90degRad = ((int)Math.Round(angleHor / GameMath.PIHALF)) * GameMath.PIHALF; float deg45rad = GameMath.PIHALF / 4; if (Math.Abs(angleHor - rounded90degRad) >= deg45rad) { bect.MeshAngle = rounded90degRad + 22.5f * GameMath.DEG2RAD * Math.Sign(angleHor - rounded90degRad); } else { bect.MeshAngle = rounded90degRad; } } if (rotatatableInterval == "22.5deg") { float deg22dot5rad = GameMath.PIHALF / 4; float roundRad = ((int)Math.Round(angleHor / deg22dot5rad)) * deg22dot5rad; bect.MeshAngle = roundRad; } } } return(val); }
public override ItemStack OnPickBlock(IWorldAccessor world, BlockPos pos) { ItemStack stack = new ItemStack(this); BlockEntityCrate be = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityCrate; if (be != null) { stack.Attributes.SetString("type", be.type); if (be.label != null && be.label.Length > 0) { stack.Attributes.SetString("label", be.label); } stack.Attributes.SetString("lidState", be.preferredLidState); } else { stack.Attributes.SetString("type", Props.DefaultType); } return(stack); }