public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel) { if (!world.TestPlayerAccessBlock(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak)) { byPlayer.InventoryManager.ActiveHotbarSlot.MarkDirty(); return(false); } Block block = world.BlockAccessor.GetBlock(blockSel.Position.AddCopy(blockSel.Face.GetOpposite())); if (block is BlockLayered) { Block nextBlock = ((BlockLayered)block).GetNextLayer(world); world.BlockAccessor.SetBlock(nextBlock.BlockId, blockSel.Position.AddCopy(blockSel.Face.GetOpposite())); return(true); } block = world.BlockAccessor.GetBlock(blockSel.Position); if (!CanLayerStay(world, blockSel.Position)) { return(false); } base.TryPlaceBlock(world, byPlayer, itemstack, blockSel); return(true); }
public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection bs) { if (!world.TestPlayerAccessBlock(byPlayer, bs.Position, EnumBlockAccessFlags.BuildOrBreak)) { byPlayer.InventoryManager.ActiveHotbarSlot.MarkDirty(); return(false); } BlockPos supportingPos = bs.Position.AddCopy(bs.Face.GetOpposite()); if (bs.Face.IsHorizontal && world.BlockAccessor.GetBlock(supportingPos).CanAttachBlockAt(world.BlockAccessor, this, bs.Position, bs.Face) && world.BlockAccessor.GetBlock(bs.Position).IsReplacableBy(this)) { Block block = world.BlockAccessor.GetBlock(CodeWithParts("wall", bs.Face.GetOpposite().Code)); world.BlockAccessor.SetBlock(block.BlockId, bs.Position); return(true); } if (world.BlockAccessor.GetBlock(bs.Position).IsReplacableBy(this)) { BlockFacing[] horVer = SuggestedHVOrientation(byPlayer, bs); AssetLocation blockCode = CodeWithParts(horVer[0].Code); Block block = world.BlockAccessor.GetBlock(blockCode); world.BlockAccessor.SetBlock(block.BlockId, bs.Position); return(true); } return(false); }
public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel) { if (!IsSuitablePosition(world, blockSel.Position)) { return(false); } if (!world.TestPlayerAccessBlock(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak)) { byPlayer.InventoryManager.ActiveHotbarSlot.MarkDirty(); return(false); } if (blockSel.Face.IsHorizontal) { if (TryAttachTo(world.BlockAccessor, blockSel.Position, blockSel.Face)) { return(true); } } Block upBlock = world.BlockAccessor.GetBlock(blockSel.Position.UpCopy()); if (upBlock is BlockVines) { BlockFacing facing = ((BlockVines)upBlock).GetOrientation(); Block block = world.BlockAccessor.GetBlock(CodeWithParts(facing.Code)); world.BlockAccessor.SetBlock(block == null ? upBlock.BlockId : block.BlockId, blockSel.Position); return(true); } return(false); }
public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel) { if (!world.TestPlayerAccessBlock(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak)) { byPlayer.InventoryManager.ActiveHotbarSlot.MarkDirty(); return(false); } BlockPos abovePos = blockSel.Position.AddCopy(0, 1, 0); IBlockAccessor ba = world.BlockAccessor; if (ba.GetBlockId(abovePos) == 0 && IsSuitablePosition(world, blockSel.Position)) { BlockFacing[] horVer = SuggestedHVOrientation(byPlayer, blockSel); string knobOrientation = GetSuggestedKnobOrientation(ba, blockSel.Position, horVer[0]); AssetLocation downBlockCode = CodeWithParts(horVer[0].Code, "down", "closed", knobOrientation); Block downBlock = ba.GetBlock(downBlockCode); AssetLocation upBlockCode = CodeWithParts(horVer[0].Code, "up", "closed", knobOrientation); Block upBlock = ba.GetBlock(upBlockCode); ba.SetBlock(downBlock.BlockId, blockSel.Position); ba.SetBlock(upBlock.BlockId, abovePos); return(true); } return(false); }
public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel, ref EnumHandling handled) { if (!world.TestPlayerAccessBlock(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak)) { byPlayer.InventoryManager.ActiveHotbarSlot.MarkDirty(); return(false); } handled = EnumHandling.PreventDefault; BlockFacing[] horVer = Block.SuggestedHVOrientation(byPlayer, blockSel); string code = "ns"; if (horVer[0].Index == 1 || horVer[0].Index == 3) { code = "we"; } Block orientedBlock = world.BlockAccessor.GetBlock(block.CodeWithParts(code)); if (orientedBlock.IsSuitablePosition(world, blockSel.Position)) { orientedBlock.DoPlaceBlock(world, blockSel.Position, blockSel.Face, itemstack); return(true); } return(false); }
public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel) { if (!world.TestPlayerAccessBlock(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak)) { byPlayer.InventoryManager.ActiveHotbarSlot.MarkDirty(); return(false); } if (!byPlayer.Entity.Controls.Sneak) { return(false); } if (IsSuitablePosition(world, blockSel.Position) && world.BlockAccessor.GetBlock(blockSel.Position.DownCopy()).SideSolid[BlockFacing.UP.Index]) { DoPlaceBlock(world, blockSel.Position, blockSel.Face, itemstack); BlockEntity be = world.BlockAccessor.GetBlockEntity(blockSel.Position); if (be is BlockEntitySmeltedContainer) { BlockEntitySmeltedContainer belmc = (BlockEntitySmeltedContainer)be; KeyValuePair <ItemStack, int> contents = GetContents(world, itemstack); contents.Key.Collectible.SetTemperature(world, contents.Key, GetTemperature(world, itemstack)); belmc.contents = contents.Key; belmc.units = contents.Value; } return(true); } return(false); }
public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel) { if (!world.TestPlayerAccessBlock(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak)) { byPlayer.InventoryManager.ActiveHotbarSlot.MarkDirty(); return(false); } if (!IsSuitablePosition(world, blockSel.Position)) { return(false); } // Prefer selected block face if (TryAttachTo(world, blockSel.Position, blockSel.Face)) { return(true); } // Otherwise attach to any possible face BlockFacing[] faces = BlockFacing.ALLFACES; for (int i = 0; i < faces.Length; i++) { if (TryAttachTo(world, blockSel.Position, faces[i])) { return(true); } } return(false); }
public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel) { if (!world.TestPlayerAccessBlock(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak)) { byPlayer.InventoryManager.ActiveHotbarSlot.MarkDirty(); return(false); } if (!IsSuitablePosition(world, blockSel.Position)) { return(false); } BlockFacing[] horVer = SuggestedHVOrientation(byPlayer, blockSel); if (blockSel.Face.IsVertical) { horVer[1] = blockSel.Face; } else { horVer[1] = blockSel.HitPosition.Y < 0.5 || !hasDownVariant ? BlockFacing.UP : BlockFacing.DOWN; } AssetLocation blockCode = CodeWithParts(horVer[1].Code, horVer[0].Code); world.BlockAccessor.SetBlock(world.BlockAccessor.GetBlock(blockCode).BlockId, blockSel.Position); return(true); }
public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel) { if (!world.TestPlayerAccessBlock(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak)) { byPlayer.InventoryManager.ActiveHotbarSlot.MarkDirty(); return(false); } if (IsSuitablePosition(world, blockSel.Position)) { BlockFacing[] horVer = SuggestedHVOrientation(byPlayer, blockSel); BlockPos secondPos = blockSel.Position.AddCopy(horVer[0]); if (!IsSuitablePosition(world, secondPos)) { return(false); } string code = horVer[0].GetOpposite().Code; Block orientedBlock = world.BlockAccessor.GetBlock(CodeWithParts("head", code)); orientedBlock.DoPlaceBlock(world, secondPos, blockSel.Face, itemstack); AssetLocation feetCode = CodeWithParts("feet", code); orientedBlock = world.BlockAccessor.GetBlock(feetCode); orientedBlock.DoPlaceBlock(world, blockSel.Position, blockSel.Face, itemstack); return(true); } return(false); }
public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel) { if (!world.TestPlayerAccessBlock(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak)) { byPlayer.InventoryManager.ActiveHotbarSlot.MarkDirty(); return(false); } if (!IsSuitablePosition(world, blockSel.Position)) { return(false); } return(TryPlaceBlockForWorldGen(world.BlockAccessor, blockSel.Position, blockSel.Face)); }
public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel) { Block block = world.BlockAccessor.GetBlock(blockSel.Position); Block blockToPlace = this; if (!world.TestPlayerAccessBlock(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak)) { byPlayer.InventoryManager.ActiveHotbarSlot.MarkDirty(); return(false); } if (block.IsLiquid()) { if (block.LiquidLevel == 7) { blockToPlace = world.GetBlock(CodeWithParts("water", LastCodePart())); } else { return(false); } if (blockToPlace == null) { blockToPlace = this; } } else { if (LastCodePart(1) != "free") { return(false); } } if (blockToPlace != null && CanPlantStay(world.BlockAccessor, blockSel.Position) && blockToPlace.IsSuitablePosition(world, blockSel.Position)) { world.BlockAccessor.SetBlock(blockToPlace.BlockId, blockSel.Position); return(true); } return(false); }
public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel) { if (!byPlayer.Entity.Controls.Sneak) { return(false); } if (!world.TestPlayerAccessBlock(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak)) { byPlayer.InventoryManager.ActiveHotbarSlot.MarkDirty(); return(false); } if (IsSuitablePosition(world, blockSel.Position) && world.BlockAccessor.GetBlock(blockSel.Position.DownCopy()).SideSolid[BlockFacing.UP.Index]) { DoPlaceBlock(world, blockSel.Position, blockSel.Face, itemstack); return(true); } return(false); }
public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel) { if (!world.TestPlayerAccessBlock(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak)) { byPlayer.InventoryManager.ActiveHotbarSlot.MarkDirty(); return(false); } if (IsSuitablePosition(world, blockSel.Position)) { BlockFacing[] horVer = SuggestedHVOrientation(byPlayer, blockSel); string face = (horVer[0] == BlockFacing.NORTH || horVer[0] == BlockFacing.SOUTH) ? "n" : "w"; string knobOrientation = GetSuggestedKnobOrientation(world.BlockAccessor, blockSel.Position, horVer[0]); AssetLocation newCode = CodeWithParts(face, "closed", knobOrientation); world.BlockAccessor.SetBlock(world.BlockAccessor.GetBlock(newCode).BlockId, blockSel.Position); return(true); } return(false); }
public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel) { if (!world.TestPlayerAccessBlock(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak)) { byPlayer.InventoryManager.ActiveHotbarSlot.MarkDirty(); return(false); } if ((blockSel.HitPosition.Y > 0.5 && blockSel.Face.IsHorizontal) || blockSel.Face == BlockFacing.DOWN) { Block block = world.BlockAccessor.GetBlock(CodeWithParts("up")); if (!IsSuitablePosition(world, blockSel.Position)) { block.DoPlaceBlock(world, blockSel.Position, blockSel.Face, itemstack); return(true); } return(false); } return(base.TryPlaceBlock(world, byPlayer, itemstack, blockSel)); }
public override bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel) { if (!world.TestPlayerAccessBlock(byPlayer, blockSel.Position, EnumBlockAccessFlags.BuildOrBreak)) { byPlayer.InventoryManager.ActiveHotbarSlot.MarkDirty(); return(false); } string orientations = GetOrientations(world, blockSel.Position); Block block = world.BlockAccessor.GetBlock(CodeWithParts(orientations)); if (block == null) { block = this; } if (block.IsSuitablePosition(world, blockSel.Position)) { world.BlockAccessor.SetBlock(block.BlockId, blockSel.Position); return(true); } return(false); }