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); }
public override void FromTreeAttributes(ITreeAttribute tree, IWorldAccessor worldForResolving) { base.FromTreeAttributes(tree, worldForResolving); }
public override ItemStack[] GetDrops(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, float dropQuantityMultiplier = 1f) { // Handled by BlockEntityItemPile return(new ItemStack[0]); }
public static void PlaySoundAt(this IWorldAccessor world, AssetLocation loc, BlockPos Pos) => world.PlaySoundAt(loc, Pos.X, Pos.Y, Pos.Z);
public static Block GetBlock(this BlockPos Pos, IWorldAccessor world) { return(world.BlockAccessor.GetBlock(Pos)); }
public virtual float GetContainingTransitionModifierPlaced(IWorldAccessor world, BlockPos pos, EnumTransitionType transType) { return(1); }
private bool IsLantern(IWorldAccessor world, BlockPos blockPos) { return(((AssetLocation)((CollectibleObject)world.BlockAccessor.GetBlock(blockPos)).Code).Path.Contains("lantern")); }
public override ItemStack OnPickBlock(IWorldAccessor world, BlockPos pos) { Block block = world.BlockAccessor.GetBlock(CodeWithParts("ew")); return(new ItemStack(block)); }
private bool IsFenceGateAt(IWorldAccessor world, BlockPos blockPos) { return(world.BlockAccessor.GetBlock(blockPos).Code.Path.Contains("fencegate")); }
public override void FromTreeAtributes(ITreeAttribute tree, IWorldAccessor worldAccessForResolve) { base.FromTreeAtributes(tree, worldAccessForResolve); timer = tree.GetInt("timer"); }
public override ItemStack[] GetDrops(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, float dropQuantityMultiplier = 1f) { Block block = world.BlockAccessor.GetBlock(CodeWithParts("ew")); return(new ItemStack[] { new ItemStack(block) }); }
public override void OnBlockRemoved(IWorldAccessor world, BlockPos pos) { base.OnBlockRemoved(world, pos); }
public override bool HasMechPowerConnectorAt(IWorldAccessor world, BlockPos pos, BlockFacing face) { return(face == powerOutFacing || face == powerOutFacing.Opposite); }
public override void DidConnectAt(IWorldAccessor world, BlockPos pos, BlockFacing face) { return; }
public virtual float GetContainingTransitionModifierContained(IWorldAccessor world, ItemSlot inSlot, EnumTransitionType transType) { return(1); }
public override BlockDropItemStack[] GetDropsForHandbook(IWorldAccessor world, BlockPos pos, IPlayer byPlayer) { return(GetHandbookDropsFromBreakDrops(world, pos, byPlayer)); }
public override void GetHeldItemInfo(ItemSlot inSlot, StringBuilder dsc, IWorldAccessor world, bool withDebugInfo) { base.GetHeldItemInfo(inSlot, dsc, world, withDebugInfo); }
public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel) { base.OnBlockInteractStart(world, byPlayer, blockSel); (blockSel.BlockEntity(world) as BlockEntityDryingStation)?.OnInteract(world, byPlayer, blockSel); return(true); }
public virtual ItemStack[] GetNonEmptyContents(IWorldAccessor world, ItemStack itemstack) { return(GetContents(world, itemstack)?.Where(stack => stack != null).ToArray()); }
public override WorldInteraction[] GetPlacedBlockInteractionHelp(IWorldAccessor world, BlockSelection selection, IPlayer forPlayer) { return(interactions.Append(base.GetPlacedBlockInteractionHelp(world, selection, forPlayer))); }
public override ItemStack OnPickBlock(IWorldAccessor world, BlockPos pos, ref EnumHandling handling) { handling = EnumHandling.PreventDefault; return(new ItemStack(world.BlockAccessor.GetBlock(block.CodeWithParts("e")))); }
public override BlockDropItemStack[] GetDropsForHandbook(IWorldAccessor world, BlockPos pos, IPlayer byPlayer) { return(new BlockDropItemStack[0]); }
public static BlockEntity BlockEntity(this BlockSelection sel, IWorldAccessor world) { return(sel.Position.BlockEntity(world)); }
public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel) { ItemSlot hotbarSlot = byPlayer.InventoryManager.ActiveHotbarSlot; if (!hotbarSlot.Empty && hotbarSlot.Itemstack.Collectible.Attributes?.IsTrue("handleLiquidContainerInteract") == true) { EnumHandHandling handling = EnumHandHandling.NotHandled; hotbarSlot.Itemstack.Collectible.OnHeldInteractStart(hotbarSlot, byPlayer.Entity, blockSel, null, true, ref handling); if (handling == EnumHandHandling.PreventDefault || handling == EnumHandHandling.PreventDefaultAction) { return(true); } } if (hotbarSlot.Empty || !(hotbarSlot.Itemstack.Collectible is ILiquidInterface)) { return(base.OnBlockInteractStart(world, byPlayer, blockSel)); } CollectibleObject obj = hotbarSlot.Itemstack.Collectible; bool singleTake = byPlayer.WorldData.EntityControls.Sneak; bool singlePut = byPlayer.WorldData.EntityControls.Sprint; if (obj is ILiquidSource objLso && !singleTake) { var contentStackToMove = objLso.GetContent(hotbarSlot.Itemstack); float litres = singlePut ? Props.TransferSizeLitres : Props.CapacityLitres; int moved = TryPutLiquid(blockSel.Position, contentStackToMove, litres); if (moved > 0) { objLso.TryTakeContent(hotbarSlot.Itemstack, moved); DoLiquidMovedEffects(byPlayer, contentStackToMove, moved, EnumLiquidDirection.Pour); return(true); } } if (obj is ILiquidSink objLsi && !singlePut) { ItemStack owncontentStack = GetContent(blockSel.Position); if (owncontentStack == null) { return(base.OnBlockInteractStart(world, byPlayer, blockSel)); } var liquidStackForParticles = owncontentStack.Clone(); float litres = singleTake ? Props.TransferSizeLitres : Props.CapacityLitres; int moved; if (hotbarSlot.Itemstack.StackSize == 1) { moved = objLsi.TryPutLiquid(hotbarSlot.Itemstack, owncontentStack, litres); } else { ItemStack containerStack = hotbarSlot.Itemstack.Clone(); containerStack.StackSize = 1; moved = objLsi.TryPutLiquid(containerStack, owncontentStack, litres); if (moved > 0) { hotbarSlot.TakeOut(1); if (!byPlayer.InventoryManager.TryGiveItemstack(containerStack, true)) { api.World.SpawnItemEntity(containerStack, byPlayer.Entity.SidedPos.XYZ); } } } if (moved > 0) { TryTakeContent(blockSel.Position, moved); DoLiquidMovedEffects(byPlayer, liquidStackForParticles, moved, EnumLiquidDirection.Fill); return(true); } } return(base.OnBlockInteractStart(world, byPlayer, blockSel)); }
public static void PlaySoundAtWithDelay(this IWorldAccessor world, AssetLocation location, BlockPos Pos, int delay) { world.RegisterCallback(dt => world.PlaySoundAt(location, Pos.X, Pos.Y, Pos.Z), delay); }
public override void GetHeldItemInfo(ItemSlot inSlot, StringBuilder dsc, IWorldAccessor world, bool withDebugInfo) { base.GetHeldItemInfo(inSlot, dsc, world, withDebugInfo); ItemStack content = GetContent(inSlot.Itemstack); if (content != null) { content.Collectible.GetHeldItemInfo(inSlot, dsc, world, withDebugInfo); ITreeAttribute potion = (ITreeAttribute)content.Attributes; if (potion != null) { try { essencesDic.Clear(); foreach (var essence in maxEssenceDic.Keys.ToList()) { if (potion.TryGetFloat("potion" + essence) != null) { if (!essencesDic.ContainsKey(essence)) { essencesDic.Add(essence, 0); } essencesDic[essence] = potion.GetFloat("potion" + essence); } } //api.Logger.Debug("potion {0}, {1}, {2}", potionId, duration); } catch (Exception e) { api.World.Logger.Error("Failed loading potion effects for potion {0}. Will ignore. Exception: {1}", Code, e); duration = 0; } } if (essencesDic != null) { dsc.AppendLine(Lang.Get("\n")); float value; if (essencesDic.TryGetValue("rangedWeaponsAcc", out value)) { dsc.AppendLine(Lang.Get("When potion is used: {0}% ranged accuracy", value * 100)); } if (essencesDic.TryGetValue("animalLootDropRate", out value)) { dsc.AppendLine(Lang.Get("When potion is used: {0}% more animal loot", value * 100)); } if (essencesDic.TryGetValue("animalHarvestingTime", out value)) { dsc.AppendLine(Lang.Get("When potion is used: {0}% faster animal harvest", value * 100)); } if (essencesDic.TryGetValue("animalSeekingRange", out value)) { dsc.AppendLine(Lang.Get("When potion is used: {0}% animal seek range", value * 100)); } if (essencesDic.TryGetValue("maxhealthExtraPoints", out value)) { dsc.AppendLine(Lang.Get("When potion is used: {0} extra max health points", value)); } if (essencesDic.TryGetValue("forageDropRate", out value)) { dsc.AppendLine(Lang.Get("When potion is used: {0}% more forage amount", value * 100)); } if (essencesDic.TryGetValue("healingeffectivness", out value)) { dsc.AppendLine(Lang.Get("When potion is used: {0}% healing effectiveness", value * 100)); } if (essencesDic.TryGetValue("hungerrate", out value)) { dsc.AppendLine(Lang.Get("When potion is used: {0}% hunger rate", value * 100)); } if (essencesDic.TryGetValue("meleeWeaponsDamage", out value)) { dsc.AppendLine(Lang.Get("When potion is used: {0}% melee damage", value * 100)); } if (essencesDic.TryGetValue("mechanicalsDamage", out value)) { dsc.AppendLine(Lang.Get("When potion is used: {0}% mechanincal damage (not sure if works)", value * 100)); } if (essencesDic.TryGetValue("miningSpeedMul", out value)) { dsc.AppendLine(Lang.Get("When potion is used: {0}% mining speed", value * 100)); } if (essencesDic.TryGetValue("oreDropRate", out value)) { dsc.AppendLine(Lang.Get("When potion is used: {0}% more ore", value * 100)); } if (essencesDic.TryGetValue("rangedWeaponsDamage", out value)) { dsc.AppendLine(Lang.Get("When potion is used: {0}% ranged damage", value * 100)); } if (essencesDic.TryGetValue("rangedWeaponsSpeed", out value)) { dsc.AppendLine(Lang.Get("When potion is used: {0}% ranged speed", value * 100)); } if (essencesDic.TryGetValue("rustyGearDropRate", out value)) { dsc.AppendLine(Lang.Get("When potion is used: {0}% more gears from metal piles", value * 100)); } if (essencesDic.TryGetValue("walkspeed", out value)) { dsc.AppendLine(Lang.Get("When potion is used: {0}% walk speed", value * 100)); } if (essencesDic.TryGetValue("vesselContentsDropRate", out value)) { dsc.AppendLine(Lang.Get("When potion is used: {0}% more vessel contents", value * 100)); } if (essencesDic.TryGetValue("wildCropDropRate", out value)) { dsc.AppendLine(Lang.Get("When potion is used: {0}% wild crop", value * 100)); } if (essencesDic.TryGetValue("wholeVesselLootChance", out value)) { dsc.AppendLine(Lang.Get("When potion is used: {0}% chance to get whole vessel", value * 100)); } if (essencesDic.TryGetValue("glow", out value)) { dsc.AppendLine(Lang.Get("When potion is used: player starts to glow")); } if (essencesDic.TryGetValue("recall", out value)) { dsc.AppendLine(Lang.Get("When potion is used: player teleports home")); } if (essencesDic.TryGetValue("duration", out value)) { dsc.Append(Lang.Get(" and lasts for {0} seconds", value)); } if (essencesDic.TryGetValue("health", out value)) { dsc.Append(Lang.Get(" and lasts for {0} seconds", value)); } } } }
public override double ExplosionDropChance(IWorldAccessor world, BlockPos pos, EnumBlastType blastType) { return(0.2); }
public override bool DoParticalSelection(IWorldAccessor world, BlockPos pos) { return(true); }
public override double GetBlastResistance(IWorldAccessor world, BlockPos pos, Vec3f blastDirectionVector, EnumBlastType blastType) { return(0.5); }
public override WorldInteraction[] GetPlacedBlockInteractionHelp(IWorldAccessor world, BlockSelection selection, IPlayer forPlayer) { return((selection.SelectionBoxIndex == 0 ? interactionsLeft : interactionsRight).Append(base.GetPlacedBlockInteractionHelp(world, selection, forPlayer))); }