From ce989e8761fcc79700ba65be02687b229d71bca6 Mon Sep 17 00:00:00 2001 From: DArkHekRoMaNT Date: Mon, 11 Jan 2021 23:07:20 +0300 Subject: [PATCH] v1.4.0 --- .gitignore | 3 +- .vscode/launch.json | 4 +- .../teleportermod/itemtypes/mirror.json | 20 +- resources/assets/teleportermod/lang/en.json | 11 +- resources/assets/teleportermod/lang/ru.json | 7 +- .../{mirror-frame.json => framemold.json} | 0 .../recipes/grid/mirror-magic.json | 11 -- .../recipes/grid/mirrormagic.json | 24 +++ ...r-magic-wood-frame.json => woodframe.json} | 0 .../{mirror-frame.json => mirrorframe.json} | 4 +- resources/modinfo.json | 2 +- src/Item/ItemMirror.cs | 171 ++++++++++-------- 12 files changed, 155 insertions(+), 102 deletions(-) rename resources/assets/teleportermod/recipes/clayforming/{mirror-frame.json => framemold.json} (100%) delete mode 100644 resources/assets/teleportermod/recipes/grid/mirror-magic.json create mode 100644 resources/assets/teleportermod/recipes/grid/mirrormagic.json rename resources/assets/teleportermod/recipes/grid/{mirror-magic-wood-frame.json => woodframe.json} (100%) rename resources/assets/teleportermod/recipes/smithing/{mirror-frame.json => mirrorframe.json} (88%) diff --git a/.gitignore b/.gitignore index 41e0d19..28a4927 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ /bin /obj /mods -/releases \ No newline at end of file +/releases +/.history \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index d2ec4fc..c78d2af 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -18,7 +18,9 @@ "${workspaceFolder}/mods" ], "console": "internalConsole", - "internalConsoleOptions": "openOnSessionStart" + "internalConsoleOptions": "openOnSessionStart", + "justMyCode": false, + "requireExactSource": false }, { "name": "Launch Client (Mono)", diff --git a/resources/assets/teleportermod/itemtypes/mirror.json b/resources/assets/teleportermod/itemtypes/mirror.json index 59d19d5..342546b 100644 --- a/resources/assets/teleportermod/itemtypes/mirror.json +++ b/resources/assets/teleportermod/itemtypes/mirror.json @@ -38,16 +38,16 @@ }, "maxstacksize": 1, "durabilityByType": { - "*-wood": 1, - "*-copper": 2, - "*-tinbronze": 3, - "*-gold": 3, - "*-silver": 3, - "*-bismuthbronze": 3, - "*-blackbronze": 5, - "*-iron": 8, - "*-meteoriciron": 10, - "*-steel": 15 + "*-wood": 1000, + "*-copper": 2000, + "*-tinbronze": 4000, + "*-gold": 4000, + "*-silver": 4000, + "*-bismuthbronze": 4000, + "*-blackbronze": 5000, + "*-iron": 8000, + "*-meteoriciron": 10000, + "*-steel": 15000 }, "attributes": { "handbook": { diff --git a/resources/assets/teleportermod/lang/en.json b/resources/assets/teleportermod/lang/en.json index 57e4fe7..f10ef41 100644 --- a/resources/assets/teleportermod/lang/en.json +++ b/resources/assets/teleportermod/lang/en.json @@ -32,12 +32,17 @@ "item-mirror-frame-meteoriciron": "Mirror Frame (Meteoric Iron)", "item-mirror-frame-steel": "Mirror Frame (Steel)", - "block-toolmold-raw-mirror": "Mirror mold (Raw)", - "block-toolmold-burned-mirror": "Mirror mold (Fired)", + "block-toolmold-raw-mirror": "Raw mirror mold", + "block-toolmold-burned-mirror": "Mirror mold", "heldhelp-savepoint": "Save point", "heldhelp-teleport": "Return", "heldhelp-teleport-to-player": "Teleport to player", - "game:tabname-teleportermod": "Temporal Mirror" + "game:tabname-teleportermod": "Temporal Mirror", + + "Teleported to {0}": "Teleported to {0}", + "Saved point: {0}, {1}, {2}": "Saved point: {0}, {1}, {2}", + "Return point saved at {0}": "Return point saved at {0}", + "Distance: {0} m": "Distance: {0} m" } diff --git a/resources/assets/teleportermod/lang/ru.json b/resources/assets/teleportermod/lang/ru.json index 0ec8377..57cd310 100644 --- a/resources/assets/teleportermod/lang/ru.json +++ b/resources/assets/teleportermod/lang/ru.json @@ -37,5 +37,10 @@ "heldhelp-savepoint": "Сохранить точку", "heldhelp-teleport": "Вернуться", - "heldhelp-teleport-to-player": "Телепортироваться к игроку" + "heldhelp-teleport-to-player": "Телепортироваться к игроку", + + "Teleported to {0}": "Телепортирован в {0}", + "Saved point: {0}, {1}, {2}": "Сохраненная точка: {0}, {1}, {2}", + "Return point saved at {0}": "Точка возврата сохранена на {0}", + "Distance: {0} m": "Расстояние: {0} м" } diff --git a/resources/assets/teleportermod/recipes/clayforming/mirror-frame.json b/resources/assets/teleportermod/recipes/clayforming/framemold.json similarity index 100% rename from resources/assets/teleportermod/recipes/clayforming/mirror-frame.json rename to resources/assets/teleportermod/recipes/clayforming/framemold.json diff --git a/resources/assets/teleportermod/recipes/grid/mirror-magic.json b/resources/assets/teleportermod/recipes/grid/mirror-magic.json deleted file mode 100644 index 2b8df41..0000000 --- a/resources/assets/teleportermod/recipes/grid/mirror-magic.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "ingredientPattern": "G,S", - "ingredients": { - "S": { "type": "item", "code": "mirror-frame-*", "name": "type" }, - "G": { "type": "item", "code": "game:gear-temporal" } - }, - "width": 1, - "height": 2, - "shapeless": true, - "output": { "type": "item", "code": "mirror-magic-{type}" } -} diff --git a/resources/assets/teleportermod/recipes/grid/mirrormagic.json b/resources/assets/teleportermod/recipes/grid/mirrormagic.json new file mode 100644 index 0000000..db2cdca --- /dev/null +++ b/resources/assets/teleportermod/recipes/grid/mirrormagic.json @@ -0,0 +1,24 @@ +[ + { + "ingredientPattern": "G,S", + "ingredients": { + "S": { "type": "item", "code": "mirror-frame-*", "name": "type" }, + "G": { "type": "item", "code": "game:gear-temporal" } + }, + "width": 1, + "height": 2, + "shapeless": true, + "output": { "type": "item", "code": "mirror-magic-{type}" } + }, + { + "ingredientPattern": "G,S", + "ingredients": { + "S": { "type": "item", "code": "mirror-magic-*", "name": "type" }, + "G": { "type": "item", "code": "game:gear-temporal" } + }, + "width": 1, + "height": 2, + "shapeless": true, + "output": { "type": "item", "code": "mirror-magic-{type}" } + } +] diff --git a/resources/assets/teleportermod/recipes/grid/mirror-magic-wood-frame.json b/resources/assets/teleportermod/recipes/grid/woodframe.json similarity index 100% rename from resources/assets/teleportermod/recipes/grid/mirror-magic-wood-frame.json rename to resources/assets/teleportermod/recipes/grid/woodframe.json diff --git a/resources/assets/teleportermod/recipes/smithing/mirror-frame.json b/resources/assets/teleportermod/recipes/smithing/mirrorframe.json similarity index 88% rename from resources/assets/teleportermod/recipes/smithing/mirror-frame.json rename to resources/assets/teleportermod/recipes/smithing/mirrorframe.json index 761ea67..7d99eaf 100644 --- a/resources/assets/teleportermod/recipes/smithing/mirror-frame.json +++ b/resources/assets/teleportermod/recipes/smithing/mirrorframe.json @@ -10,7 +10,9 @@ "blackbronze", "silver", "gold", - "iron" + "iron", + "meteoriciron", + "steel" ] }, "pattern": [["____#####", "#####___#", "____#####"]], diff --git a/resources/modinfo.json b/resources/modinfo.json index 5e987e5..f1f8d60 100644 --- a/resources/modinfo.json +++ b/resources/modinfo.json @@ -4,7 +4,7 @@ "name": "Temporal Mirror", "author": "DArkHekRoMaNT", "description": "Add mirror for teleportation", - "version": "1.3.1", + "version": "1.4.0", "dependency": { "game": "1.14.0" }, diff --git a/src/Item/ItemMirror.cs b/src/Item/ItemMirror.cs index 038610a..5ffa7a3 100644 --- a/src/Item/ItemMirror.cs +++ b/src/Item/ItemMirror.cs @@ -10,22 +10,25 @@ namespace TeleporterMod { public class ItemMirror : Item { - protected const int secondsNeed = 5; - protected SimpleParticleProperties particles = new SimpleParticleProperties( - 1, // min quantity - 1, // add quantity - ColorUtil.WhiteAhsl, // color - new Vec3d(), // min pos - new Vec3d(), // add pos - new Vec3f(-0.25f, 0.1f, -0.25f), // min velocity - new Vec3f(0.25f, 0.1f, 0.25f), // add velocity - 0.2f, // life length - 0.075f, // gravity effect - 0.1f, // min size - 0.1f, // max size - EnumParticleModel.Cube // model + SimpleParticleProperties particles = new SimpleParticleProperties( + minQuantity: 1, + maxQuantity: 1, + color: ColorUtil.WhiteAhsl, + minPos: new Vec3d(), + maxPos: new Vec3d(), + minVelocity: new Vec3f(-0.25f, 0.1f, -0.25f), + maxVelocity: new Vec3f(0.25f, 0.1f, 0.25f), + lifeLength: 0.2f, + gravityEffect: 0.075f, + minSize: 0.1f, + maxSize: 0.1f, + model: EnumParticleModel.Cube ); - protected ILoadedSound sound; + ILoadedSound sound; + + const int secondsNeed = 5; + bool teleported; + BlockPos beforeTpPos; public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling) { @@ -34,50 +37,51 @@ public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, Bl base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handling); return; } + if (slot.Itemstack.Item.Variant["type"] == "magic") { + if (blockSel != null && byEntity.Controls.Sneak) { - BlockPos pos = blockSel.Position.AddCopy(1, 0, 1); - slot.Itemstack.Attributes.SetInt("point.x", pos.X); - slot.Itemstack.Attributes.SetInt("point.y", pos.Y); - slot.Itemstack.Attributes.SetInt("point.z", pos.Z); + slot.Itemstack.Attributes.SetInt("x", blockSel.Position.X); + slot.Itemstack.Attributes.SetInt("y", blockSel.Position.Y); + slot.Itemstack.Attributes.SetInt("z", blockSel.Position.Z); - SendMessage("Return point saved at " + HumanCoord(pos), byEntity); + SendMessage(Lang.Get("Return point saved at {0}", MapPos(blockSel.Position)), byEntity); handling = EnumHandHandling.Handled; return; } - if (!slot.Itemstack.Attributes.HasAttribute("point.x")) return; - } - if (byEntity.World is IClientWorldAccessor) - { - IClientWorldAccessor world = byEntity.World as IClientWorldAccessor; - sound = world.LoadSound(new SoundParams() + if (!slot.Itemstack.Attributes.HasAttribute("x")) return; + + if (byEntity.World is IClientWorldAccessor world) { - Location = new AssetLocation("teleportermod:sounds/teleport.ogg"), - ShouldLoop = false, - Position = byEntity.Pos.XYZ.ToVec3f(), - DisposeOnFinish = true, - Volume = 1f, - Pitch = 0.7f - }); - sound?.Start(); - } + sound = world.LoadSound(new SoundParams() + { + Location = new AssetLocation("teleportermod:sounds/teleport.ogg"), + ShouldLoop = false, + Position = byEntity.Pos.XYZ.ToVec3f(), + DisposeOnFinish = true, + Volume = 1f, + Pitch = 0.7f + }); + sound?.Start(); + } - handling = EnumHandHandling.PreventDefault; + teleported = false; + handling = EnumHandHandling.PreventDefault; + } } public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel) { - if (secondsUsed >= secondsNeed) return false; - if (api.Side == EnumAppSide.Client) { ModelTransform tf = new ModelTransform(); tf.EnsureDefaultValues(); - tf.Translation.Set(-secondsUsed * 0.05f, secondsUsed * 0.025f, secondsUsed * 0.05f); + float trans = Math.Min(secondsUsed, secondsNeed); + tf.Translation.Set(-trans * 0.05f, trans * 0.025f, trans * 0.05f); byEntity.Controls.UsingHeldItemTransformAfter = tf; if (secondsUsed > 0.5) @@ -97,35 +101,56 @@ public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, Entity byEntity.World.SpawnParticles(particles); } } - return true; - } - public override void OnHeldInteractStop(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel) - { - sound?.Stop(); - if (secondsUsed >= secondsNeed) + if (!teleported && secondsUsed > secondsNeed) { if (slot.Itemstack.Item.Variant["type"] == "magic") { - BlockPos tpPos = new BlockPos().Set( - slot.Itemstack.Attributes.GetInt("point.x"), - slot.Itemstack.Attributes.GetInt("point.y") + 1, - slot.Itemstack.Attributes.GetInt("point.z") + + Vec3d tpPos = new Vec3d().Set( + slot.Itemstack.Attributes.GetInt("x") + 0.5f, + slot.Itemstack.Attributes.GetInt("y") + 1, + slot.Itemstack.Attributes.GetInt("z") + 0.5f ); - api.World.Logger.Notification("Teleported to " + HumanCoord(tpPos)); - SendMessage("Teleported to " + HumanCoord(tpPos), byEntity); - byEntity.TeleportTo(tpPos.AddCopy(0, 1, 0)); - // TODO: Need check teleportation complete - if ((byEntity as EntityPlayer)?.Player.WorldData.CurrentGameMode != EnumGameMode.Creative) + beforeTpPos = byEntity.Pos.AsBlockPos; + + if ((int)beforeTpPos.DistanceTo(tpPos.AsBlockPos) >= slot.Itemstack.Collectible.Durability) { - slot.Itemstack.Collectible.DamageItem(byEntity.World, byEntity, slot); + return false; + } + + if (!byEntity.Teleporting) + { + byEntity.TeleportToDouble(tpPos.X, tpPos.Y, tpPos.Z, () => teleported = true); + api.World.Logger.Notification("Teleported to {0}", tpPos); + SendMessage(Lang.Get("Teleported to {0}", MapPos(tpPos.AsBlockPos)), byEntity); } } - else - { - //TODO: Wormhole, open gui and select player - } + } + + return !teleported; + } + + public override bool OnHeldInteractCancel(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, EnumItemUseCancelReason cancelReason) + { + bool flag = base.OnHeldInteractCancel(secondsUsed, slot, byEntity, blockSel, entitySel, cancelReason); + + if (flag) + { + sound?.Stop(); + } + + return flag; + } + + public override void OnHeldInteractStop(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel) + { + sound?.Stop(); + + if (teleported && (byEntity as EntityPlayer)?.Player.WorldData.CurrentGameMode != EnumGameMode.Creative) + { + slot.Itemstack.Collectible.DamageItem(byEntity.World, byEntity, slot, (int)beforeTpPos.DistanceTo(byEntity.Pos.AsBlockPos)); } } @@ -165,26 +190,27 @@ public override WorldInteraction[] GetHeldInteractionHelp(ItemSlot inSlot) public override void GetHeldItemInfo(ItemSlot inSlot, StringBuilder dsc, IWorldAccessor world, bool withDebugInfo) { base.GetHeldItemInfo(inSlot, dsc, world, withDebugInfo); - if (inSlot.Itemstack.Attributes.HasAttribute("point.x")) + if (inSlot.Itemstack.Attributes.HasAttribute("x")) { - BlockPos tpPos = HumanCoord(new BlockPos().Set( - inSlot.Itemstack.Attributes.GetInt("point.x"), - inSlot.Itemstack.Attributes.GetInt("point.y") + 1, - inSlot.Itemstack.Attributes.GetInt("point.z") - )); - dsc.AppendLine("Saved point: " + tpPos.X + ", " + tpPos.Y + ", " + tpPos.Z); + BlockPos tpPos = new BlockPos().Set( + inSlot.Itemstack.Attributes.GetInt("x"), + inSlot.Itemstack.Attributes.GetInt("y") + 1, + inSlot.Itemstack.Attributes.GetInt("z") + ); + BlockPos mapTpPos = MapPos(tpPos); + dsc.AppendLine(Lang.Get("Saved point: {0}, {1}, {2}", mapTpPos.X, mapTpPos.Y, mapTpPos.Z)); + dsc.AppendLine(Lang.Get("Distance: {0} m", (int)(api as ICoreClientAPI)?.World?.Player?.Entity?.Pos.AsBlockPos.DistanceTo(tpPos))); } } - protected BlockPos HumanCoord(BlockPos trueCoord) + private BlockPos MapPos(BlockPos pos) { - int x = (int)(trueCoord.X - api.World.DefaultSpawnPosition.XYZ.Z); - int y = trueCoord.Y; - int z = (int)(trueCoord.Z - api.World.DefaultSpawnPosition.XYZ.Z); - return new BlockPos(x, y, z); + int x = pos.X - api.World.DefaultSpawnPosition.XYZInt.X; + int z = pos.Z - api.World.DefaultSpawnPosition.XYZInt.Z; + return new BlockPos(x, pos.Y + 1, z); } - protected void SendMessage(string msg, EntityAgent byEntity) + private void SendMessage(string msg, EntityAgent byEntity) { IPlayer byPlayer = api.World.PlayerByUid((byEntity as EntityPlayer).PlayerUID); if (api.Side == EnumAppSide.Server) @@ -198,6 +224,5 @@ protected void SendMessage(string msg, EntityAgent byEntity) //cp.ShowChatNotification(msg); } } - } } \ No newline at end of file