Skip to content

Commit 2fcf239

Browse files
author
MagmaGuy
committed
FreeMinecraftModels 2.0.0:
- Added prop command & prop system - Armor stands now work - Fixed problems with contact damage - Added scale to animations - Updated for Minecraft 1.21.5 - Added a centralized ticking system for better performance - Several improvements to the prop system, damage system and bounding box system - A lot of optimizations around the watchers and animation system - New correctly checking for remote updates - Added new hitbox system which supports having x and z dimension be different for hitboxes, and increases accuracy as it supports hitboxes rotating when entities rotate (this is not something Minecraft can do) - Plugin is now more optimized around having significantly more entities
1 parent 6f7230a commit 2fcf239

File tree

17 files changed

+145
-284
lines changed

17 files changed

+145
-284
lines changed

ReadMe.md

Lines changed: 77 additions & 53 deletions
Large diffs are not rendered by default.

pom.xml

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

66
<groupId>com.magmaguy</groupId>
77
<artifactId>FreeMinecraftModels</artifactId>
8-
<version>1.6.0</version>
8+
<version>2.0.0</version>
99

1010
<properties>
1111
<maven.compiler.source>17</maven.compiler.source>
@@ -86,7 +86,7 @@
8686
<dependency>
8787
<groupId>com.magmaguy</groupId>
8888
<artifactId>EasyMinecraftGoals-dist</artifactId>
89-
<version>1.19.2-SNAPSHOT</version>
89+
<version>1.19.3</version>
9090
</dependency>
9191

9292
<dependency>

