Skip to content

Commit 5ae6699

Browse files
OReliomilutinkeBruceChenQAQ
committed
MC 1.17/1.18 Terrain/Entity/Inventory (#1943)
Merge branch 'master' of github.com:milutinke/Minecraft-Console-Client into milutinke-master Manually fix merge conflicts Additional changes: - WindowItems: Fix data type for "elements" below 1.17 - DestroyEntities: Fix packet palettes and remove DestroyEntity - EntityMetadata: Throw exception if health field mapping is not updated Co-authored-by: Milutinke <[email protected]> Co-authored-by: BruceChen <[email protected]>
2 parents 73195c5 + 1ce7850 commit 5ae6699

34 files changed

+5941
-878
lines changed

MinecraftClient/ChatBots/AutoAttack.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,15 @@ public override void Update()
103103
}
104104
}
105105
}
106-
// check entity distance and health again
107-
if (shouldAttackEntity(entitiesToAttack[priorityEntity]))
106+
107+
if (entitiesToAttack.ContainsKey(priorityEntity))
108108
{
109-
InteractEntity(priorityEntity, interactMode); // hit the entity!
110-
SendAnimation(Inventory.Hand.MainHand); // Arm animation
109+
// check entity distance and health again
110+
if (shouldAttackEntity(entitiesToAttack[priorityEntity]))
111+
{
112+
InteractEntity(priorityEntity, interactMode); // hit the entity!
113+
SendAnimation(Inventory.Hand.MainHand); // Arm animation
114+
}
111115
}
112116
}
113117
else
@@ -143,6 +147,22 @@ public override void OnEntityDespawn(Entity entity)
143147
}
144148
}
145149

150+
public override void OnEntityHealth(Entity entity, float health)
151+
{
152+
if (!entity.Type.IsHostile())
153+
return;
154+
155+
if (entitiesToAttack.ContainsKey(entity.ID))
156+
{
157+
entitiesToAttack[entity.ID].Health = health;
158+
159+
if (entitiesToAttack[entity.ID].Health <= 0)
160+
{
161+
entitiesToAttack.Remove(entity.ID);
162+
}
163+
}
164+
}
165+
146166
public override void OnEntityMove(Entity entity)
147167
{
148168
shouldAttackEntity(entity);

MinecraftClient/Commands/Move.cs

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace MinecraftClient.Commands
88
public class Move : Command
99
{
1010
public override string CmdName { get { return "move"; } }
11-
public override string CmdUsage { get { return "move <on|off|get|up|down|east|west|north|south|x y z|gravity [on|off]> [-f]"; } }
11+
public override string CmdUsage { get { return "move <on|off|get|up|down|east|west|north|south|center|x y z|gravity [on|off]> [-f]"; } }
1212
public override string CmdDesc { get { return "walk or start walking. \"-f\": force unsafe movements like falling or touching fire"; } }
1313

1414
public override string Run(McClient handler, string command, Dictionary<string, object> localVars)
@@ -17,7 +17,14 @@ public override string Run(McClient handler, string command, Dictionary<string,
1717
bool takeRisk = false;
1818

1919
if (args.Count < 1)
20-
return GetCmdDescTranslated();
20+
{
21+
string desc = GetCmdDescTranslated();
22+
23+
if (handler.GetTerrainEnabled())
24+
handler.Log.Info(getChunkLoadingStatus(handler.GetWorld()));
25+
26+
return desc;
27+
}
2128

2229
if (args.Contains("-f"))
2330
{
@@ -56,6 +63,11 @@ public override string Run(McClient handler, string command, Dictionary<string,
5663
case "west": direction = Direction.West; break;
5764
case "north": direction = Direction.North; break;
5865
case "south": direction = Direction.South; break;
66+
case "center":
67+
Location current = handler.GetCurrentLocation();
68+
Location currentCenter = new Location(Math.Floor(current.X) + 0.5, current.Y, Math.Floor(current.Z) + 0.5);
69+
handler.MoveTo(currentCenter, allowDirectTeleport: true);
70+
return Translations.Get("cmd.move.walk", currentCenter, current);
5971
case "get": return handler.GetCurrentLocation().ToString();
6072
default: return Translations.Get("cmd.look.unknown", args[0]);
6173
}
@@ -76,8 +88,15 @@ public override string Run(McClient handler, string command, Dictionary<string,
7688
int z = int.Parse(args[2]);
7789
Location goal = new Location(x, y, z);
7890

91+
if (handler.GetWorld().GetChunkColumn(goal) == null || handler.GetWorld().GetChunkColumn(goal).FullyLoaded == false)
92+
return Translations.Get("cmd.move.chunk_not_loaded");
93+
94+
Location current = handler.GetCurrentLocation();
95+
Location currentCenter = new Location(Math.Floor(current.X) + 0.5, current.Y, Math.Floor(current.Z) + 0.5);
96+
handler.MoveTo(currentCenter, allowDirectTeleport: true);
97+
7998
if (handler.MoveTo(goal, allowUnsafe: takeRisk))
80-
return Translations.Get("cmd.move.walk", goal);
99+
return Translations.Get("cmd.move.walk", goal, current);
81100
else return takeRisk ? Translations.Get("cmd.move.fail", goal) : Translations.Get("cmd.move.suggestforce", goal);
82101
}
83102
catch (FormatException) { return GetCmdDescTranslated(); }
@@ -86,5 +105,19 @@ public override string Run(McClient handler, string command, Dictionary<string,
86105
}
87106
else return Translations.Get("extra.terrainandmovement_required");
88107
}
108+
109+
private string getChunkLoadingStatus(World world)
110+
{
111+
double chunkLoadedRatio;
112+
if (world.chunkCnt == 0)
113+
chunkLoadedRatio = 0;
114+
else
115+
chunkLoadedRatio = (world.chunkCnt - world.chunkLoadNotCompleted) / (double)world.chunkCnt;
116+
117+
string status = Translations.Get("cmd.move.chunk_loading_status",
118+
chunkLoadedRatio, world.chunkCnt - world.chunkLoadNotCompleted, world.chunkCnt);
119+
120+
return status;
121+
}
89122
}
90123
}

MinecraftClient/Inventory/Container.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ public class Container
2525
/// </summary>
2626
public string Title;
2727

28+
/// <summary>
29+
/// state of container
30+
/// </summary>
31+
public int StateID;
32+
2833
/// <summary>
2934
/// Container Items
3035
/// </summary>

0 commit comments

Comments
 (0)