Skip to content

Commit

Permalink
Added /spawnparticle and dimension argument to /playsound
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro270707 committed Mar 26, 2024
1 parent 8224a38 commit 7a32feb
Show file tree
Hide file tree
Showing 23 changed files with 351 additions and 68 deletions.
4 changes: 3 additions & 1 deletion output/production/commander-bta.main/commander.accesswidener
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
accessWidener v2 named
accessible method net/minecraft/client/gui/Gui drawRect (IIIII)V
accessible method net/minecraft/client/gui/Gui drawRectWidthHeight (IIIII)V
accessible method net/minecraft/client/gui/Gui drawRectWidthHeight (IIIII)V
accessible field net/minecraft/client/sound/SoundPool nameToSoundPoolEntriesMapping Ljava/util/Map;
accessible field net/minecraft/client/sound/SoundManager soundPoolSounds Lnet/minecraft/client/sound/SoundPool;
4 changes: 2 additions & 2 deletions output/production/commander-bta.main/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "commander",
"version": "1.3.0",
"version": "1.3.0.1",

"name": "Commander",
"description": "This mod overhauls the command system.",
Expand All @@ -13,7 +13,7 @@
"sources": "https://github.com/Pedro270707/commander-bta"
},

"license": "CC0-1.0",
"license": "GPL-3.0",

"environment": "*",
"entrypoints": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ argument_types.commander.dimension.invalid_dimension=Invalid dimension ID
argument_types.commander.biome.invalid_biome=Invalid biome ID
argument_types.commander.damage_type.invalid_damage_type=Invalid damage type ID
argument_types.commander.gamerule.invalid_value=Invalid game rule value
argument_types.commander.sound_type.invalid_sound_type=Invalid sound type
argument_types.commander.sound_category.invalid_sound_category=Invalid sound category
argument_types.commander.entity.invalid_selector.single_player_only=Selector includes more than one entity, but command only accepts a single player as an argument
argument_types.commander.entity.invalid_selector.single_entity_only=Selector includes more than one entity, but command only accepts a single entity as an argument
argument_types.commander.entity.invalid_selector.player_only=Selector includes non-player entities, but command only accepts players as an argument
Expand Down Expand Up @@ -155,4 +157,7 @@ commands.commander.testfor.block.failure=The two blocks are not equal
commands.commander.damage.success_single=Damaged %s entity
commands.commander.damage.success_multiple=Damaged %s entities
commands.commander.heal.success_single=Healed %s entity
commands.commander.heal.success_multiple=Healed %s entities
commands.commander.heal.success_multiple=Healed %s entities
commands.commander.playsound.success=Played sound %s in category %s at %s, %s, %s
commands.commander.playsound.exception_failure=Could not play sound %s
commands.commander.spawnparticle.success=Spawned particle %s at %s, %s, %s
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

import net.minecraft.client.Minecraft;
import net.minecraft.core.entity.player.EntityPlayer;
import net.minecraft.core.lang.I18n;
import net.minecraft.core.net.command.ClientCommandHandler;
import net.minecraft.core.net.command.ClientPlayerCommandSender;
import net.minecraft.core.net.command.CommandHandler;
import net.minecraft.core.net.command.CommandSender;
import net.minecraft.core.sound.SoundCategory;
Expand Down Expand Up @@ -147,6 +144,30 @@ public boolean playSound(String sound, SoundCategory category, float x, float y,
return true;
}

@Override
public boolean playSound(String sound, SoundCategory category, float x, float y, float z, float volume, float pitch, int dimension) {
return dimension == this.mc.theWorld.dimension.id && this.playSound(sound, category, x, y, z, volume, pitch);
}

@Override
public void addParticle(String particle, double x, double y, double z, double motionX, double motionY, double motionZ) {
this.addParticle(particle, x, y, z, motionX, motionY, motionZ, null);
}

@Override
public void addParticle(String particle, double x, double y, double z, double motionX, double motionY, double motionZ, @Nullable Double maxDistance) {
if (maxDistance == null) {
this.mc.renderGlobal.addParticle(particle, x, y, z, motionX, motionY, motionZ);
} else {
this.mc.renderGlobal.addParticle(particle, x, y, z, motionX, motionY, motionZ, maxDistance);
}
}

@Override
public void addParticle(String particle, double x, double y, double z, double motionX, double motionY, double motionZ, @Nullable Double maxDistance, int dimension) {
if (dimension == this.mc.theWorld.dimension.id) this.addParticle(particle, x, y, z, motionX, motionY, motionZ, maxDistance);
}

