Skip to content
This repository was archived by the owner on Feb 19, 2019. It is now read-only.

Commit 3c2b675

Browse files
committed
Created SpawnParticleEvent
1 parent 48f529a commit 3c2b675

File tree

3 files changed

+170
-0
lines changed

3 files changed

+170
-0
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
* Copyright 2018 ImpactDevelopment
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package clientapi.event.defaults.game.render;
18+
19+
import me.zero.alpine.type.Cancellable;
20+
21+
/**
22+
* Called when {@code ParticleManager#spawnEffectParticle} is invoked.
23+
* If cancelled, the particle is not created and therefore does not
24+
* get spawned.
25+
*
26+
* @author Brady
27+
* @since 4/10/2018 3:25 PM
28+
*/
29+
public final class SpawnParticleEvent extends Cancellable {
30+
31+
/**
32+
* The Particle ID of the particle being spawned
33+
*/
34+
private final int particleID;
35+
36+
/**
37+
* The X coordinate of the particle being spawned
38+
*/
39+
private final double x;
40+
41+
/**
42+
* The Y coordinate of the particle being spawned
43+
*/
44+
private final double y;
45+
46+
/**
47+
* The Z coordinate of the particle being spawned
48+
*/
49+
private final double z;
50+
51+
/**
52+
* The X speed of the particle being spawned++++
53+
*/
54+
private final double speedX;
55+
56+
/**
57+
* The Y speed of the particle being spawned
58+
*/
59+
private final double speedY;
60+
61+
/**
62+
* The Z speed of the particle being spawned
63+
*/
64+
private final double speedZ;
65+
66+
public SpawnParticleEvent(int particleID, double x, double y, double z, double speedX, double speedY, double speedZ) {
67+
this.particleID = particleID;
68+
this.x = x;
69+
this.y = y;
70+
this.z = z;
71+
this.speedX = speedX;
72+
this.speedY = speedY;
73+
this.speedZ = speedZ;
74+
}
75+
76+
/**
77+
* @return The Particle ID of the particle being spawned
78+
*/
79+
public final int getParticleID() {
80+
return this.particleID;
81+
}
82+
83+
/**
84+
* @return The X coordinate of the particle being spawned
85+
*/
86+
public final double getX() {
87+
return this.x;
88+
}
89+
90+
/**
91+
* @return The Y coordinate of the particle being spawned
92+
*/
93+
public final double getY() {
94+
return this.y;
95+
}
96+
97+
/**
98+
* @return The Z coordinate of the particle being spawned
99+
*/
100+
public final double getZ() {
101+
return this.z;
102+
}
103+
104+
/**
105+
* @return The X speed of the particle being spawned
106+
*/
107+
public final double getSpeedX() {
108+
return this.speedX;
109+
}
110+
111+
/**
112+
* @return The Y speed of the particle being spawned
113+
*/
114+
public final double getSpeedY() {
115+
return this.speedY;
116+
}
117+
118+
/**
119+
* @return The Z speed of the particle being spawned
120+
*/
121+
public final double getSpeedZ() {
122+
return this.speedZ;
123+
}
124+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2018 ImpactDevelopment
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package clientapi.load.mixin;
18+
19+
import clientapi.ClientAPI;
20+
import clientapi.event.defaults.game.render.SpawnParticleEvent;
21+
import net.minecraft.client.particle.IParticleFactory;
22+
import net.minecraft.client.particle.Particle;
23+
import net.minecraft.client.particle.ParticleManager;
24+
import net.minecraft.world.World;
25+
import org.spongepowered.asm.mixin.Mixin;
26+
import org.spongepowered.asm.mixin.injection.At;
27+
import org.spongepowered.asm.mixin.injection.Redirect;
28+
29+
/**
30+
* @author Brady
31+
* @since 4/10/2018 9:54 PM
32+
*/
33+
@Mixin(ParticleManager.class)
34+
public class MixinParticleManager {
35+
36+
@Redirect(method = "spawnEffectParticle", at = @At(value = "INVOKE", target = "net/minecraft/client/particle/IParticleFactory.createParticle(ILnet/minecraft/world/World;DDDDDD[I)Lnet/minecraft/client/particle/Particle;"))
37+
private Particle spawnParticle(IParticleFactory particleFactory, int particleID, World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double xSpeedIn, double ySpeedIn, double zSpeedIn, int... parameters) {
38+
SpawnParticleEvent event = new SpawnParticleEvent(particleID, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn);
39+
ClientAPI.EVENT_BUS.post(event);
40+
if (event.isCancelled())
41+
return null;
42+
43+
return particleFactory.createParticle(particleID, worldIn, xCoordIn, yCoordIn, zCoordIn, xSpeedIn, ySpeedIn, zSpeedIn, parameters);
44+
}
45+
}

src/main/resources/mixins.capi.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"MixinNettyPacketDecoder",
2424
"MixinNettyPacketEncoder",
2525
"MixinNetworkManager",
26+
"MixinParticleManager",
2627
"MixinProfiler",
2728
"MixinRender",
2829
"MixinRenderItem",

0 commit comments

Comments
 (0)