Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ziqian zhang
Grasscutter
Commits
184eec82
Commit
184eec82
authored
May 30, 2022
by
Melledy
Browse files
Limit spawn amount if too many entities are in the world
Can be controlled in the config with `sceneEntityLimit`
parent
18721758
Changes
3
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/command/commands/SpawnCommand.java
View file @
184eec82
...
@@ -20,6 +20,7 @@ import javax.swing.text.html.parser.Entity;
...
@@ -20,6 +20,7 @@ import javax.swing.text.html.parser.Entity;
import
java.util.List
;
import
java.util.List
;
import
java.util.Random
;
import
java.util.Random
;
import
static
emu
.
grasscutter
.
Configuration
.*;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
import
static
emu
.
grasscutter
.
utils
.
Language
.
translate
;
@Command
(
label
=
"spawn"
,
usage
=
"spawn <entityId> [amount] [level(monster only)]"
,
permission
=
"server.spawn"
,
permissionTargeted
=
"server.spawn.others"
,
description
=
"commands.spawn.description"
)
@Command
(
label
=
"spawn"
,
usage
=
"spawn <entityId> [amount] [level(monster only)]"
,
permission
=
"server.spawn"
,
permissionTargeted
=
"server.spawn.others"
,
description
=
"commands.spawn.description"
)
...
@@ -62,8 +63,17 @@ public final class SpawnCommand implements CommandHandler {
...
@@ -62,8 +63,17 @@ public final class SpawnCommand implements CommandHandler {
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.generic.invalid.entityId"
));
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.generic.invalid.entityId"
));
return
;
return
;
}
}
Scene
scene
=
targetPlayer
.
getScene
();
Scene
scene
=
targetPlayer
.
getScene
();
if
(
scene
.
getEntities
().
size
()
+
amount
>
GAME_OPTIONS
.
sceneEntityLimit
)
{
amount
=
Math
.
max
(
Math
.
min
(
GAME_OPTIONS
.
sceneEntityLimit
-
scene
.
getEntities
().
size
(),
amount
),
0
);
CommandHandler
.
sendMessage
(
sender
,
translate
(
sender
,
"commands.spawn.limit_reached"
,
amount
));
if
(
amount
<=
0
)
{
return
;
}
}
double
maxRadius
=
Math
.
sqrt
(
amount
*
0.2
/
Math
.
PI
);
double
maxRadius
=
Math
.
sqrt
(
amount
*
0.2
/
Math
.
PI
);
for
(
int
i
=
0
;
i
<
amount
;
i
++)
{
for
(
int
i
=
0
;
i
<
amount
;
i
++)
{
Position
pos
=
GetRandomPositionInCircle
(
targetPlayer
.
getPos
(),
maxRadius
).
addY
(
3
);
Position
pos
=
GetRandomPositionInCircle
(
targetPlayer
.
getPos
(),
maxRadius
).
addY
(
3
);
...
...
src/main/java/emu/grasscutter/utils/ConfigContainer.java
View file @
184eec82
...
@@ -171,7 +171,7 @@ public class ConfigContainer {
...
@@ -171,7 +171,7 @@ public class ConfigContainer {
public
static
class
GameOptions
{
public
static
class
GameOptions
{
public
InventoryLimits
inventoryLimits
=
new
InventoryLimits
();
public
InventoryLimits
inventoryLimits
=
new
InventoryLimits
();
public
AvatarLimits
avatarLimits
=
new
AvatarLimits
();
public
AvatarLimits
avatarLimits
=
new
AvatarLimits
();
public
int
world
EntityLimit
=
1000
;
// Unenforced. TODO: Implement.
public
int
scene
EntityLimit
=
1000
;
// Unenforced. TODO: Implement.
public
boolean
watchGachaConfig
=
false
;
public
boolean
watchGachaConfig
=
false
;
public
boolean
enableShopItems
=
true
;
public
boolean
enableShopItems
=
true
;
...
...
src/main/resources/languages/en-US.json
View file @
184eec82
...
@@ -306,6 +306,7 @@
...
@@ -306,6 +306,7 @@
"spawn"
:
{
"spawn"
:
{
"usage"
:
"Usage: spawn <entityID> [amount] [level(monster only)]"
,
"usage"
:
"Usage: spawn <entityID> [amount] [level(monster only)]"
,
"success"
:
"Spawned %s of %s."
,
"success"
:
"Spawned %s of %s."
,
"limit_reached"
:
"Scene spawn limit reached. Spawning %s entities instead."
,
"description"
:
"Spawns an entity near you"
"description"
:
"Spawns an entity near you"
},
},
"stop"
:
{
"stop"
:
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment