Skip to content

Commit

Permalink
Check again virtual wild when querying properties
Browse files Browse the repository at this point in the history
  • Loading branch information
3TUSK committed Dec 19, 2024
1 parent f6bd7d9 commit 03477a0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/main/java/org/teacon/areacontrol/api/AreaControlAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public Area findBy(String dimKey, double x, double y, double z) {
public Area findBy(String dimKey, int x, int y, int z) {
throw new IllegalStateException("Not initialized yet!");
}

@Override
public @Nullable Area getVirtualWild() {
throw new IllegalStateException("Not initialized yet!");
}
};

public static GroupProvider groupProvider = new GroupProvider() {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/teacon/areacontrol/api/AreaLookup.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ public interface AreaLookup {

@Nullable
Area findBy(String dimKey, int x, int y, int z);

@Nullable
Area getVirtualWild();
}
9 changes: 8 additions & 1 deletion src/main/java/org/teacon/areacontrol/api/AreaProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,14 @@ public static Optional<Boolean> getBoolOptional(@Nullable Area area, String key)
}

public static Optional<Boolean> getBoolOptional(@Nullable Area area, String key, boolean recursive) {
if (area == null) return Optional.empty();
if (area == null) {
Area virtualWild = AreaControlAPI.areaLookup.getVirtualWild();
if (virtualWild == null) {
return Optional.empty();
}
area = virtualWild;
recursive = false;
}
Object o = area.properties.get(key);
if (o == null || "null".equals(o)) {
if (recursive) {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/teacon/areacontrol/impl/AreaLookupImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.Nullable;
import org.teacon.areacontrol.AreaManager;
import org.teacon.areacontrol.api.Area;
import org.teacon.areacontrol.api.AreaLookup;
Expand Down Expand Up @@ -39,4 +40,10 @@ public Area findBy(String dimKey, int x, int y, int z) {
var dimResKey = this.getOrCreate(dimKey);
return AreaManager.INSTANCE.findBy(dimResKey, new BlockPos(x, y, z));
}

@Override
public @Nullable Area getVirtualWild() {
return AreaManager.INSTANCE.getVirtualWild();
}

}

0 comments on commit 03477a0

Please sign in to comment.