src/main/java/com/magmaguy/freeminecraftmodels/FreeMinecraftModels.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import com.magmaguy.freeminecraftmodels.customentity.core.OBBHitDetection;
1111
import com.magmaguy.freeminecraftmodels.dataconverter.FileModelConverter;
1212
import com.magmaguy.freeminecraftmodels.listeners.EntityTeleportEvent;
13-
import com.magmaguy.freeminecraftmodels.utils.VersionChecker;
1413
import com.magmaguy.magmacore.MagmaCore;
1514
import com.magmaguy.magmacore.command.CommandManager;
1615
import org.bstats.bukkit.Metrics;
@@ -34,24 +33,20 @@ public void onEnable() {
3433
Bukkit.getLogger().info("Version " + this.getDescription().getVersion());
3534
MetadataHandler.PLUGIN = this;
3635
MagmaCore.onEnable();
36+
MagmaCore.checkVersionUpdate("111660");
3737
//Initialize plugin configuration files
3838
new DefaultConfig();
3939
MagmaCore.initializeImporter();
4040
OutputFolder.initializeConfig();
4141
ModelsFolder.initializeConfig();
4242
Metrics metrics = new Metrics(this, 19337);
4343
Bukkit.getPluginManager().registerEvents(new ModeledEntityEvents(), this);
44-
// Bukkit.getPluginManager().registerEvents(new LegacyHitDetection(), this);
4544
Bukkit.getPluginManager().registerEvents(new OBBHitDetection(), this);
4645
Bukkit.getPluginManager().registerEvents(new PropEntity.PropEntityEvents(), this);
47-
48-
Bukkit.getPluginManager().registerEvents(new VersionChecker.VersionCheckerEvents(), this);
4946
Bukkit.getPluginManager().registerEvents(new EntityTeleportEvent(), this);
5047
NMSManager.initializeAdapter(this);
51-
VersionChecker.checkPluginVersion();
5248
CommandManager manager = new CommandManager(this, "freeminecraftmodels");
5349
manager.registerCommand(new MountCommand());
54-
manager.registerCommand(new PropCommand());
5550
manager.registerCommand(new HitboxDebugCommand());
5651
manager.registerCommand(new ReloadCommand());
5752
manager.registerCommand(new SpawnCommand());

src/main/java/com/magmaguy/freeminecraftmodels/commands/PropCommand.java

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/main/java/com/magmaguy/freeminecraftmodels/commands/SpawnCommand.java

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.magmaguy.freeminecraftmodels.commands;
22

3+
import com.magmaguy.freeminecraftmodels.config.props.PropsConfig;
4+
import com.magmaguy.freeminecraftmodels.config.props.PropsConfigFields;
35
import com.magmaguy.freeminecraftmodels.customentity.DynamicEntity;
46
import com.magmaguy.freeminecraftmodels.customentity.StaticEntity;
57
import com.magmaguy.freeminecraftmodels.dataconverter.FileModelConverter;
@@ -19,39 +21,60 @@
1921

2022
public class SpawnCommand extends AdvancedCommand {
2123

22-
List<String> spawnTypes = List.of("static", "dynamic");
24+
List<String> spawnTypes = List.of("static", "dynamic", "prop");
2325
List<String> entityIDs = new ArrayList<>();
2426

2527
public SpawnCommand() {
2628
super(List.of("spawn"));
27-
addArgument("type", new ListStringCommandArgument(List.of("STATIC", "DYNAMIC"), "<spawn>"));
29+
addArgument("type", new ListStringCommandArgument(List.of("STATIC", "DYNAMIC", "PROP"), "<spawn>"));
2830
entityIDs = new ArrayList<>();
2931
FileModelConverter.getConvertedFileModels().values().forEach(fileModelConverter -> entityIDs.add(fileModelConverter.getID()));
3032
addArgument("model", new ListStringCommandArgument(entityIDs, "<model>"));
31-
setDescription("Spawns a custom models");
33+
setDescription("Spawns custom models or creates props");
3234
setPermission("freeminecraftmodels.*");
33-
setUsage("/fmm spawn <static/dynamic> <modelID>");
35+
setUsage("/fmm spawn <static/dynamic/prop> <modelID>");
3436
setSenderType(SenderType.PLAYER);
3537
}
3638

3739
@Override
3840
public void execute(CommandData commandData) {
3941
Player player = commandData.getPlayerSender();
40-
if (!entityIDs.contains(commandData.getStringArgument("model"))) {
42+
String modelID = commandData.getStringArgument("model");
43+
44+
if (!entityIDs.contains(modelID)) {
4145
Logger.sendMessage(commandData.getCommandSender(), "Invalid entity ID!");
4246
return;
4347
}
48+
49+
String type = commandData.getStringArgument("type").toLowerCase();
50+
51+
if (type.equals("prop")) {
52+
createProp(player, modelID);
53+
return;
54+
}
55+
56+
// Handle static and dynamic types (existing functionality)
4457
RayTraceResult rayTraceResult = player.rayTraceBlocks(300);
4558
if (rayTraceResult == null) {
4659
Logger.sendMessage(commandData.getCommandSender(), "You need to be looking at the ground to spawn a mob!");
4760
return;
4861
}
62+
4963
Location location = rayTraceResult.getHitBlock().getLocation().add(0.5, 1, 0.5);
5064
location.setPitch(0);
5165
location.setYaw(180);
52-
if (commandData.getStringArgument("type").equalsIgnoreCase("static"))
53-
StaticEntity.create(commandData.getStringArgument("model"), location);
54-
else if (commandData.getStringArgument("type").equalsIgnoreCase("dynamic"))
55-
DynamicEntity.create(commandData.getStringArgument("model"), (LivingEntity) location.getWorld().spawnEntity(location, EntityType.PIG));
66+
67+
if (type.equals("static")) {
68+
StaticEntity.create(modelID, location);
69+
} else if (type.equals("dynamic")) {
70+
DynamicEntity.create(modelID, (LivingEntity) location.getWorld().spawnEntity(location, EntityType.PIG));
71+
}
72+
}
73+
74+
private void createProp(Player player, String propFilename) {
75+
// Get or create the prop configuration, messaging is now handled in PropsConfig
76+
PropsConfigFields prop = PropsConfig.addPropConfigurationFile(propFilename, player);
77+
prop.permanentlyAddLocation(player.getLocation());
78+
Logger.sendMessage(player, "Successfully added prop!");
5679
}
57-
}
80+
}

src/main/java/com/magmaguy/freeminecraftmodels/config/ModelsFolder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import com.magmaguy.freeminecraftmodels.MetadataHandler;
55
import com.magmaguy.freeminecraftmodels.dataconverter.BoneBlueprint;
66
import com.magmaguy.freeminecraftmodels.dataconverter.FileModelConverter;
7-
import com.magmaguy.freeminecraftmodels.utils.VersionChecker;
87
import com.magmaguy.magmacore.util.Logger;
8+
import com.magmaguy.magmacore.util.VersionChecker;
99
import org.apache.commons.io.FileUtils;
1010

1111
import java.io.File;

src/main/java/com/magmaguy/freeminecraftmodels/config/props/PropsConfig.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
import com.magmaguy.magmacore.config.ConfigurationEngine;
44
import com.magmaguy.magmacore.config.CustomConfig;
55
import com.magmaguy.magmacore.config.CustomConfigFields;
6+
import com.magmaguy.magmacore.util.Logger;
67
import lombok.Getter;
78
import org.bukkit.configuration.file.FileConfiguration;
9+
import org.bukkit.entity.Player;
810

911
import java.io.File;
1012
import java.util.HashMap;
@@ -23,12 +25,20 @@ public PropsConfig() {
2325
propsConfigs.put(key, (PropsConfigFields) super.getCustomConfigFieldsHashMap().get(key));
2426
}
2527

26-
public static PropsConfigFields addPropConfigurationFile(String propFilename) {
27-
PropsConfig.getPropsConfigs().put(propFilename, new PropsConfigFields(propFilename, true));
28-
PropsConfigFields newProp = PropsConfig.getPropsConfigs().get(propFilename);
29-
propsConfigs.put(propFilename, newProp);
30-
INSTANCE.initialize(newProp);
31-
return newProp;
28+
public static PropsConfigFields addPropConfigurationFile(String propFilename, Player player) {
29+
if (!propsConfigs.containsKey(propFilename)) {
30+
PropsConfigFields newProp = new PropsConfigFields(propFilename, true);
31+
propsConfigs.put(propFilename, newProp);
32+
INSTANCE.initialize(newProp);
33+
34+
// Only show this message if a new config was created
35+
Logger.sendMessage(player, "Created new prop config file at ~/plugins/FreeMinecraftModels/props/" + propFilename + ".yml");
36+
return newProp;
37+
} else {
38+
// If the config already exists, inform the user where they can edit the values
39+
Logger.sendMessage(player, "Using existing prop config. You can edit properties at ~/plugins/FreeMinecraftModels/props/" + propFilename + ".yml");
40+
return propsConfigs.get(propFilename);
41+
}
3242
}
3343

3444
private void initialize(CustomConfigFields customConfigFields) {
@@ -51,5 +61,4 @@ private void initialize(CustomConfigFields customConfigFields) {
5161
//Store for use by the plugin
5262
addCustomConfigFields(file.getName(), customConfigFields);
5363
}
54-
55-
}
64+
}

src/main/java/com/magmaguy/freeminecraftmodels/customentity/DynamicEntity.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.magmaguy.freeminecraftmodels.MetadataHandler;
55
import com.magmaguy.freeminecraftmodels.customentity.core.ModeledEntityInterface;
66
import com.magmaguy.freeminecraftmodels.customentity.core.OBBHitDetection;
7-
import com.magmaguy.freeminecraftmodels.customentity.core.OrientedBoundingBox;
87
import com.magmaguy.freeminecraftmodels.customentity.core.RegisterModelEntity;
98
import com.magmaguy.freeminecraftmodels.dataconverter.FileModelConverter;
109
import com.magmaguy.magmacore.util.AttributeManager;
@@ -18,7 +17,6 @@
1817
import org.bukkit.entity.LivingEntity;
1918
import org.bukkit.entity.Player;
2019
import org.bukkit.persistence.PersistentDataType;
21-
import org.bukkit.util.BoundingBox;
2220
import org.checkerframework.checker.nullness.qual.Nullable;
2321

2422
import java.util.ArrayList;
@@ -32,11 +30,12 @@ public class DynamicEntity extends ModeledEntity implements ModeledEntityInterfa
3230
@Getter
3331
private final String name = "default";
3432
boolean oneTimeDamageWarning = false;
33+
int counter = 0;
3534
// Contact damage detection is integrated into the entity's internal clock
3635
// Contact damage properties
3736
@Getter
3837
@Setter
39-
private boolean damagesOnContact = true;
38+
private boolean damagesOnContact = false;
4039
@Getter
4140
private int customDamage = 1;
4241

@@ -117,8 +116,8 @@ private void syncSkeletonWithEntity() {
117116
getSkeleton().setCurrentHeadPitch(livingEntity.getEyeLocation().getPitch());
118117
getSkeleton().setCurrentHeadYaw(livingEntity.getEyeLocation().getYaw());
119118

120-
//todo: might want to run every other tick for performance
121-
if (damagesOnContact) checkPlayerCollisions();
119+
if (damagesOnContact && counter % 2 == 0) checkPlayerCollisions();
120+
counter++;
122121
}
123122

124123
@Override
@@ -175,7 +174,7 @@ private void checkPlayerCollisions() {
175174

176175
// Check for nearby players (within 5 blocks)
177176
List<Player> nearbyPlayers = livingEntity.getWorld().getPlayers().stream()
178-
.filter(player -> player.getLocation().distanceSquared(livingEntity.getLocation()) < 25)
177+
.filter(player -> player.getLocation().distanceSquared(livingEntity.getLocation()) < Math.pow(10, 2))
179178
.collect(Collectors.toList());
180179

181180
// For each nearby player, check collision and apply damage if colliding
@@ -199,14 +198,8 @@ private void checkPlayerCollisions() {
199198
* Checks if a player is colliding with this entity
200199
*/
201200
private boolean isPlayerColliding(Player player) {
202-
// Get fresh OBB for entity
203-
OrientedBoundingBox entityOBB = OrientedBoundingBox.createOBB(this);
204-
205-
// Get player's bounding box
206-
BoundingBox playerBB = player.getBoundingBox();
207-
208201
// Check for collision
209-
return getObbHitbox().isAABBCollidingWithOBB(playerBB, entityOBB);
202+
return getObbHitbox().isAABBCollidingWithOBB(player.getBoundingBox(), getObbHitbox());
210203
}
211204

212205
}

src/main/java/com/magmaguy/freeminecraftmodels/customentity/ModeledEntity.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.bukkit.entity.Player;
1616
import org.bukkit.entity.TextDisplay;
1717
import org.bukkit.persistence.PersistentDataType;
18-
import org.joml.Vector3d;
1918

2019
import java.util.ArrayList;
2120
import java.util.HashSet;
@@ -100,8 +99,7 @@ public OrientedBoundingBox getObbHitbox() {
10099

101100
public void tick() {
102101
getSkeleton().transform();
103-
Location location = getLocation();
104-
getObbHitbox().setCenter(new Vector3d(location.getX(), location.getY(), location.getZ()));
102+
getObbHitbox().update(getLocation());
105103
if (animationManager != null)
106104
animationManager.tick();
107105
//overriden by extending classes

src/main/java/com/magmaguy/freeminecraftmodels/customentity/core/Bone.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.magmaguy.freeminecraftmodels.config.DefaultConfig;
44
import com.magmaguy.freeminecraftmodels.dataconverter.BoneBlueprint;
55
import com.magmaguy.freeminecraftmodels.thirdparty.Floodgate;
6-
import com.magmaguy.freeminecraftmodels.utils.VersionChecker;
6+
import com.magmaguy.magmacore.util.VersionChecker;
77
import lombok.Getter;
88
import org.bukkit.Color;
99
import org.bukkit.entity.ArmorStand;

0 commit comments

Comments
 (0)