Skip to content

Commit

Permalink
v1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
DArkHekRoMaNT committed Jan 11, 2021
1 parent 0bba4a5 commit ce989e8
Show file tree
Hide file tree
Showing 12 changed files with 155 additions and 102 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
/bin
/obj
/mods
/releases
/releases
/.history
4 changes: 3 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"${workspaceFolder}/mods"
],
"console": "internalConsole",
"internalConsoleOptions": "openOnSessionStart"
"internalConsoleOptions": "openOnSessionStart",
"justMyCode": false,
"requireExactSource": false
},
{
"name": "Launch Client (Mono)",
Expand Down
20 changes: 10 additions & 10 deletions resources/assets/teleportermod/itemtypes/mirror.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
11 changes: 8 additions & 3 deletions resources/assets/teleportermod/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
7 changes: 6 additions & 1 deletion resources/assets/teleportermod/lang/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -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} м"
}
11 changes: 0 additions & 11 deletions resources/assets/teleportermod/recipes/grid/mirror-magic.json

This file was deleted.

24 changes: 24 additions & 0 deletions resources/assets/teleportermod/recipes/grid/mirrormagic.json
Original file line number Diff line number Diff line change
@@ -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}" }
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"blackbronze",
"silver",
"gold",
"iron"
"iron",
"meteoriciron",
"steel"
]
},
"pattern": [["____#####", "#####___#", "____#####"]],
Expand Down
2 changes: 1 addition & 1 deletion resources/modinfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
171 changes: 98 additions & 73 deletions src/Item/ItemMirror.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
Expand All @@ -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));
}
}

Expand Down Expand Up @@ -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)
Expand All @@ -198,6 +224,5 @@ protected void SendMessage(string msg, EntityAgent byEntity)
//cp.ShowChatNotification(msg);
}
}

}
}

0 comments on commit ce989e8

Please sign in to comment.