public ItemStack TryPlaceOn(ItemStack stack, BlockEntityAnvil beAnvil) { // Already occupied anvil if (beAnvil.WorkItemStack != null) { return(null); } if (stack.Attributes.HasAttribute("voxels")) { try { beAnvil.Voxels = BlockEntityAnvil.deserializeVoxels(stack.Attributes.GetBytes("voxels")); beAnvil.SelectedRecipeId = stack.Attributes.GetInt("selectedRecipeId"); } catch (Exception) { CreateVoxelsFromIronBloom(ref beAnvil.Voxels); } } else { CreateVoxelsFromIronBloom(ref beAnvil.Voxels); } ItemStack workItemStack = stack.Clone(); workItemStack.StackSize = 1; workItemStack.Collectible.SetTemperature(api.World, workItemStack, stack.Collectible.GetTemperature(api.World, stack)); return(workItemStack.Clone()); }
public AnvilWorkItemRenderer(BlockEntityAnvil beAnvil, BlockPos pos, ICoreClientAPI capi) { this.pos = pos; this.api = capi; this.beAnvil = beAnvil; coreMod = capi.ModLoader.GetModSystem <SurvivalCoreSystem>(); }
public EnumHelveWorkableMode GetHelveWorkableMode(ItemStack stack, BlockEntityAnvil beAnvil) { if (beAnvil.SelectedRecipe.Name.Path == "plate" || beAnvil.SelectedRecipe.Name.Path == "blistersteel") { return(EnumHelveWorkableMode.TestSufficientVoxelsWorkable); } return(EnumHelveWorkableMode.NotWorkable); }
public override void OnDecalTesselation(IWorldAccessor world, MeshData decalMesh, BlockPos pos) { base.OnDecalTesselation(world, decalMesh, pos); BlockEntityAnvil bect = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityAnvil; if (bect != null) { decalMesh.Rotate(new Vec3f(0.5f, 0.5f, 0.5f), 0, bect.MeshAngle, 0); } }
public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel) { BlockEntityAnvil bea = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityAnvil; if (bea != null) { return(bea.OnPlayerInteract(world, byPlayer, blockSel)); } return(base.OnBlockInteractStart(world, byPlayer, blockSel)); }
public override Cuboidf[] GetSelectionBoxes(IBlockAccessor blockAccessor, BlockPos pos) { BlockEntityAnvil bea = blockAccessor.GetBlockEntity(pos) as BlockEntityAnvil; if (bea != null) { Cuboidf[] selectionBoxes = bea.GetSelectionBoxes(blockAccessor, pos); selectionBoxes[0] = this.SelectionBoxes[0]; return(selectionBoxes); } return(base.GetSelectionBoxes(blockAccessor, pos)); }
public ItemStack TryPlaceOn(ItemStack stack, BlockEntityAnvil beAnvil) { try { beAnvil.Voxels = BlockEntityAnvil.deserializeVoxels(stack.Attributes.GetBytes("voxels")); beAnvil.SelectedRecipeId = stack.Attributes.GetInt("selectedRecipeId"); } catch (Exception) { } return(stack.Clone()); }
public override Cuboidf[] GetSelectionBoxes(IBlockAccessor blockAccessor, BlockPos pos) { BlockEntityAnvil bea = blockAccessor.GetBlockEntity(pos) as BlockEntityAnvil; if (bea != null) { Cuboidf[] selectionBoxes = bea.GetSelectionBoxes(blockAccessor, pos); float angledeg = Math.Abs(bea.MeshAngle * GameMath.RAD2DEG); selectionBoxes[0] = angledeg == 0 || angledeg == 180 ? SelectionBoxes[0] : SelectionBoxes[1]; return(selectionBoxes); } return(base.GetSelectionBoxes(blockAccessor, pos)); }
public ItemStack TryPlaceOn(ItemStack stack, BlockEntityAnvil beAnvil) { if (!CanWork(stack)) { return(null); } Item item = api.World.GetItem(new AssetLocation("workitem-" + Variant["metal"])); if (item == null) { return(null); } ItemStack workItemStack = new ItemStack(item); workItemStack.Collectible.SetTemperature(api.World, workItemStack, stack.Collectible.GetTemperature(api.World, stack)); if (beAnvil.WorkItemStack == null) { CreateVoxelsFromIngot(api, ref beAnvil.Voxels, isBlisterSteel); } else { if (isBlisterSteel) { return(null); } IAnvilWorkable workable = beAnvil.WorkItemStack.Collectible as IAnvilWorkable; if (!workable.GetBaseMaterial(beAnvil.WorkItemStack).Equals(api.World, GetBaseMaterial(stack), GlobalConstants.IgnoredStackAttributes)) { if (api.Side == EnumAppSide.Client) { (api as ICoreClientAPI).TriggerIngameError(this, "notequal", Lang.Get("Must be the same metal to add voxels")); } return(null); } AddVoxelsFromIngot(api, ref beAnvil.Voxels); } return(workItemStack); }
public override void OnHeldAttackStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling) { if (blockSel == null) { return; } if (!(byEntity.World.BlockAccessor.GetBlock(blockSel.Position) is BlockAnvil)) { return; } BlockEntityAnvil bea = byEntity.World.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityAnvil; if (bea == null) { return; } IPlayer byPlayer = null; if (byEntity is EntityPlayer) { byPlayer = byEntity.World.PlayerByUid(((EntityPlayer)byEntity).PlayerUID); } if (byPlayer == null) { return; } bea.OnBeginUse(byPlayer, blockSel); byEntity.World.RegisterCallback((dt) => { if (byEntity.Controls.HandUse == EnumHandInteract.HeldItemAttack) { byPlayer.Entity.World.PlaySoundAt(new AssetLocation("sounds/effect/anvilhit"), byPlayer, byPlayer); } }, 464); handling = EnumHandHandling.PreventDefault; }
public override void OnHeldAttackStop(float secondsPassed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel) { if (blockSel == null) { return; } if (!(byEntity.World.BlockAccessor.GetBlock(blockSel.Position) is BlockAnvil)) { return; } BlockEntityAnvil bea = byEntity.World.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityAnvil; if (bea == null) { return; } IPlayer byPlayer = null; if (byEntity is IEntityPlayer) { byPlayer = byEntity.World.PlayerByUid(((IEntityPlayer)byEntity).PlayerUID); } if (byPlayer == null) { return; } if (bea.AvailableVoxels <= 0 && GetToolMode(slot, byPlayer, blockSel) != 5) { bea.didBeginUse--; return; } // The server side call is made using a custom network packet if (byEntity.World is IClientWorldAccessor) { bea.OnUseOver(byPlayer, blockSel.SelectionBoxIndex); } }
public ItemStack TryPlaceOn(ItemStack stack, BlockEntityAnvil beAnvil) { if (!CanWork(stack)) { return(null); } ItemStack workItemStack = new ItemStack(api.World.GetItem(new AssetLocation("workitem-" + Variant["metal"]))); workItemStack.Collectible.SetTemperature(api.World, workItemStack, stack.Collectible.GetTemperature(api.World, stack)); if (beAnvil.WorkItemStack == null) { CreateVoxels(ref beAnvil.Voxels); } else { AddVoxels(ref beAnvil.Voxels); } return(workItemStack); }
public override bool DoPlaceBlock(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ItemStack byItemStack) { bool val = base.DoPlaceBlock(world, byPlayer, blockSel, byItemStack); if (val) { BlockEntityAnvil bect = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityAnvil; 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 = byPlayer.Entity.Pos.Z - (targetPos.Z + blockSel.HitPosition.Z); float angleHor = (float)Math.Atan2(dx, dz); float deg22dot5rad = GameMath.PIHALF / 4; float roundRad = ((int)Math.Round(angleHor / deg22dot5rad)) * deg22dot5rad; bect.MeshAngle = roundRad; } } return(val); }
public override void OnHeldAttackStop(float secondsPassed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel) { if (blockSel == null || secondsPassed < 0.4f) { return; } IPlayer byPlayer = (byEntity as EntityPlayer)?.Player; BlockEntity be = byEntity.World.BlockAccessor.GetBlockEntity(blockSel.Position); if (be is BlockEntityAnvilPart bep) { bep.OnHammerHitOver(byPlayer, blockSel.HitPosition); } if (!(byEntity.World.BlockAccessor.GetBlock(blockSel.Position) is BlockAnvil)) { return; } BlockEntityAnvil bea = be as BlockEntityAnvil; if (bea == null) { return; } /*if (bea.AvailableMetalVoxels <= 0 && GetToolMode(slot, byPlayer, blockSel) != 5) * { * return; * }*/ // The server side call is made using a custom network packet if (byEntity.World is IClientWorldAccessor cWorld) { bea.OnUseOver(byPlayer, blockSel.SelectionBoxIndex); } }
public EnumHelveWorkableMode GetHelveWorkableMode(ItemStack stack, BlockEntityAnvil beAnvil) { return(EnumHelveWorkableMode.NotWorkable); }
public override void OnHeldAttackStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling) { if (blockSel == null) { return; } IPlayer byPlayer = (byEntity as EntityPlayer)?.Player; if (byPlayer == null) { return; } BlockEntity be = byEntity.World.BlockAccessor.GetBlockEntity(blockSel.Position); if (be is BlockEntityAnvilPart beap) { handling = EnumHandHandling.PreventDefault; if (!beap.TestReadyToMerge()) { return; } byEntity.World.RegisterCallback((dt) => { if (byEntity.Controls.HandUse == EnumHandInteract.HeldItemAttack) { byPlayer.Entity.World.PlaySoundAt(new AssetLocation("sounds/effect/anvilmergehit"), byPlayer, byPlayer); } }, 464); return; } if (!(byEntity.World.BlockAccessor.GetBlock(blockSel.Position) is BlockAnvil)) { return; } BlockEntityAnvil bea = be as BlockEntityAnvil; if (bea == null) { return; } bea.OnBeginUse(byPlayer, blockSel); byEntity.World.RegisterCallback((dt) => { if (byEntity.Controls.HandUse == EnumHandInteract.HeldItemAttack) { byPlayer.Entity.World.PlaySoundAt(new AssetLocation("sounds/effect/anvilhit"), byPlayer, byPlayer); } }, 440); handling = EnumHandHandling.PreventDefault; }
public static byte[,,] GetVoxels(ItemStack workitemStack) { return(BlockEntityAnvil.deserializeVoxels(workitemStack.Attributes.GetBytes("voxels"))); }
public override void OnLoaded(ICoreAPI api) { base.OnLoaded(api); if (api.Side != EnumAppSide.Client) { return; } ICoreClientAPI capi = api as ICoreClientAPI; Dictionary <string, MetalPropertyVariant> metalsByCode = new Dictionary <string, MetalPropertyVariant>(); MetalProperty metals = api.Assets.TryGet("worldproperties/block/metal.json").ToObject <MetalProperty>(); for (int i = 0; i < metals.Variants.Length; i++) { // Metals currently don't have a domain metalsByCode[metals.Variants[i].Code.Path] = metals.Variants[i]; } string metalType = LastCodePart(); int ownMetalTier = 0; if (metalsByCode.ContainsKey(metalType)) { ownMetalTier = metalsByCode[metalType].Tier; } interactions = ObjectCacheUtil.GetOrCreate(api, "anvilBlockInteractions" + ownMetalTier, () => { List <ItemStack> workableStacklist = new List <ItemStack>(); List <ItemStack> hammerStacklist = new List <ItemStack>(); foreach (Item item in api.World.Items) { if (item.Code == null) { continue; } bool viableTier = metalsByCode.ContainsKey(metalType) && metalsByCode[metalType].Tier <= ownMetalTier + 1; if (item is ItemIngot && viableTier) { workableStacklist.Add(new ItemStack(item)); } if (item is ItemHammer) { hammerStacklist.Add(new ItemStack(item)); } } return(new WorldInteraction[] { new WorldInteraction() { ActionLangCode = "blockhelp-anvil-takeworkable", HotKeyCode = null, MouseButton = EnumMouseButton.Right, ShouldApply = (wi, bs, es) => { BlockEntityAnvil bea = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityAnvil; return bea?.WorkItemStack != null; } }, new WorldInteraction() { ActionLangCode = "blockhelp-anvil-placeworkable", HotKeyCode = "sneak", MouseButton = EnumMouseButton.Right, Itemstacks = workableStacklist.ToArray(), GetMatchingStacks = (wi, bs, es) => { BlockEntityAnvil bea = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityAnvil; return bea?.WorkItemStack == null ? wi.Itemstacks : null; } }, new WorldInteraction() { ActionLangCode = "blockhelp-anvil-smith", MouseButton = EnumMouseButton.Left, Itemstacks = hammerStacklist.ToArray(), GetMatchingStacks = (wi, bs, es) => { BlockEntityAnvil bea = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityAnvil; return bea?.WorkItemStack == null ? null : wi.Itemstacks; } }, new WorldInteraction() { ActionLangCode = "blockhelp-anvil-rotateworkitem", MouseButton = EnumMouseButton.Right, Itemstacks = hammerStacklist.ToArray(), GetMatchingStacks = (wi, bs, es) => { BlockEntityAnvil bea = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityAnvil; return bea?.WorkItemStack == null ? null : wi.Itemstacks; } }, new WorldInteraction() { ActionLangCode = "blockhelp-selecttoolmode", HotKeyCode = "toolmodeselect", MouseButton = EnumMouseButton.None, Itemstacks = hammerStacklist.ToArray(), GetMatchingStacks = (wi, bs, es) => { BlockEntityAnvil bea = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityAnvil; return bea?.WorkItemStack == null ? null : wi.Itemstacks; } }, new WorldInteraction() { ActionLangCode = "blockhelp-anvil-addvoxels", HotKeyCode = "sneak", MouseButton = EnumMouseButton.Right, Itemstacks = workableStacklist.ToArray(), GetMatchingStacks = (wi, bs, es) => { BlockEntityAnvil bea = api.World.BlockAccessor.GetBlockEntity(bs.Position) as BlockEntityAnvil; return bea?.WorkItemStack == null ? null : new ItemStack[] { (bea.WorkItemStack.Collectible as IAnvilWorkable).GetBaseMaterial(bea.WorkItemStack) }; } } }); }); }