Skip to content

Commit daeedde

Browse files
committed
Added advanced natural spawner config
1 parent 16ab4f4 commit daeedde

13 files changed

Lines changed: 119 additions & 15 deletions

File tree

NMS/v1_21_6/build.gradle

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
plugins {
2+
id 'java-library'
3+
}
4+
5+
group 'NMS:v1_21_6'
6+
7+
dependencies {
8+
implementation project(':core')
9+
implementation project(':api')
10+
compileOnly 'io.papermc.paper:paper-api:1.21.6-R0.1-SNAPSHOT'
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package github.nighter.smartspawner.v1_21_6;
2+
3+
import github.nighter.smartspawner.nms.ParticleWrapper;
4+
import org.bukkit.Particle;
5+
6+
public class ParticleInitializer {
7+
public static void init() {
8+
ParticleWrapper.VILLAGER_HAPPY = Particle.HAPPY_VILLAGER;
9+
ParticleWrapper.SPELL_WITCH = Particle.WITCH;
10+
}
11+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package github.nighter.smartspawner.v1_21_6;
2+
import org.bukkit.entity.EntityType;
3+
import github.nighter.smartspawner.nms.SpawnerWrapper;
4+
import java.util.Arrays;
5+
6+
public class SpawnerInitializer {
7+
public static void init() {
8+
SpawnerWrapper.SUPPORTED_MOBS = Arrays.stream(EntityType.values())
9+
.map(EntityType::name)
10+
.toList();
11+
}
12+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package github.nighter.smartspawner.v1_21_6;
2+
3+
import github.nighter.smartspawner.nms.TextureWrapper;
4+
import org.bukkit.entity.EntityType;
5+
6+
public class TextureInitializer {
7+
public static void init() {
8+
TextureWrapper.addVersionSpecificTexture(
9+
EntityType.ARMADILLO,
10+
"9164ed0e0ef69b0ce7815e4300b4413a4828fcb0092918543545a418a48e0c3c"
11+
);
12+
TextureWrapper.addVersionSpecificTexture(
13+
EntityType.BOGGED,
14+
"a3b9003ba2d05562c75119b8a62185c67130e9282f7acbac4bc2824c21eb95d9"
15+
);
16+
TextureWrapper.addVersionSpecificTexture(
17+
EntityType.BREEZE,
18+
"a275728af7e6a29c88125b675a39d88ae9919bb61fdc200337fed6ab0c49d65c"
19+
);
20+
TextureWrapper.addVersionSpecificTexture(
21+
EntityType.MOOSHROOM,
22+
"45603d539f666fdf0f7a0fe20b81dfef3abe6c51da34b9525a5348432c5523b2"
23+
);
24+
TextureWrapper.addVersionSpecificTexture(
25+
EntityType.SNOW_GOLEM,
26+
"1fdfd1f7538c040258be7a91446da89ed845cc5ef728eb5e690543378fcf4"
27+
);
28+
TextureWrapper.addVersionSpecificTexture(
29+
EntityType.CREAKING,
30+
"ac91c87bbe7f4c586e0f8b60f9b76d173a41daa302944531703be9ff4fd117f8"
31+
);
32+
TextureWrapper.addVersionSpecificTexture(
33+
EntityType.HAPPY_GHAST,
34+
"a1a36cb93d01675c4622dd5c8d872110911ec12c372e89afa8ba03862867f6fb"
35+
);
36+
}
37+
}

core/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ jar {
4040
from { project(':NMS:v1_20').sourceSets.main.output }
4141
from { project(':NMS:v1_21').sourceSets.main.output }
4242
from { project(':NMS:v1_21_4').sourceSets.main.output }
43+
from { project(':NMS:v1_21_6').sourceSets.main.output }
4344

4445
// destinationDirectory = file('C:\\Users\\ADMIN\\OneDrive\\Desktop\\Paper1216\\plugins\\')
4546
from sourceSets.main.output

core/src/main/java/github/nighter/smartspawner/SmartSpawner.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ private void registerListeners() {
269269

270270
// Register core listeners
271271
pm.registerEvents(pluginCompatibilityHandler, this);
272+
pm.registerEvents(naturalSpawnerListener, this);
272273
pm.registerEvents(spawnerListGUI, this);
273274
pm.registerEvents(spawnerBreakListener, this);
274275
pm.registerEvents(spawnerPlaceListener, this);

core/src/main/java/github/nighter/smartspawner/nms/VersionInitializer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ private String determineVersionPath() {
5959
// Define supported versions and their package names
6060
// Order matters: more specific versions should come first
6161
Map<String, String> supportedVersions = new LinkedHashMap<>();
62+
supportedVersions.put("1.21.6", "v1_21_6");
6263
supportedVersions.put("1.21.4", "v1_21_4");
6364
supportedVersions.put("1.21", "v1_21");
6465
supportedVersions.put("1.20", "v1_20");

core/src/main/java/github/nighter/smartspawner/spawner/interactions/destroy/SpawnerBreakListener.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void onSpawnerBreak(BlockBreakEvent event) {
7272

7373
final SpawnerData spawner = spawnerManager.getSpawnerByLocation(location);
7474

75-
if (!plugin.getConfig().getBoolean("natural_spawner.breakable", true)) {
75+
if (!plugin.getConfig().getBoolean("natural_spawner.breakable", false)) {
7676
if (spawner == null) {
7777
block.setType(Material.AIR);
7878
event.setCancelled(true);
@@ -88,22 +88,22 @@ public void onSpawnerBreak(BlockBreakEvent event) {
8888
}
8989

9090
if (spawner != null) {
91-
handleVanillaSpawnerBreak(block, spawner, player);
91+
handleSmartSpawnerBreak(block, spawner, player);
9292
plugin.getRangeChecker().stopSpawnerTask(spawner);
9393
} else {
9494
CreatureSpawner creatureSpawner = (CreatureSpawner) block.getState();
9595
if(callAPIEvent(player, block.getLocation(), 1)) {
9696
event.setCancelled(true);
9797
return;
9898
}
99-
handleSpawnerBreak(block, creatureSpawner, player);
99+
handleVanillaSpawnerBreak(block, creatureSpawner, player);
100100
}
101101

102102
event.setCancelled(true);
103103
cleanupAssociatedHopper(block);
104104
}
105105

106-
private void handleVanillaSpawnerBreak(Block block, SpawnerData spawner, Player player) {
106+
private void handleSmartSpawnerBreak(Block block, SpawnerData spawner, Player player) {
107107
Location location = block.getLocation();
108108
ItemStack tool = player.getInventory().getItemInMainHand();
109109

@@ -122,7 +122,7 @@ private void handleVanillaSpawnerBreak(Block block, SpawnerData spawner, Player
122122
}
123123
}
124124

125-
private void handleSpawnerBreak(Block block, CreatureSpawner creatureSpawner, Player player) {
125+
private void handleVanillaSpawnerBreak(Block block, CreatureSpawner creatureSpawner, Player player) {
126126
Location location = block.getLocation();
127127
ItemStack tool = player.getInventory().getItemInMainHand();
128128

@@ -131,7 +131,12 @@ private void handleSpawnerBreak(Block block, CreatureSpawner creatureSpawner, Pl
131131
}
132132

133133
EntityType entityType = creatureSpawner.getSpawnedType();
134-
ItemStack spawnerItem = spawnerItemFactory.createSpawnerItem(entityType);
134+
ItemStack spawnerItem;
135+
if (plugin.getConfig().getBoolean("natural_spawner.convert_to_smart_spawner", false)) {
136+
spawnerItem = spawnerItemFactory.createSpawnerItem(entityType);
137+
} else {
138+
spawnerItem = spawnerItemFactory.createVanillaSpawnerItem(entityType);
139+
}
135140

136141
boolean directToInventory = plugin.getConfig().getBoolean("spawner_break.direct_to_inventory", false);
137142

core/src/main/java/github/nighter/smartspawner/spawner/interactions/destroy/SpawnerExplosionListener.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ public SpawnerExplosionListener(SmartSpawner plugin) {
3232
this.hopperHandler = plugin.getHopperHandler();
3333
}
3434

35-
36-
3735
@EventHandler
3836
public void onEntityExplosion(EntityExplodeEvent event) {
3937
handleExplosion(event.blockList());
@@ -81,6 +79,9 @@ private void handleExplosion(List<Block> blockList) {
8179
}
8280
} else {
8381
// Allow vanilla spawners to be destroyed
82+
if (plugin.getConfig().getBoolean("natural_spawner.protect_from_explosions", false)) {
83+
blocksToRemove.add(block);
84+
}
8485
}
8586
} else if (block.getType() == Material.RESPAWN_ANCHOR) {
8687
if (plugin.getConfig().getBoolean("spawner_properties.default.protect_from_explosions", true)) {

core/src/main/java/github/nighter/smartspawner/spawner/item/SpawnerItemFactory.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ public ItemStack createSpawnerItem(EntityType entityType, int amount) {
239239
return spawner;
240240
}
241241

242+
public ItemStack createVanillaSpawnerItem(EntityType entityType) {
243+
return createVanillaSpawnerItem(entityType, 1);
244+
}
245+
242246
public ItemStack createVanillaSpawnerItem(EntityType entityType, int amount) {
243247
ItemStack spawner = new ItemStack(Material.SPAWNER, amount);
244248
ItemMeta meta = spawner.getItemMeta();

0 commit comments

Comments
 (0)