public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel) { BEReedPresser besc = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BEReedPresser; if (besc != null) { bool placed = besc.Interact(byPlayer); (byPlayer as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract); return(true); } return(base.OnBlockInteractStart(world, byPlayer, blockSel)); }
public override void OnNeighbourBlockChange(IWorldAccessor world, BlockPos pos, BlockPos neibpos) { BEReedPresser besc = world.BlockAccessor.GetBlockEntity(pos) as BEReedPresser; if (besc != null) { besc.HandleNeighborUpdate(world, pos, neibpos); } else { base.OnNeighbourBlockChange(world, pos, neibpos); } }
public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ref EnumHandling handling) { handling = EnumHandling.PassThrough; if (!(block.Code.Path.Contains("andesite-rock") || block.Code.Path.Contains("granite-rock"))) { world.Logger.Debug(String.Format("{0} failed the check for rock type", block.Code.Path)); return(false); } if (blockSel.Face != BlockFacing.UP) { world.Logger.Debug(String.Format("{0} was not the correct face, expected {1}", blockSel.Face, BlockFacing.UP)); return(false); } bool sneaking = byPlayer.WorldData.EntityControls.Sneak; ItemSlot slot = byPlayer.InventoryManager.ActiveHotbarSlot; if (slot.Itemstack == null) { return(false); } if (sneaking && slot.Itemstack.Class == EnumItemClass.Item && slot.Itemstack.Item.Code.Path.Contains("soakedreeds")) { ItemStack stk = slot.Itemstack; if (stk.StackSize >= 10) { String rockType = block.Code.Path.Contains("andesite-rock") ? "andesite" : block.Code.Path.Contains("granite-rock") ? "granite" : null; if (rockType == null) { world.Logger.Error("how'd we get here?"); return(false); } Block target = world.GetBlock(new AssetLocation(String.Format("books:reedpresser-{0}", rockType))); if (target == null) { world.Logger.Error("Failed failed to locate block type for reedpresser"); return(false); } world.BlockAccessor.SetBlock(target.BlockId, blockSel.Position); // we're doing major overhauls to this block, don't let weirdness happen by subsequent events firing on the wrong block type. handling = EnumHandling.PreventSubsequent; Block inst = world.BlockAccessor.GetBlock(blockSel.Position); if (inst.Id == 0 || inst.BlockId != target.BlockId) { world.Logger.Error("Failed to place ReedPresser block in world", target, blockSel.Position); return(false); } BEReedPresser be = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BEReedPresser; if (be == null) { world.Logger.Error("Converted block at position to ReedPresser, but no BEReedPresser created in tandem", target, blockSel.Position); return(false); } be.Inventory[0].Itemstack = stk.Clone(); slot.Itemstack = null; return(true); } else { (world.Api as ICoreClientAPI)?.TriggerIngameError( this, "invalid-item-count", Lang.Get("Not enough reeds to create a sheet of paper for pressing.") ); return(false); } } if (slot.Itemstack.Class == EnumItemClass.Item) { world.Logger.Debug(String.Format("Tried to use the wrong item type for creating a presser {0}", slot.Itemstack.Item.Code.Path)); } return(false); }