Make the FireworkShapes enum extensible (Closes #9486)

This commit is contained in:
LexManos committed 2023-07-14 14:01:32 -07:00
1 parent ea7f755a11
commit 0c81a71308
7 files changed
+137 -1

No files matched your search

@@ -0,0 +1,31 @@
--- a/net/minecraft/client/particle/FireworkParticles.java
+++ b/net/minecraft/client/particle/FireworkParticles.java
@@ -172,7 +_,7 @@
} else {
for(int i = 0; i < this.f_106752_.size(); ++i) {
CompoundTag compoundtag = this.f_106752_.m_128728_(i);
- if (FireworkRocketItem.Shape.m_41237_(compoundtag.m_128445_("Type")) == FireworkRocketItem.Shape.LARGE_BALL) {
+ if (FireworkRocketItem.Shape.getShape(compoundtag) == FireworkRocketItem.Shape.LARGE_BALL) {
flag1 = true;
break;
}
@@ -192,7 +_,7 @@
if (this.f_106754_ % 2 == 0 && this.f_106752_ != null && this.f_106754_ / 2 < this.f_106752_.size()) {
int k = this.f_106754_ / 2;
CompoundTag compoundtag1 = this.f_106752_.m_128728_(k);
- FireworkRocketItem.Shape fireworkrocketitem$shape = FireworkRocketItem.Shape.m_41237_(compoundtag1.m_128445_("Type"));
+ FireworkRocketItem.Shape fireworkrocketitem$shape = FireworkRocketItem.Shape.getShape(compoundtag1);
boolean flag4 = compoundtag1.m_128471_("Trail");
boolean flag2 = compoundtag1.m_128471_("Flicker");
int[] aint = compoundtag1.m_128465_("Colors");
@@ -201,6 +_,10 @@
aint = new int[]{DyeColor.BLACK.m_41070_()};
}
+ var factory = net.minecraftforge.client.FireworkShapeFactoryRegistry.get(fireworkrocketitem$shape);
+ if (factory != null)
+ factory.build(this, flag4, flag2, aint, aint1);
+ else
switch (fireworkrocketitem$shape) {
case SMALL_BALL:
default:
@@ -1,6 +1,6 @@
--- a/net/minecraft/client/particle/Particle.java
+++ b/net/minecraft/client/particle/Particle.java
@@ -226,4 +_,12 @@
@@ -226,4 +_,16 @@
public Optional<ParticleGroup> m_142654_() {
return Optional.empty();
}
@@ -11,5 +11,9 @@
+ */
+ public boolean shouldCull() {
+ return true;
+ }
+
+ public net.minecraft.world.phys.Vec3 getPos() {
+ return new net.minecraft.world.phys.Vec3(this.f_107212_, this.f_107213_, this.f_107214_);
+ }
}
@@ -0,0 +1,40 @@
--- a/net/minecraft/world/item/FireworkRocketItem.java
+++ b/net/minecraft/world/item/FireworkRocketItem.java
@@ -107,7 +_,7 @@
return itemstack;
}
- public static enum Shape {
+ public static enum Shape implements net.minecraftforge.common.IExtensibleEnum {
SMALL_BALL(0, "small_ball"),
LARGE_BALL(1, "large_ball"),
STAR(2, "star"),
@@ -131,8 +_,28 @@
return this.f_41228_;
}
+ public void save(net.minecraft.nbt.CompoundTag tag) {
+ tag.m_128344_("Type", (byte)m_41236_());
+ tag.m_128359_("forge:shape_type", name());
+ }
+
+ /** Use {getShape(ComoundTag)} */
+ @Deprecated
public static FireworkRocketItem.Shape m_41237_(int p_41238_) {
return f_41226_.apply(p_41238_);
+ }
+
+ public static FireworkRocketItem.Shape getShape(net.minecraft.nbt.CompoundTag tag) {
+ var name = tag.m_128425_("forge:shape_type", 8) ? tag.m_128461_("forge:shape_type") : null;
+ if (name == null) return m_41237_(tag.m_128445_("Type"));
+ for (var ret : values())
+ if (ret.name().equals(name))
+ return ret;
+ return SMALL_BALL;
+ }
+
+ public static Shape create(String registryName, int id, String shapeName) {
+ throw new IllegalStateException("Enum not extended");
}
}
}
@@ -0,0 +1,11 @@
--- a/net/minecraft/world/item/FireworkStarItem.java
+++ b/net/minecraft/world/item/FireworkStarItem.java
@@ -23,7 +_,7 @@
}
public static void m_41256_(CompoundTag p_41257_, List<Component> p_41258_) {
- FireworkRocketItem.Shape fireworkrocketitem$shape = FireworkRocketItem.Shape.m_41237_(p_41257_.m_128445_("Type"));
+ FireworkRocketItem.Shape fireworkrocketitem$shape = FireworkRocketItem.Shape.getShape(p_41257_);
p_41258_.add(Component.m_237115_("item.minecraft.firework_star.shape." + fireworkrocketitem$shape.m_41241_()).m_130940_(ChatFormatting.GRAY));
int[] aint = p_41257_.m_128465_("Colors");
if (aint.length > 0) {
@@ -0,0 +1,11 @@
--- a/net/minecraft/world/item/crafting/FireworkStarRecipe.java
+++ b/net/minecraft/world/item/crafting/FireworkStarRecipe.java
@@ -107,7 +_,7 @@
}
compoundtag.m_128408_("Colors", list);
- compoundtag.m_128344_("Type", (byte)fireworkrocketitem$shape.m_41236_());
+ fireworkrocketitem$shape.save(compoundtag);
return itemstack;
}
@@ -0,0 +1,35 @@
/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.client;
import java.util.HashMap;
import java.util.Map;
import org.jetbrains.annotations.Nullable;
import net.minecraft.client.particle.FireworkParticles;
import net.minecraft.world.item.FireworkRocketItem;
/**
* Keeps track of custom firework shape types, because Particle is client side only this can't be on the Shape itself.
* So sometime during your client initalization call register.
*/
public class FireworkShapeFactoryRegistry {
private static final Map<FireworkRocketItem.Shape, Factory> factories = new HashMap<>();
public static interface Factory {
void build(FireworkParticles.Starter starter, boolean trail, boolean flicker, int[] colors, int[] fadecolors);
}
public static void register(FireworkRocketItem.Shape shape, Factory factory) {
factories.put(shape, factory);
}
@Nullable
public static Factory get(FireworkRocketItem.Shape shape) {
return factories.get(shape);
}
}
@@ -76,6 +76,10 @@ public net.minecraft.client.gui.screens.Screen f_169369_ # renderables
public net.minecraft.client.model.geom.LayerDefinitions f_171106_ # OUTER_ARMOR_DEFORMATION
public net.minecraft.client.model.geom.LayerDefinitions f_171107_ # INNER_ARMOR_DEFORMATION
public net.minecraft.client.multiplayer.ClientPacketListener f_104899_ # commands
public net.minecraft.client.particle.FireworkParticles$Starter m_106767_(DDDDDD[I[IZZ)V # createParticle
public net.minecraft.client.particle.FireworkParticles$Starter m_106778_(DI[I[IZZ)V # createParticleBall
public net.minecraft.client.particle.FireworkParticles$Starter m_106785_(D[[D[I[IZZZ)V # createParticleShape
public net.minecraft.client.particle.FireworkParticles$Starter m_106793_([I[IZZ)V # createParticleBurst
public net.minecraft.client.particle.ParticleEngine m_107378_(Lnet/minecraft/core/particles/ParticleType;Lnet/minecraft/client/particle/ParticleEngine$SpriteParticleRegistration;)V # register
public net.minecraft.client.particle.ParticleEngine m_107381_(Lnet/minecraft/core/particles/ParticleType;Lnet/minecraft/client/particle/ParticleProvider;)V # register
public net.minecraft.client.particle.ParticleEngine m_272137_(Lnet/minecraft/core/particles/ParticleType;Lnet/minecraft/client/particle/ParticleProvider$Sprite;)V # register