mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-25 11:57:35 +00:00
Fix region removal checking
This commit is contained in:
parent
5cd9d3a26d
commit
e514095e8a
@ -6,9 +6,10 @@ import emu.grasscutter.net.proto.SceneEntityInfoOuterClass;
|
||||
import emu.grasscutter.scripts.data.SceneRegion;
|
||||
import emu.grasscutter.utils.Position;
|
||||
import it.unimi.dsi.fastutil.ints.Int2FloatMap;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class EntityRegion extends GameEntity {
|
||||
|
@ -1,7 +1,5 @@
|
||||
package emu.grasscutter.scripts;
|
||||
|
||||
import static emu.grasscutter.scripts.constants.EventType.*;
|
||||
|
||||
import com.github.davidmoten.rtreemulti.RTree;
|
||||
import com.github.davidmoten.rtreemulti.geometry.Geometry;
|
||||
import emu.grasscutter.Grasscutter;
|
||||
@ -28,6 +26,14 @@ import emu.grasscutter.utils.Position;
|
||||
import io.netty.util.concurrent.FastThreadLocalThread;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import kotlin.Pair;
|
||||
import lombok.val;
|
||||
import org.luaj.vm2.LuaError;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
import org.luaj.vm2.lib.jse.CoerceJavaToLua;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
@ -35,13 +41,8 @@ import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import kotlin.Pair;
|
||||
import lombok.val;
|
||||
import org.luaj.vm2.LuaError;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
import org.luaj.vm2.lib.jse.CoerceJavaToLua;
|
||||
|
||||
import static emu.grasscutter.scripts.constants.EventType.EVENT_TIMER_EVENT;
|
||||
|
||||
public class SceneScriptManager {
|
||||
private final Scene scene;
|
||||
@ -351,9 +352,10 @@ public class SceneScriptManager {
|
||||
}
|
||||
|
||||
public synchronized void deregisterRegion(SceneRegion region) {
|
||||
var instance =
|
||||
regions.values().stream().filter(r -> r.getConfigId() == region.config_id).findFirst();
|
||||
instance.ifPresent(entityRegion -> regions.remove(entityRegion.getId()));
|
||||
this.regions.values().stream()
|
||||
.filter(r -> r.getMetaRegion().equals(region))
|
||||
.findFirst()
|
||||
.ifPresent(entityRegion -> this.regions.remove(entityRegion.getId()));
|
||||
}
|
||||
|
||||
public Map<Integer, Set<SceneGroup>> getLoadedGroupSetPerBlock() {
|
||||
|
@ -2,9 +2,10 @@ package emu.grasscutter.scripts.data;
|
||||
|
||||
import emu.grasscutter.scripts.constants.ScriptRegionShape;
|
||||
import emu.grasscutter.utils.Position;
|
||||
import java.util.List;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Setter
|
||||
public class SceneRegion {
|
||||
public int config_id;
|
||||
@ -20,6 +21,13 @@ public class SceneRegion {
|
||||
|
||||
public transient SceneGroup group;
|
||||
|
||||
/**
|
||||
* @return The group ID for this region.
|
||||
*/
|
||||
public int getGroupId() {
|
||||
return this.group == null ? -1 : this.group.id;
|
||||
}
|
||||
|
||||
public boolean contains(Position position) {
|
||||
switch (shape) {
|
||||
case ScriptRegionShape.CUBIC:
|
||||
@ -35,4 +43,21 @@ public class SceneRegion {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if two regions are the same.
|
||||
*
|
||||
* @param region The region to compare to.
|
||||
* @return True if the regions are the same, false otherwise.
|
||||
*/
|
||||
public boolean equals(SceneRegion region) {
|
||||
return this.config_id == region.config_id
|
||||
&& this.shape == region.shape
|
||||
&& this.pos.equals(region.pos)
|
||||
&& this.size.equals(region.size)
|
||||
&& this.radius == region.radius
|
||||
&& this.area_id == region.area_id
|
||||
&& this.height == region.height
|
||||
&& this.point_array.equals(region.point_array);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user