Skip to content

Commit 4b6b803

Browse files
v3.1.0
Fixed the data on Pokemons
1 parent dca9aa0 commit 4b6b803

File tree

5 files changed

+96
-18
lines changed

5 files changed

+96
-18
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
.idea/
44
.gradle/
55
build/
6-
run/
6+
run/
7+
*.jar

build.gradle

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
buildscript {
2+
repositories {
3+
jcenter()
4+
maven {
5+
name = "forge"
6+
url = "http://files.minecraftforge.net/maven"
7+
}
8+
}
9+
dependencies {
10+
classpath "net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT"
11+
}
12+
}
13+
114
plugins {
215
id "maven"
316
id "org.jetbrains.kotlin.jvm" version "1.2.51"
@@ -12,8 +25,16 @@ if (!isJitpack) {
1225
apply plugin: "flavor.pie.promptsign"
1326
}
1427

28+
apply plugin: "net.minecraftforge.gradle.forge"
29+
1530
group "de.randombyte"
16-
version "3.0.0"
31+
version "3.1.0"
32+
33+
minecraft {
34+
version = "1.12.2-14.23.5.2768"
35+
runDir = "run"
36+
mappings = "snapshot_20171003"
37+
}
1738

1839
repositories {
1940
jcenter()
@@ -32,6 +53,7 @@ dependencies {
3253
kapt "org.spongepowered:spongeapi:7.0.0"
3354
shadow("com.github.randombyte-developer.kosp:kosp:v2.2.3") { transitive = false }
3455
shadow "org.bstats:bstats-sponge:1.2"
56+
compile files("libs/Pixelmon-1.12.2-7.0.1-server.jar")
3557
}
3658

3759
shadowJar {
@@ -44,6 +66,7 @@ shadowJar {
4466
classifier = null // Remove "-all" suffix from output file name
4567
}
4668
build.dependsOn shadowJar
69+
reobfJar.dependsOn shadowJar
4770
install.dependsOn shadowJar
4871
if (!isJitpack) {
4972
signArchives.dependsOn shadowJar

src/main/kotlin/de/randombyte/entityparticles/EntityParticles.kt

+6-13
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import de.randombyte.entityparticles.data.EntityParticlesKeys.IS_REMOVER
1313
import de.randombyte.entityparticles.data.EntityParticlesKeys.PARTICLE_ID
1414
import de.randombyte.entityparticles.data.ParticleData
1515
import de.randombyte.entityparticles.data.RemoverItemData
16+
import de.randombyte.entityparticles.data.particleId
1617
import de.randombyte.kosp.config.ConfigManager
1718
import de.randombyte.kosp.extensions.executeAsConsole
1819
import de.randombyte.kosp.extensions.orNull
@@ -68,13 +69,16 @@ class EntityParticles @Inject constructor(
6869
internal companion object {
6970
const val ID = "entity-particles"
7071
const val NAME = "EntityParticles"
71-
const val VERSION = "3.0.0"
72+
const val VERSION = "3.1.0"
7273
const val AUTHOR = "RandomByte"
7374

7475
const val ROOT_PERMISSION = ID
7576

7677
const val PARTICLE_ID_ARG = "particleId"
7778
const val PLAYER_ARG = "player"
79+
80+
const val PIXELMON_ID = "pixelmon"
81+
const val PIXELMON_PARTICLE_TAG_KEY = "$ID:particle"
7882
}
7983

8084
private val configManager = ConfigManager(
@@ -172,7 +176,7 @@ class EntityParticles @Inject constructor(
172176
("entityParticles set ${targetEntity.location.extent.uniqueId} ${targetEntity.uniqueId} $particleId").executeAsConsole()
173177
}
174178
isRemover -> {
175-
if (!targetEntity.get(EntityParticlesKeys.PARTICLE_ID).isPresent) return
179+
if (targetEntity.particleId == null) return
176180
player.setItemInHand(HandTypes.MAIN_HAND, itemInHand.setAmount(itemInHand.quantity - 1))
177181
("entityParticles set ${targetEntity.location.extent.uniqueId} ${targetEntity.uniqueId} nothing").executeAsConsole()
178182
}
@@ -280,16 +284,5 @@ class EntityParticles @Inject constructor(
280284
location.extent.spawnParticles(particleEffect, location.position.add(effect.centerOffset))
281285
}
282286

283-
private val Entity.particleId: String? get() {
284-
val id = this.get(EntityParticlesKeys.PARTICLE_ID).orNull() ?: return null
285-
val particleConfig = config.particles[id]
286-
if (particleConfig == null) {
287-
// invalid data -> remove
288-
this.remove(ParticleData::class.java)
289-
return null
290-
}
291-
return id
292-
}
293-
294287
private fun ItemStack.setAmount(amount: Int): ItemStack = apply { quantity = amount }
295288
}

src/main/kotlin/de/randombyte/entityparticles/commands/SetParticleCommand.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package de.randombyte.entityparticles.commands
33
import de.randombyte.entityparticles.Config
44
import de.randombyte.entityparticles.EntityParticles
55
import de.randombyte.entityparticles.EntityParticles.Companion.PARTICLE_ID_ARG
6-
import de.randombyte.entityparticles.data.ParticleData
6+
import de.randombyte.entityparticles.data.particleId
77
import de.randombyte.kosp.extensions.getWorld
88
import de.randombyte.kosp.extensions.orNull
99
import de.randombyte.kosp.extensions.toText
@@ -38,7 +38,7 @@ internal class SetParticleCommand(
3838
val trackedEntities = entityParticles.trackedEntities.getOrPut(entity.location.extent.uniqueId) { mutableMapOf() }
3939

4040
if (particleId == "nothing") {
41-
entity.remove(ParticleData::class.java)
41+
entity.particleId = null
4242
entity.offer(Keys.GLOWING, false)
4343

4444
trackedEntities -= (entity.uniqueId)
@@ -49,7 +49,7 @@ internal class SetParticleCommand(
4949
val particleConfig = getParticleConfig(particleId)
5050
?: throw CommandException("Particle '$particleId' is not available!".toText())
5151

52-
entity.offer(ParticleData(id = particleId, isActive = true))
52+
entity.particleId = particleId
5353

5454
if (particleConfig.glowing) {
5555
entity.offer(Keys.GLOWING, true)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package de.randombyte.entityparticles.data
2+
3+
import com.pixelmonmod.pixelmon.entities.pixelmon.Entity1Base
4+
import de.randombyte.entityparticles.EntityParticles.Companion.PIXELMON_ID
5+
import de.randombyte.entityparticles.EntityParticles.Companion.PIXELMON_PARTICLE_TAG_KEY
6+
import de.randombyte.kosp.extensions.orNull
7+
import net.minecraft.nbt.NBTTagCompound
8+
import net.minecraftforge.common.util.Constants
9+
import org.spongepowered.api.Sponge
10+
import org.spongepowered.api.entity.Entity
11+
12+
// What a hassle to get Pixelmon and the Sponge Data API working "together"
13+
14+
var Entity.particleId: String?
15+
get() {
16+
return if (Sponge.getPluginManager().isLoaded(PIXELMON_ID) && this is Entity1Base) {
17+
val persistentData = this.pokemonData.persistentData
18+
if (!persistentData.hasKey(PIXELMON_PARTICLE_TAG_KEY)) {
19+
// has to be accessed this way because of unknown issues with Sponge & Pixelmon
20+
val spongeSavedParticleId = persistentData.removeSpongeSavedParticleId()
21+
if (spongeSavedParticleId != null) {
22+
this.particleId = spongeSavedParticleId // save the ID the new way (directly with NBT)
23+
spongeSavedParticleId
24+
} else null
25+
} else {
26+
persistentData.getString(PIXELMON_PARTICLE_TAG_KEY)
27+
}
28+
} else {
29+
this.get(EntityParticlesKeys.PARTICLE_ID).orNull()
30+
}
31+
}
32+
set(id) {
33+
if (Sponge.getPluginManager().isLoaded(PIXELMON_ID) && this is Entity1Base) { // is Pixelmon entity? -> then do NBT
34+
with(this.pokemonData.persistentData) {
35+
if (id == null) {
36+
this.removeTag(PIXELMON_PARTICLE_TAG_KEY)
37+
} else {
38+
this.setString(PIXELMON_PARTICLE_TAG_KEY, id)
39+
}
40+
}
41+
} else {
42+
if (id == null) { // normal entity -> Sponge data api
43+
this.remove(EntityParticlesKeys.PARTICLE_ID)
44+
} else {
45+
this.tryOffer(ParticleData(id = id, isActive = true))
46+
}
47+
}
48+
}
49+
50+
private fun NBTTagCompound.removeSpongeSavedParticleId(): String? {
51+
val manipulatorsCompoundTag = this.getCompoundTag("SpongeData").getTagList("CustomManipulators", Constants.NBT.TAG_COMPOUND)
52+
val manipulators = manipulatorsCompoundTag.toList()
53+
54+
val particleManipulatorIndex = manipulators.indexOfFirst { (it as NBTTagCompound).getString("ManipulatorId") == "entity-particles:particle" }
55+
if (particleManipulatorIndex < 0) return null
56+
val particleManipulator = manipulators[particleManipulatorIndex]
57+
58+
manipulatorsCompoundTag.removeTag(particleManipulatorIndex) // remove old sponge data api tag
59+
60+
return (particleManipulator as NBTTagCompound).getCompoundTag("ManipulatorData").getString("Id")
61+
}

0 commit comments

Comments
 (0)