Skip to content

Commit

Permalink
Merge pull request #91 from alt-art/fireworks
Browse files Browse the repository at this point in the history
Add fireworks action event
  • Loading branch information
alt-art authored Mar 6, 2024
2 parents 7e55f62 + 1bf37b4 commit c6049b1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
6 changes: 5 additions & 1 deletion backend/src/components/tabs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def save_prompt(prompt_id: str, prompt: str):
async def change_personality(personality_id: str, checkboxes: list):
clear_context = "Clear context" in checkboxes
notify_minecraft = "Notify Minecraft" in checkboxes
fireworks = "Fireworks" in checkboxes
logger.info(f"Setting personality to {personality_id}")

if personality_id not in list(prompt_manager.personalities):
Expand All @@ -41,6 +42,9 @@ async def change_personality(personality_id: str, checkboxes: list):
data = json.dumps(prompt_manager.personalities[personality_id])
await ws.broadcast({"action": "new_personality", "data": data})

if fireworks:
await ws.broadcast({"action": "fireworks"})

return f"Personality setted to {personality_id}"


Expand Down Expand Up @@ -74,7 +78,7 @@ def config_tab():
),
gr.CheckboxGroup(
label="Clear context",
choices=["Clear context", "Notify Minecraft"],
choices=["Clear context", "Notify Minecraft", "Fireworks"],
container=False,
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import net.minecraft.client.Minecraft;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvents;
Expand All @@ -15,7 +17,9 @@
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.FireworkRocketEntity;
import net.minecraft.world.inventory.ChestMenu;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist;
Expand Down Expand Up @@ -454,12 +458,37 @@ public static void onPlayerJoin(PlayerEvent.PlayerLoggedInEvent event) {
if (ClientConfig.SEND_TO_CHAT.get()) {
player.sendSystemMessage(Component.nullToEmpty("Personalidade alterada!"));
}

JsonObject personality = jsonObject.getAsJsonObject("data");
String voiceID = personality.get("voice_id").getAsString();
ClientConfig.ELEVENLABS_VOICE_ID.set(voiceID);
player.level().playSound(null, player.getX(), player.getY(), player.getZ(), SoundEvents.PLAYER_LEVELUP, SoundSource.MASTER, 1.5F, 1.0F);
return null;
});

player.level().playSound(null, player.getX(), player.getY(), player.getZ(), SoundEvents.EXPERIENCE_ORB_PICKUP, SoundSource.MASTER, 1.0F, 1.0F);
wsClient.addEventListener("fireworks", jsonObject -> {
ItemStack itemStack = new ItemStack(net.minecraft.world.item.Items.FIREWORK_ROCKET);
CompoundTag fireworksTag = new CompoundTag();
fireworksTag.putFloat("Flight", 0.4F);
fireworksTag.putInt("LifeTime", 40);
fireworksTag.putInt("Life", 10);
ListTag explosions = new ListTag();
for (int i = 0; i < 3; i++) {
CompoundTag explosion = new CompoundTag();
explosion.putByte("Type", (byte) 4);
explosion.putBoolean("Flicker", Math.random() > 0.5);
explosion.putBoolean("Trail", Math.random() > 0.5);
explosion.putIntArray("Colors", new int[]{DyeColor.byId(i).getFireworkColor()});
explosions.add(explosion);
}
fireworksTag.put("Explosions", explosions);
CompoundTag NBTTag = new CompoundTag();
NBTTag.put("Fireworks", fireworksTag);
itemStack.setTag(NBTTag);
for (int i = 0; i < 10; i++) {
float angle = (i * 36) * ((float) Math.PI / 180);
FireworkRocketEntity firework = new FireworkRocketEntity(player.level(), player.getX() + Math.sin(angle) * 2, player.getY(), player.getZ() + Math.cos(angle) * 2, itemStack);
player.level().addFreshEntity(firework);
}
return null;
});

Expand Down

0 comments on commit c6049b1

Please sign in to comment.