Skip to content

Commit 8453df3

Browse files
committed
0x01
1 parent 78d9312 commit 8453df3

File tree

7 files changed

+220
-43
lines changed

7 files changed

+220
-43
lines changed

README.md

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,29 @@
1-
# Example Mod
1+
# ClearLag
22

3-
Template for making Babric mods for BTA!
3+
A plugin to help manage lag on BTA servers.
44

5-
**Note: *DO NOT fork this repository unless you want to contribute!***
5+
Its just removes types of entities, nothing too fancy.
66

7-
## Prerequisites
8-
- JDK for Java 17 ([Eclipse Temurin](https://adoptium.net/temurin/releases/) recommended)
9-
- [Intellij IDEA](https://www.jetbrains.com/idea/download/) (Scroll down for the free community edition, if using linux **DO NOT** use the flatpak distribution)
10-
- Minecraft Development plugin (Optional, but highly recommended)
7+
### Usage
118

12-
## Setup instructions
13-
9+
`/lag [range]`
1410

15-
1. Click the `Use this template` button on this repo's page above (Will only appear if logged in). Choose `Create a new repository`, you will be redirected to a new page. Enter your repo's name and description, and hit `Create repository`.
16-
To get your project, open IntelliJ IDEA and click `Get from VCS`. Select `Repository URL` and enter your repo's url
11+
`/lag [chunkRange]`
1712

18-
2. After the project has finished importing, close it and open it again.
19-
If that does not work, open the right sidebar with `Gradle` on it, open `Tasks` > `fabric` and run `ideaSyncTask`.
13+
`/lag [lagType] [chunkRange]`
2014

21-
3. Create a new run configuration by going in `Run > Edit Configurations`.
22-
Then click on the plus icon and select Gradle. In the `Tasks and Arguments` field enter `build`.
23-
Running it will build your finished jar files and put them in `build/libs/`.
15+
`/lag [targetPlayer] [lagType] [chunkRange]`
2416

25-
4. Lastly, open `File` > `Settings` and head to `Build, Execution, Development` > `Build Tools` > `Gradle`.
26-
Make sure `Build and run using` and `Run tests using` is set to `Gradle`.
17+
### Specifics
18+
The `chunkRange` defines a square area of chunks, centered on the specified player.
2719

28-
5. Done! Now, all that's left is to change every mention of `examplemod` and `turniplabs` to your own mod id and mod group, respectively. Happy modding!
20+
This should not remove named entities, tamed dogs, or saddled pigs.
2921

30-
## Tips
31-
32-
1. If you haven't already you should join the BTA modding discord! https://discord.gg/FTUNJhswBT
33-
2. You can set your username when launching the client run configuration by setting `--username <username>` in your program arguments.
34-
3. When launching the server run configuration you may want to remove the `nogui` program argument in order to see the regular server GUI.
35-
4. In Intellij you can double press shift or press ctrl+N to search class files, change the search from the default `Project Files` to `All Places` you can easily explore the classes for you dependencies and even BTA itself.
36-
5. In Intellij if ctrl+left click on a field or method you can quickly get information on when and where that field or method is assign or used.
22+
#### Lag types:
23+
- mobs
24+
- items
25+
- all
3726

27+
#### Default values:
28+
- chunkRange = 0
29+
- lagType = all

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ halplibe_version=3.5.2
1212

1313
# Mod
1414
mod_version=1.0.0
15-
mod_group=turniplabs
16-
mod_name=examplemod
15+
mod_group=wyspr
16+
mod_name=clearlag

src/main/java/turniplabs/examplemod/ExampleMod.java renamed to src/main/java/wyspr/clearlag/ClearLag.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
1-
package turniplabs.examplemod;
1+
package wyspr.clearlag;
22

33
import net.fabricmc.api.ModInitializer;
44
import org.slf4j.Logger;
55
import org.slf4j.LoggerFactory;
6-
import turniplabs.halplibe.helper.BlockBuilder;
76
import turniplabs.halplibe.util.GameStartEntrypoint;
87
import turniplabs.halplibe.util.RecipeEntrypoint;
98

9+
import java.util.Objects;
1010

11-
public class ExampleMod implements ModInitializer, GameStartEntrypoint, RecipeEntrypoint {
12-
public static final String MOD_ID = "examplemod";
11+
12+
public class ClearLag implements ModInitializer, GameStartEntrypoint, RecipeEntrypoint {
13+
public static final String MOD_ID = "ClearLag";
1314
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
1415
@Override
1516
public void onInitialize() {
16-
LOGGER.info("ExampleMod initialized.");
17+
log("ClearLag initialized.");
1718
}
1819

20+
public static void log(String s) {
21+
LOGGER.info(s);
22+
System.out.println(s);
23+
}
24+
1925
@Override
2026
public void beforeGameStart() {
2127

@@ -30,4 +36,14 @@ public void afterGameStart() {
3036
public void onRecipesReady() {
3137

3238
}
39+
40+
public enum LagSource {
41+
ITEMS,
42+
MOBS,
43+
// REDSTONE,
44+
ALL {
45+
@Override
46+
public String toString() { return "entities"; }
47+
}
48+
}
3349
}
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
package wyspr.clearlag.commands;
2+
3+
import net.minecraft.core.entity.Entity;
4+
import net.minecraft.core.entity.EntityItem;
5+
import net.minecraft.core.entity.EntityLiving;
6+
import net.minecraft.core.entity.animal.EntityPig;
7+
import net.minecraft.core.entity.animal.EntityWolf;
8+
import net.minecraft.core.entity.player.EntityPlayer;
9+
import net.minecraft.core.net.command.Command;
10+
import net.minecraft.core.net.command.CommandError;
11+
import net.minecraft.core.net.command.CommandHandler;
12+
import net.minecraft.core.net.command.CommandSender;
13+
import net.minecraft.core.util.phys.AABB;
14+
import net.minecraft.core.world.World;
15+
import wyspr.clearlag.ClearLag;
16+
import wyspr.clearlag.ClearLag.LagSource;
17+
18+
import java.util.List;
19+
import java.util.stream.Collectors;
20+
21+
public class ClearLagCommand extends Command {
22+
public ClearLagCommand() {
23+
super("clearlag", "cl", "lag");
24+
}
25+
26+
@Override
27+
public boolean execute(CommandHandler handler, CommandSender sender, String[] args) {
28+
if (sender.isConsole()) return false;
29+
30+
EntityPlayer p = sender.getPlayer();
31+
LagSource target = LagSource.ALL;
32+
int range = 0;
33+
34+
switch (args.length) {
35+
case 0:
36+
break;
37+
case 1:
38+
try {
39+
range = Integer.parseInt(args[0]);
40+
} catch (NumberFormatException ignored) {
41+
// Ignore because we have default value
42+
}
43+
break;
44+
case 2:
45+
try {
46+
target = LagSource.valueOf(args[0].toUpperCase());
47+
} catch (IllegalArgumentException ignored) {
48+
// Ignore because we have default value
49+
}
50+
try {
51+
range = Integer.parseInt(args[1]);
52+
} catch (NumberFormatException ignored) {
53+
// Ignore because we have default value
54+
}
55+
break;
56+
default:
57+
EntityPlayer targetPlayer = handler.getPlayer(args[0]);
58+
if (targetPlayer == null) {
59+
throw new CommandError("Player not found!");
60+
}
61+
p = targetPlayer;
62+
try {
63+
target = LagSource.valueOf(args[1].toUpperCase());
64+
} catch (IllegalArgumentException ignored) {
65+
// Ignore because we have default value
66+
}
67+
try {
68+
range = Integer.parseInt(args[2]);
69+
} catch (NumberFormatException ignored) {
70+
// Ignore because we have default value
71+
}
72+
}
73+
74+
int centerChunkX = p.chunkCoordX;
75+
int centerChunkZ = p.chunkCoordZ;
76+
AABB area = new AABB(
77+
16.0 * (centerChunkX - range),
78+
0.0,
79+
16.0 * (centerChunkZ - range),
80+
16.0 * (1 + centerChunkX + range),
81+
255.0,
82+
16.0 * (1 + centerChunkZ + range)
83+
);
84+
World world = handler.getWorld(p);
85+
86+
List<Entity> entities = null;
87+
88+
switch (target) {
89+
case ITEMS:
90+
entities = world.getEntitiesWithinAABB(EntityItem.class, area);
91+
break;
92+
case MOBS:
93+
entities = world.getEntitiesWithinAABB(EntityLiving.class, area);
94+
break;
95+
case ALL:
96+
entities = world.getEntitiesWithinAABB(EntityItem.class, area);
97+
entities.addAll(world.getEntitiesWithinAABB(EntityLiving.class, area));
98+
break;
99+
}
100+
101+
entities = entities.stream()
102+
.filter(e -> !( e instanceof EntityPlayer))
103+
.filter(e -> !( e instanceof EntityLiving && !((EntityLiving) e).nickname.isEmpty() ))
104+
.filter(e -> !( e instanceof EntityWolf && ((EntityWolf) e).isWolfTamed() ))
105+
.filter(e -> !( e instanceof EntityPig && ((EntityPig) e).getSaddled() ))
106+
.collect(Collectors.toList());
107+
108+
boolean debugMode = false;
109+
int entityAmount = entities.size();
110+
for (Entity e : entities) {
111+
if (debugMode) {
112+
String entityName = e.getClass()
113+
.getSimpleName()
114+
.replace("Entity", "");
115+
116+
String info = String.format("Removed %-8s at: %.1f, %.1f, %.1f", entityName, e.x, e.y, e.z);
117+
ClearLag.log(info);
118+
}
119+
e.remove();
120+
}
121+
122+
String targetString = target.toString().toLowerCase();
123+
sender.sendMessage("§eRemoved §4" + entityAmount + " " + targetString + "§e in a §4" + range + "§e chunk radius.");
124+
125+
return true;
126+
}
127+
128+
@Override
129+
public boolean opRequired(String[] strings) {
130+
return true;
131+
}
132+
133+
@Override
134+
public void sendCommandSyntax(CommandHandler handler, CommandSender sender) {
135+
sender.sendMessage("/lag [chunkRange]");
136+
sender.sendMessage("/lag [lagType] [chunkRange]");
137+
sender.sendMessage("/lag [player] [lagType] [chunkRange]");
138+
sender.sendMessage("Lag types:");
139+
sender.sendMessage(" mobs, items, all");
140+
sender.sendMessage("Default values:");
141+
sender.sendMessage(" Range = 0");
142+
sender.sendMessage(" Type = all");
143+
}
144+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package wyspr.clearlag.mixins;
2+
3+
import net.minecraft.core.net.command.Command;
4+
import net.minecraft.core.net.command.Commands;
5+
import org.spongepowered.asm.mixin.Final;
6+
import org.spongepowered.asm.mixin.Mixin;
7+
import org.spongepowered.asm.mixin.Shadow;
8+
import org.spongepowered.asm.mixin.injection.At;
9+
import org.spongepowered.asm.mixin.injection.Inject;
10+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
11+
import wyspr.clearlag.commands.ClearLagCommand;
12+
13+
import java.util.ArrayList;
14+
import java.util.List;
15+
16+
@Mixin(value = Commands.class, remap = false)
17+
public final class CommandsMixin {
18+
@Shadow
19+
public static final List<Command> commands = new ArrayList<>();
20+
@Inject(method = "initCommands", at = @At("TAIL"))
21+
private static void initCommands(CallbackInfo ci) {
22+
commands.add(new ClearLagCommand());
23+
}
24+
}

src/main/resources/examplemod.mixins.json renamed to src/main/resources/clearlag.mixins.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"required": true,
33
"minVersion": "0.8",
4-
"package": "turniplabs.examplemod.mixin",
4+
"package": "wyspr.clearlag.mixins",
55
"compatibilityLevel": "JAVA_8",
66
"mixins": [
7+
"CommandsMixin"
78
],
89
"client": [
910
],

src/main/resources/fabric.mod.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"schemaVersion": 1,
3-
"id": "examplemod",
3+
"id": "clearlag",
44
"version": "${version}",
55

6-
"name": "Example Mod",
7-
"description": "This mod aims to help new BTA modders.",
6+
"name": "Clear Lag",
7+
"description": "A plugin to help remove lag.",
88
"authors": [
9-
"Turnip Labs"
9+
"wyspr"
1010
],
1111
"contact": {
1212
"homepage": "",
@@ -19,20 +19,20 @@
1919
"environment": "*",
2020
"entrypoints": {
2121
"main": [
22-
"turniplabs.examplemod.ExampleMod"
22+
"wyspr.clearlag.ClearLag"
2323
],
2424
"beforeGameStart": [
25-
"turniplabs.examplemod.ExampleMod"
25+
"wyspr.clearlag.ClearLag"
2626
],
2727
"afterGameStart": [
28-
"turniplabs.examplemod.ExampleMod"
28+
"wyspr.clearlag.ClearLag"
2929
],
3030
"recipesReady": [
31-
"turniplabs.examplemod.ExampleMod"
31+
"wyspr.clearlag.ClearLag"
3232
]
3333
},
3434
"mixins": [
35-
"examplemod.mixins.json"
35+
"clearlag.mixins.json"
3636
],
3737

3838
"depends": {

0 commit comments

Comments
 (0)