@Override
public String getName() {
return this.mc.thePlayer.username;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public void init() {
DamageCommand.register(DISPATCHER);
HealCommand.register(DISPATCHER);
PlaySoundCommand.register(DISPATCHER);
SpawnParticleCommand.register(DISPATCHER);

if (this.isServer) {
StopCommand.register(DISPATCHER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import net.minecraft.core.net.command.CommandSender;
import net.minecraft.core.sound.SoundCategory;
import net.minecraft.core.util.phys.Vec3d;
import net.minecraft.core.world.Dimension;
import net.minecraft.core.world.World;
import net.pedroricardo.commander.content.helpers.DoublePos;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;
Expand Down Expand Up @@ -59,6 +61,12 @@ default void sendTranslatableMessage(EntityPlayer player, String message, Object

boolean playSound(String sound, SoundCategory category, float x, float y, float z, float volume, float pitch);

boolean playSound(String sound, SoundCategory category, float x, float y, float z, float volume, float pitch, int dimension);

void addParticle(String particle, double x, double y, double z, double motionX, double motionY, double motionZ);
void addParticle(String particle, double x, double y, double z, double motionX, double motionY, double motionZ, @Nullable Double maxDistance);
void addParticle(String particle, double x, double y, double z, double motionX, double motionY, double motionZ, @Nullable Double maxDistance, int dimension);

String getName();

@Deprecated CommandHandler getCommandHandler();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import net.minecraft.core.net.command.CommandHandler;
import net.minecraft.core.net.command.CommandSender;
import net.minecraft.core.net.command.ConsoleCommandSender;
import net.minecraft.core.net.command.ServerCommandHandler;
import net.minecraft.core.net.packet.Packet3Chat;
import net.minecraft.core.net.packet.Packet62PlaySoundDirect;
import net.minecraft.core.net.packet.Packet63SpawnParticleEffect;
import net.minecraft.core.sound.SoundCategory;
import net.minecraft.core.sound.SoundTypes;
import net.minecraft.core.util.helper.AES;
Expand Down Expand Up @@ -121,6 +123,31 @@ public boolean playSound(String sound, SoundCategory category, float x, float y,
return true;
}

@Override
public boolean playSound(String sound, SoundCategory category, float x, float y, float z, float volume, float pitch, int dimension) {
int soundId = SoundTypes.getSoundId(sound);
if (soundId < 0) return false;
this.server.playerList.sendPacketToPlayersAroundPoint(x, y, z, 128.0, dimension, new Packet62PlaySoundDirect(soundId, category, x, y, z, volume, pitch));
return true;
}

@Override
public void addParticle(String particle, double x, double y, double z, double motionX, double motionY, double motionZ) {
this.addParticle(particle, x, y, z, motionX, motionY, motionZ, 16.0);
}

@Override
public void addParticle(String particle, double x, double y, double z, double motionX, double motionY, double motionZ, @Nullable Double maxDistance) {
for (Dimension dimension : Dimension.getDimensionList().values()) {
this.addParticle(particle, x, y, z, motionX, motionY, motionZ, maxDistance, dimension.id);
}
}

@Override
public void addParticle(String particle, double x, double y, double z, double motionX, double motionY, double motionZ, @Nullable Double maxDistance, int dimension) {
this.server.playerList.sendPacketToPlayersAroundPoint(x, y, z, maxDistance == null ? 16.0 : maxDistance, dimension, new Packet63SpawnParticleEffect(particle, x, y, z, motionX, motionY, motionZ));
}

@Override
public String getName() {
return "Server";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.core.net.command.ServerPlayerCommandSender;
import net.minecraft.core.net.packet.Packet3Chat;
import net.minecraft.core.net.packet.Packet62PlaySoundDirect;
import net.minecraft.core.net.packet.Packet63SpawnParticleEffect;
import net.minecraft.core.sound.SoundCategory;
import net.minecraft.core.sound.SoundTypes;
import net.minecraft.core.util.helper.AES;
Expand All @@ -16,6 +17,7 @@
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.entity.player.EntityPlayerMP;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -123,6 +125,31 @@ public boolean playSound(String sound, SoundCategory category, float x, float y,
return true;
}

@Override
public boolean playSound(String sound, SoundCategory category, float x, float y, float z, float volume, float pitch, int dimension) {
int soundId = SoundTypes.getSoundId(sound);
if (soundId < 0) return false;
this.server.playerList.sendPacketToPlayersAroundPoint(x, y, z, 128.0, dimension, new Packet62PlaySoundDirect(soundId, category, x, y, z, volume, pitch));
return true;
}

@Override
public void addParticle(String particle, double x, double y, double z, double motionX, double motionY, double motionZ) {
this.addParticle(particle, x, y, z, motionX, motionY, motionZ, 16.0);
}

@Override
public void addParticle(String particle, double x, double y, double z, double motionX, double motionY, double motionZ, @Nullable Double maxDistance) {
for (Dimension dimension : Dimension.getDimensionList().values()) {
this.addParticle(particle, x, y, z, motionX, motionY, motionZ, maxDistance, dimension.id);
}
}

@Override
public void addParticle(String particle, double x, double y, double z, double motionX, double motionY, double motionZ, @Nullable Double maxDistance, int dimension) {
this.server.playerList.sendPacketToPlayersAroundPoint(x, y, z, maxDistance == null ? 16.0 : maxDistance, dimension, new Packet63SpawnParticleEffect(particle, x, y, z, motionX, motionY, motionZ));
}

@Override
public String getName() {
return this.player.username;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package net.pedroricardo.commander.content.arguments;

import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import net.minecraft.core.util.phys.Vec3d;
import net.pedroricardo.commander.content.CommanderCommandSource;
import net.pedroricardo.commander.content.exceptions.CommanderExceptions;
import net.pedroricardo.commander.content.helpers.DoubleCoordinate;
import net.pedroricardo.commander.content.helpers.DoublePos;

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.CompletableFuture;

public class PositionArgumentType implements ArgumentType<DoublePos> {
private static final List<String> EXAMPLES = Arrays.asList("~ ~ ~", "0 0 0", "~ ~60 ~", "~-20 ~10 ~-25.5");

public static PositionArgumentType pos() {
return new PositionArgumentType();
}

@Override
public DoublePos parse(StringReader reader) throws CommandSyntaxException {
int i = reader.getCursor();
DoubleCoordinate x = DoubleCoordinate.parse(reader);
if (!reader.canRead() || reader.peek() != ' ') {
if (reader.peek() == 'f' || reader.peek() == 'd') {
reader.skip();
if (!reader.canRead() || reader.peek() != ' ') {
reader.setCursor(i);
throw CommanderExceptions.incomplete().createWithContext(reader);
}
} else {
reader.setCursor(i);
throw CommanderExceptions.incomplete().createWithContext(reader);
}
}
reader.skip();
DoubleCoordinate y = DoubleCoordinate.parse(reader);
if (!reader.canRead() || reader.peek() != ' ') {
if (reader.peek() == 'f' || reader.peek() == 'd') {
reader.skip();
if (!reader.canRead() || reader.peek() != ' ') {
reader.setCursor(i);
throw CommanderExceptions.incomplete().createWithContext(reader);
}
} else {
reader.setCursor(i);
throw CommanderExceptions.incomplete().createWithContext(reader);
}
}
reader.skip();
DoubleCoordinate z = DoubleCoordinate.parse(reader);
return new DoublePos(x, y, z);
}

@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
String string = builder.getRemaining();
Vec3d coordinates = ((CommanderCommandSource)context.getSource()).getCoordinates(true);

if (coordinates == null) return builder.buildFuture();

if (string.isEmpty()) {
coordinates.xCoord = roundToSixDecimals(coordinates.xCoord);
coordinates.yCoord = roundToSixDecimals(coordinates.yCoord);
coordinates.zCoord = roundToSixDecimals(coordinates.zCoord);
String allCoordinates = coordinates.xCoord + " " + coordinates.yCoord + " " + coordinates.zCoord;
try {
this.parse(new StringReader(allCoordinates));
builder.suggest(String.valueOf(coordinates.xCoord));
builder.suggest(coordinates.xCoord + " " + coordinates.yCoord);
builder.suggest(allCoordinates);
} catch (CommandSyntaxException ignored) {}
} else {
String[] strings = string.split(" ");
String allCoordinates;
switch (strings.length) {
case 1:
allCoordinates = strings[0] + " " + coordinates.yCoord + " " + coordinates.zCoord;
try {
this.parse(new StringReader(allCoordinates));
builder.suggest(strings[0] + " " + coordinates.yCoord);
builder.suggest(allCoordinates);
} catch (CommandSyntaxException ignored) {}
break;
case 2:
allCoordinates = strings[0] + " " + strings[1] + " " + coordinates.zCoord;
try {
this.parse(new StringReader(allCoordinates));
builder.suggest(allCoordinates);
} catch (CommandSyntaxException ignored) {}
break;
}
}
return builder.buildFuture();
}

private static double roundToSixDecimals(double value) {
DecimalFormat df = new DecimalFormat("#.######", DecimalFormatSymbols.getInstance(Locale.ROOT));
return Double.parseDouble(df.format(value));
}

@Override
public Collection<String> getExamples() {
return EXAMPLES;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import net.minecraft.core.lang.I18n;
import net.minecraft.core.sound.SoundTypes;
import net.pedroricardo.commander.CommanderHelper;
import net.pedroricardo.commander.content.CommanderCommandSource;

import java.util.Arrays;
import java.util.Collection;
Expand Down
Loading

0 comments on commit 7a32feb

Please sign in to comment.