Skip to content

Commit

Permalink
Allow 3-dimensional offsets in PlayEffect
Browse files Browse the repository at this point in the history
Useful for things like red_dust RGB colors 😸
The meta is weird.
  • Loading branch information
Morphan1 committed Jul 10, 2015
1 parent 376bbef commit f5beed2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
Expand Up @@ -1891,7 +1891,7 @@ public void registerCoreMembers() {

// <--[command]
// @Name PlayEffect
// @Syntax playeffect [<location>|...] [effect:<name>] (data:<#.#>) (visibility:<#.#>) (qty:<#>) (offset:<#.#>) (targets:<player>|...)
// @Syntax playeffect [<location>|...] [effect:<name>] (data:<#.#>) (visibility:<#.#>) (qty:<#>) (offset:<#.#>,<#.#>,<#.#>) (targets:<player>|...)
// @Required 2
// @Stable stable
// @Short Plays a visible or audible effect at the location.
Expand All @@ -1906,7 +1906,7 @@ public void registerCoreMembers() {
// TODO: Document Command Details
// -->
registerCoreMember(PlayEffectCommand.class,
"PLAYEFFECT", "playeffect [<location>|...] [effect:<name>] (data:<#.#>) (visibility:<#.#>) (qty:<#>) (offset:<#.#>) (targets:<player>|...)", 2);
"PLAYEFFECT", "playeffect [<location>|...] [effect:<name>] (data:<#.#>) (visibility:<#.#>) (qty:<#>) (offset:<#.#>,<#.#>,<#.#>) (targets:<player>|...)", 2);


// <--[command]
Expand Down
Expand Up @@ -161,7 +161,15 @@ else if (!scriptEntry.hasObject("offset")
&& arg.matchesPrimitive(aH.PrimitiveType.Double)
&& arg.matchesPrefix("offset", "o")) {

scriptEntry.addObject("offset", arg.asElement());
double offset = arg.asElement().asDouble();
scriptEntry.addObject("offset", new dLocation(null, offset, offset, offset));
}

else if (!scriptEntry.hasObject("offset")
&& arg.matchesArgumentType(dLocation.class)
&& arg.matchesPrefix("offset", "o")) {

scriptEntry.addObject("offset", arg.asType(dLocation.class));
}

else if (!scriptEntry.hasObject("targets")
Expand All @@ -182,7 +190,7 @@ else if (!scriptEntry.hasObject("targets")
scriptEntry.defaultObject("data", new Element(0));
scriptEntry.defaultObject("radius", new Element(15));
scriptEntry.defaultObject("qty", new Element(1));
scriptEntry.defaultObject("offset", new Element(0.5));
scriptEntry.defaultObject("offset", new dLocation(null, 0.5, 0.5, 0.5));

// Check to make sure required arguments have been filled

Expand All @@ -207,7 +215,7 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
Element radius = scriptEntry.getElement("radius");
Element data = scriptEntry.getElement("data");
Element qty = scriptEntry.getElement("qty");
Element offset = scriptEntry.getElement("offset");
dLocation offset = scriptEntry.getdObject("offset");

// Report to dB
dB.report(scriptEntry, getName(), (effect != null ? aH.debugObj("effect", effect.name()) :
Expand All @@ -218,8 +226,7 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
radius.debug() +
data.debug() +
qty.debug() +
offset.debug() +
(effect != null ? "" : offset.debug()));
offset.debug());

for (dLocation location : locations) {
// Slightly increase the location's Y so effects don't seem to come out of the ground
Expand All @@ -241,7 +248,9 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

// Play a ParticleEffect
else if (particleEffect != null) {
float os = offset.asFloat();
float osX = (float) offset.getX();
float osY = (float) offset.getY();
float osZ = (float) offset.getZ();
List<Player> players = new ArrayList<Player>();
if (targets == null) {
float rad = radius.asFloat();
Expand All @@ -256,15 +265,17 @@ else if (particleEffect != null) {
if (player.isValid() && player.isOnline()) players.add(player.getPlayerEntity());
}
PacketPlayOutWorldParticles o = new PacketPlayOutWorldParticles(particleEffect.effect, false, (float) location.getX(),
(float) location.getY(), (float) location.getZ(), os, os, os, data.asFloat(), qty.asInt());
(float) location.getY(), (float) location.getZ(), osX, osY, osZ, data.asFloat(), qty.asInt());
for (Player player : players) {
((CraftPlayer) player).getHandle().playerConnection.sendPacket(o);
}
}

// Play an iconcrack (item break) effect
else {
float os = offset.asFloat();
float osX = (float) offset.getX();
float osY = (float) offset.getY();
float osZ = (float) offset.getZ();
List<Player> players = new ArrayList<Player>();
if (targets == null) {
float rad = radius.asFloat();
Expand All @@ -279,7 +290,7 @@ else if (particleEffect != null) {
if (player.isValid() && player.isOnline()) players.add(player.getPlayerEntity());
}
PacketPlayOutWorldParticles o = new PacketPlayOutWorldParticles(EnumParticle.ITEM_CRACK, false, (float) location.getX(),
(float) location.getY(), (float) location.getZ(), os, os, os, data.asFloat(), qty.asInt(),
(float) location.getY(), (float) location.getZ(), osX, osY, osZ, data.asFloat(), qty.asInt(),
iconcrack.asInt(), iconcrack.asInt()); // TODO: ???
for (Player player : players) {
((CraftPlayer) player).getHandle().playerConnection.sendPacket(o);
Expand Down

0 comments on commit f5beed2

Please sign in to comment.