Skip to content

Commit 52d9e4b

Browse files
committed
World: Add getWorld
1 parent 29abe4e commit 52d9e4b

25 files changed

Lines changed: 185 additions & 40 deletions

File tree

iCommon-API/src/main/java/me/isaiah/common/IServer.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import net.minecraft.item.ItemStack;
1010
import net.minecraft.resource.ResourcePackProfile;
1111
import net.minecraft.server.MinecraftServer;
12+
import net.minecraft.util.Identifier;
1213
import net.minecraft.village.TradeOffer;
1314

1415
public interface IServer {
@@ -22,8 +23,16 @@ public interface IServer {
2223
public Collection<IWorld> getWorlds();
2324

2425
/**
26+
* Retrives the World given the Level Name
27+
* (Ex: "world", "world_nether", "world_the_end")
2528
*/
2629
public IWorld getWorld(String name);
30+
31+
/**
32+
* Retrives the World given the Registry Name
33+
* (Ex: "minecraft:overworld", "minecraft:the_end")
34+
*/
35+
IWorld getWorld(Identifier id);
2736

2837
/**
2938
*/

iCommon-API/src/main/java/me/isaiah/common/cmixin/IMixinEntity.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import net.minecraft.server.network.ServerPlayerEntity;
1818
import net.minecraft.server.world.ServerWorld;
1919
import net.minecraft.text.Text;
20+
import net.minecraft.world.World;
2021

2122
public interface IMixinEntity {
2223

@@ -42,7 +43,9 @@ else if (mc instanceof ArmorStandEntity) {
4243

4344
/**
4445
* @reason 1.16 & 1.17 differ in entity removal
46+
* @deprecated We only support 1.18+
4547
*/
48+
@Deprecated
4649
public void Iremove(IRemoveReason r);
4750

4851
/**
@@ -53,7 +56,9 @@ else if (mc instanceof ArmorStandEntity) {
5356
/**
5457
* 1.16 - removed
5558
* 1.17 - isRemoved()
59+
* @deprecated We only support 1.18+
5660
*/
61+
@Deprecated
5762
public boolean ic_isRemoved();
5863

5964
/**
@@ -82,5 +87,11 @@ else if (mc instanceof ArmorStandEntity) {
8287
* >= 1.20: Entity.teleportTo(TeleportTarget)
8388
*/
8489
public void IC$teleport(ServerWorld world, double x, double y, double z);
90+
91+
/**
92+
* You Just Had to Break getWorld()...
93+
* https://fabricmc.net/2025/09/23/1219.html
94+
*/
95+
public World ic$getWorld();
8596

8697
}
Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,60 @@
11
package me.isaiah.common.entity;
22

33
import me.isaiah.common.ICommandSource;
4+
import me.isaiah.common.world.IWorld;
45

56
public interface IEntity extends ICommandSource {
67

7-
public Object getMC();
8+
/**
9+
*/
10+
public Object getMC();
811

9-
public String getName();
12+
/**
13+
*/
14+
public String getName();
1015

11-
public void remove(IRemoveReason r);
16+
/**
17+
*/
18+
@Deprecated
19+
public void remove(IRemoveReason r);
1220

13-
public boolean isRemoved();
21+
/**
22+
*/
23+
@Deprecated
24+
public boolean isRemoved();
1425

15-
public String getDisplayedName();
26+
/**
27+
*/
28+
public String getDisplayedName();
1629

17-
public void setDisplayedName(String name);
30+
/**
31+
*/
32+
public void setDisplayedName(String name);
1833

19-
public EntityType getEntityType();
34+
/**
35+
*/
36+
public EntityType getEntityType();
2037

21-
void collidesWith(IEntity e);
38+
/**
39+
*/
40+
void collidesWith(IEntity e);
2241

23-
void teleport(double x, double y, double z);
42+
/**
43+
*/
44+
void teleport(double x, double y, double z);
2445

25-
void teleport(double x, double y, double z, float yaw, float pitch);
46+
/**
47+
*/
48+
void teleport(double x, double y, double z, float yaw, float pitch);
2649

27-
/**
28-
* @see IMixinTameableEntity#set_tamed
29-
*/
50+
/**
51+
* @see IMixinTameableEntity#set_tamed
52+
*/
3053
void set_tamed(boolean tame, boolean updateAttrib);
3154

55+
/**
56+
* Retrives the {@link IWorld} for this Entity.
57+
*/
58+
IWorld getIWorld();
59+
3260
}

iCommon-API/src/main/java/me/isaiah/common/fabric/FabricServer.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,44 @@
1313
import me.isaiah.common.IServer;
1414
import me.isaiah.common.Side;
1515
import me.isaiah.common.cmixin.IMixinMinecraftServer;
16+
import me.isaiah.common.cmixin.IMixinWorld;
1617
import me.isaiah.common.world.IWorld;
1718
import net.minecraft.MinecraftVersion;
1819
import net.minecraft.item.ItemStack;
1920
import net.minecraft.resource.ResourcePackProfile;
2021
import net.minecraft.server.MinecraftServer;
22+
import net.minecraft.server.world.ServerWorld;
23+
import net.minecraft.util.Identifier;
2124
import net.minecraft.util.JsonHelper;
2225
import net.minecraft.village.TradeOffer;
26+
import net.minecraft.world.World;
2327

2428
public class FabricServer implements IServer {
2529

30+
private static FabricServer INSTANCE;
31+
32+
public static FabricServer getInstance() {
33+
return INSTANCE;
34+
}
35+
2636
private MinecraftServer mc;
2737
public HashMap<String, IWorld> worlds;
38+
public HashMap<String, IWorld> worldsMap;
2839

2940
public FabricServer(MinecraftServer mc) {
41+
FabricServer.INSTANCE = this;
3042
this.mc = mc;
3143
this.worlds = new HashMap<>();
44+
this.worldsMap = new HashMap<>();
3245
}
3346

34-
public void world(IWorld icommon, String name) {
47+
public void world(IWorld icommon, String name, Identifier worldId) {
3548
worlds.put(name, icommon);
49+
worldsMap.put(worldId.toString(), icommon);
50+
}
51+
52+
public IWorld getIWorldForMinecraftWorld(World world) {
53+
return worldsMap.get(world.getRegistryKey().getValue().toString());
3654
}
3755

3856
@Override
@@ -44,6 +62,11 @@ public String getMinecraftVersion() {
4462
public Collection<IWorld> getWorlds() {
4563
return worlds.values();
4664
}
65+
66+
@Override
67+
public IWorld getWorld(Identifier id) {
68+
return worldsMap.get(id.toString());
69+
}
4770

4871
@Override
4972
public IWorld getWorld(String name) {

iCommon-API/src/main/java/me/isaiah/common/fabric/entity/FabricEntity.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,22 @@
77
import me.isaiah.common.entity.EntityType;
88
import me.isaiah.common.entity.IEntity;
99
import me.isaiah.common.entity.IRemoveReason;
10+
import me.isaiah.common.fabric.FabricServer;
1011
import net.minecraft.entity.Entity;
11-
import net.minecraft.server.world.ServerWorld;
1212
import net.minecraft.text.Text;
13+
import net.minecraft.world.World;
14+
import me.isaiah.common.world.IWorld;
1315

1416
public class FabricEntity implements IEntity {
1517

1618
public Entity mc;
1719
public FabricEntity(Entity mc) {
1820
this.mc = mc;
1921
}
22+
23+
private IMixinEntity imixin() {
24+
return (IMixinEntity) mc;
25+
}
2026

2127
@Override
2228
public String getName() {
@@ -28,6 +34,13 @@ public String getName() {
2834
public Entity getMC() {
2935
return mc;
3036
}
37+
38+
@Override
39+
public IWorld getIWorld() {
40+
World world = this.imixin().ic$getWorld();
41+
return FabricServer.getInstance().getIWorldForMinecraftWorld(world);
42+
}
43+
3144

3245
@Override
3346
public String getDisplayedName() {

iCommon-Fabric-1.18.2/src/main/java/me/isaiah/common/mixin/R1_18/MixinEntity.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import net.minecraft.server.world.ServerWorld;
1818
import net.minecraft.text.Text;
1919
import net.minecraft.util.registry.Registry;
20+
import net.minecraft.world.World;
2021

2122
@SupportedVersion({"1.17"})
2223
@Mixin(Entity.class)
@@ -124,5 +125,10 @@ public boolean isRemoved() {
124125
((Entity) (Object) this).teleport(x, y, z);
125126
}
126127

128+
@Override
129+
public World ic$getWorld() {
130+
return ((Entity) (Object) this).getWorld();
131+
}
132+
127133

128134
}

iCommon-Fabric-1.18.2/src/main/java/me/isaiah/common/mixin/R1_18/MixinWorld_18.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import net.minecraft.block.Blocks;
2121
import net.minecraft.item.map.MapState;
2222
import net.minecraft.server.world.ServerWorld;
23+
import net.minecraft.util.Identifier;
2324
import net.minecraft.util.collection.IndexedIterable;
2425
import net.minecraft.util.math.BlockPos;
2526
import net.minecraft.util.math.ChunkPos;
@@ -63,7 +64,8 @@ public void init(MutableWorldProperties a, RegistryKey<?> b, RegistryEntry<Dimen
6364
}
6465
ICommonMod.LOGGER.info("Setting IWorld for world \"" + name + "\"");
6566
this.icommon = new FabricWorld(name, (World)(Object)this);
66-
((FabricServer)ICommonMod.getIServer()).world(icommon, name);
67+
Identifier id = nms.getRegistryKey().getValue();
68+
((FabricServer)ICommonMod.getIServer()).world(icommon, name, id);
6769

6870
// ServerWorldInitEvent
6971
EventRegistery.invoke(ServerWorldInitEvent.class, new ServerWorldInitEvent(icommon));

iCommon-Fabric-1.19.2/src/main/java/me/isaiah/common/mixin/R1_19/MixinEntity.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import me.isaiah.common.ICommonMod;
99
import me.isaiah.common.cmixin.IMixinEntity;
10-
import me.isaiah.common.cmixin.SupportedVersion;
1110
import me.isaiah.common.entity.IEntity;
1211
import me.isaiah.common.entity.IRemoveReason;
1312
import net.minecraft.entity.Entity;
@@ -17,8 +16,8 @@
1716
import net.minecraft.server.world.ServerWorld;
1817
import net.minecraft.text.Text;
1918
import net.minecraft.util.registry.Registry;
19+
import net.minecraft.world.World;
2020

21-
@SupportedVersion({"1.17"})
2221
@Mixin(Entity.class)
2322
public class MixinEntity implements IMixinEntity {
2423

@@ -123,5 +122,10 @@ public boolean isRemoved() {
123122
public void IC$teleport(ServerWorld world, double x, double y, double z) {
124123
((Entity) (Object) this).teleport(x, y, z);
125124
}
125+
126+
@Override
127+
public World ic$getWorld() {
128+
return ((Entity) (Object) this).getWorld();
129+
}
126130

127131
}

iCommon-Fabric-1.19.2/src/main/java/me/isaiah/common/mixin/R1_19/MixinWorld_18.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import net.minecraft.block.Blocks;
2121
import net.minecraft.item.map.MapState;
2222
import net.minecraft.server.world.ServerWorld;
23+
import net.minecraft.util.Identifier;
2324
import net.minecraft.util.collection.IndexedIterable;
2425
import net.minecraft.util.math.BlockPos;
2526
import net.minecraft.util.math.ChunkPos;
@@ -64,7 +65,8 @@ public void init(MutableWorldProperties a, RegistryKey<?> b, RegistryEntry<Dimen
6465
}
6566
ICommonMod.LOGGER.info("Setting IWorld for world \"" + name + "\"");
6667
this.icommon = new FabricWorld(name, (World)(Object)this);
67-
((FabricServer)ICommonMod.getIServer()).world(icommon, name);
68+
Identifier id = nms.getRegistryKey().getValue();
69+
((FabricServer)ICommonMod.getIServer()).world(icommon, name, id);
6870

6971
// ServerWorldInitEvent
7072
EventRegistery.invoke(ServerWorldInitEvent.class, new ServerWorldInitEvent(icommon));

iCommon-Fabric-1.19.4/src/main/java/me/isaiah/common/mixin/R1_19/MixinEntity.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
import net.minecraft.registry.Registries;
1818
import net.minecraft.server.world.ServerWorld;
1919
import net.minecraft.text.Text;
20+
import net.minecraft.world.World;
2021

21-
@SupportedVersion({"1.17"})
2222
@Mixin(Entity.class)
2323
public class MixinEntity implements IMixinEntity {
2424

@@ -124,5 +124,10 @@ public boolean isRemoved() {
124124
((Entity) (Object) this).teleport(x, y, z);
125125
}
126126

127+
@Override
128+
public World ic$getWorld() {
129+
return ((Entity) (Object) this).getWorld();
130+
}
131+
127132

128133
}

0 commit comments

Comments
 (0)