public override string GetHeldBlockInfo(IWorldAccessor world, ItemSlot inSlot) { EnumSlabPlaceMode mode = (EnumSlabPlaceMode)inSlot.Itemstack.Attributes.GetInt("slabPlaceMode", 0); switch (mode) { case EnumSlabPlaceMode.Auto: return(Lang.Get("slab-placemode-auto") + "\n"); case EnumSlabPlaceMode.Horizontal: return(Lang.Get("slab-placemode-horizontal") + "\n"); case EnumSlabPlaceMode.Vertical: return(Lang.Get("slab-placemode-vertical") + "\n"); } return(base.GetHeldBlockInfo(world, inSlot)); }
public override void OnBeforeRender(ICoreClientAPI capi, ItemStack itemstack, EnumItemRenderTarget target, ref ItemRenderInfo renderinfo) { EnumSlabPlaceMode mode = (EnumSlabPlaceMode)itemstack.Attributes.GetInt("slabPlaceMode", 0); if (mode == EnumSlabPlaceMode.Vertical) { renderinfo.Transform = renderinfo.Transform.Clone(); renderinfo.Transform.Rotation.X = -80; renderinfo.Transform.Rotation.Y = 0; renderinfo.Transform.Rotation.Z = -22.5f; } if (mode == EnumSlabPlaceMode.Horizontal) { renderinfo.Transform = renderinfo.Transform.Clone(); renderinfo.Transform.Rotation.X = 5; } base.OnBeforeRender(capi, itemstack, target, ref renderinfo); }
public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel, ref EnumHandling handling, ref string failureCode) { handling = EnumHandling.PreventDefault; AssetLocation blockCode = null; Block orientedBlock; EnumSlabPlaceMode mode = itemstack.Attributes == null ? EnumSlabPlaceMode.Auto : (EnumSlabPlaceMode)itemstack.Attributes.GetInt("slabPlaceMode", 0); if (mode == EnumSlabPlaceMode.Horizontal) { string side = blockSel.HitPosition.Y < 0.5 ? "down" : "up"; if (blockSel.Face.IsVertical) { side = blockSel.Face.Opposite.Code; } blockCode = block.CodeWithVariant("rot", side); orientedBlock = world.BlockAccessor.GetBlock(blockCode); if (orientedBlock.CanPlaceBlock(world, byPlayer, blockSel, ref failureCode)) { world.BlockAccessor.SetBlock(orientedBlock.BlockId, blockSel.Position); return(true); } return(false); } if (mode == EnumSlabPlaceMode.Vertical) { BlockFacing[] hv = Block.SuggestedHVOrientation(byPlayer, blockSel); string side = hv[0].Code; if (blockSel.Face.IsHorizontal) { side = blockSel.Face.Opposite.Code; } blockCode = block.CodeWithVariant("rot", side); orientedBlock = world.BlockAccessor.GetBlock(blockCode); if (orientedBlock.CanPlaceBlock(world, byPlayer, blockSel, ref failureCode)) { world.BlockAccessor.SetBlock(orientedBlock.BlockId, blockSel.Position); return(true); } return(false); } if (rotateSides) { // Simple 6 state rotator. if (facing == "block") { var x = Math.Abs(blockSel.HitPosition.X - 0.5); var y = Math.Abs(blockSel.HitPosition.Y - 0.5); var z = Math.Abs(blockSel.HitPosition.Z - 0.5); switch (blockSel.Face.Axis) { case EnumAxis.X: if (z < 0.3 && y < 0.3) { blockCode = block.CodeWithVariant("rot", blockSel.Face.Opposite.Code); } else if (z > y) { blockCode = block.CodeWithVariant("rot", blockSel.HitPosition.Z < 0.5 ? "north" : "south"); } else { blockCode = block.CodeWithVariant("rot", blockSel.HitPosition.Y < 0.5 ? "down" : "up"); } break; case EnumAxis.Y: if (z < 0.3 && x < 0.3) { blockCode = block.CodeWithVariant("rot", blockSel.Face.Opposite.Code); } else if (z > x) { blockCode = block.CodeWithVariant("rot", blockSel.HitPosition.Z < 0.5 ? "north" : "south"); } else { blockCode = block.CodeWithVariant("rot", blockSel.HitPosition.X < 0.5 ? "west" : "east"); } break; case EnumAxis.Z: if (x < 0.3 && y < 0.3) { blockCode = block.CodeWithVariant("rot", blockSel.Face.Opposite.Code); } else if (x > y) { blockCode = block.CodeWithVariant("rot", blockSel.HitPosition.X < 0.5 ? "west" : "east"); } else { blockCode = block.CodeWithVariant("rot", blockSel.HitPosition.Y < 0.5 ? "down" : "up"); } break; } } else { if (blockSel.Face.IsVertical) { blockCode = block.CodeWithVariant("rot", blockSel.Face.Opposite.Code); } else { blockCode = block.CodeWithVariant("rot", BlockFacing.HorizontalFromAngle(byPlayer.Entity.Pos.Yaw).Code); } } } else if (rotateH || rotateV) { // Complex 4/8/16 state rotator. string h = "north"; string v = "up"; if (blockSel.Face.IsVertical) { v = blockSel.Face.Code; h = BlockFacing.HorizontalFromAngle(byPlayer.Entity.Pos.Yaw).Code; } else if (rotateV4) { if (facing == "block") { h = blockSel.Face.Opposite.Code; } else { // Default to player facing. h = BlockFacing.HorizontalFromAngle(byPlayer.Entity.Pos.Yaw).Code; } switch (blockSel.Face.Axis) { case EnumAxis.X: // Find the axis farther from the center. if (Math.Abs(blockSel.HitPosition.Z - 0.5) > Math.Abs(blockSel.HitPosition.Y - 0.5)) { v = blockSel.HitPosition.Z < 0.5 ? "left" : "right"; } else { v = blockSel.HitPosition.Y < 0.5 ? "up" : "down"; } break; case EnumAxis.Z: if (Math.Abs(blockSel.HitPosition.X - 0.5) > Math.Abs(blockSel.HitPosition.Y - 0.5)) { v = blockSel.HitPosition.X < 0.5 ? "left" : "right"; } else { v = blockSel.HitPosition.Y < 0.5 ? "up" : "down"; } break; } } else { v = blockSel.HitPosition.Y < 0.5 ? "up" : "down"; } if (rotateH && rotateV) { blockCode = block.CodeWithVariants(new string[] { "v", "rot" }, new string[] { v, h }); } else if (rotateH) { blockCode = block.CodeWithVariant("rot", h); } else if (rotateV) { blockCode = block.CodeWithVariant("rot", v); } } if (blockCode == null) { blockCode = this.block.Code; } orientedBlock = world.BlockAccessor.GetBlock(blockCode); if (orientedBlock.CanPlaceBlock(world, byPlayer, blockSel, ref failureCode)) { world.BlockAccessor.SetBlock(orientedBlock.BlockId, blockSel.Position); return(true); } return(false); }