13
0
geforkt von Mirrors/Paper

SPIGOT-7868, #1463: Fix default and max power in FireworkMeta

By: Doc <nachito94@msn.com>
Dieser Commit ist enthalten in:
CraftBukkit/Spigot 2024-08-17 08:37:46 +10:00
Ursprung 71695536dd
Commit 9f0a790b3d
2 geänderte Dateien mit 20 neuen und 19 gelöschten Zeilen

Datei anzeigen

@ -8,6 +8,7 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import net.minecraft.core.component.DataComponentPatch; import net.minecraft.core.component.DataComponentPatch;
import net.minecraft.core.component.DataComponents; import net.minecraft.core.component.DataComponents;
import net.minecraft.world.item.component.FireworkExplosion; import net.minecraft.world.item.component.FireworkExplosion;
@ -43,7 +44,7 @@ class CraftMetaFirework extends CraftMetaItem implements FireworkMeta {
static final ItemMetaKey EXPLOSIONS = new ItemMetaKey("firework-effects"); static final ItemMetaKey EXPLOSIONS = new ItemMetaKey("firework-effects");
private List<FireworkEffect> effects; private List<FireworkEffect> effects;
private int power; private Integer power;
CraftMetaFirework(CraftMetaItem meta) { CraftMetaFirework(CraftMetaItem meta) {
super(meta); super(meta);
@ -78,6 +79,18 @@ class CraftMetaFirework extends CraftMetaItem implements FireworkMeta {
}); });
} }
CraftMetaFirework(Map<String, Object> map) {
super(map);
Integer power = SerializableMeta.getObject(Integer.class, map, FLIGHT.BUKKIT, true);
if (power != null) {
this.power = power;
}
Iterable<?> effects = SerializableMeta.getObject(Iterable.class, map, EXPLOSIONS.BUKKIT, true);
safelyAddEffects(effects);
}
static FireworkEffect getEffect(FireworkExplosion explosion) { static FireworkEffect getEffect(FireworkExplosion explosion) {
FireworkEffect.Builder effect = FireworkEffect.builder() FireworkEffect.Builder effect = FireworkEffect.builder()
.flicker(explosion.hasTwinkle()) .flicker(explosion.hasTwinkle())
@ -144,18 +157,6 @@ class CraftMetaFirework extends CraftMetaItem implements FireworkMeta {
} }
} }
CraftMetaFirework(Map<String, Object> map) {
super(map);
Integer power = SerializableMeta.getObject(Integer.class, map, FLIGHT.BUKKIT, true);
if (power != null) {
this.power = power;
}
Iterable<?> effects = SerializableMeta.getObject(Iterable.class, map, EXPLOSIONS.BUKKIT, true);
safelyAddEffects(effects);
}
@Override @Override
public boolean hasEffects() { public boolean hasEffects() {
return !(effects == null || effects.isEmpty()); return !(effects == null || effects.isEmpty());
@ -191,7 +192,7 @@ class CraftMetaFirework extends CraftMetaItem implements FireworkMeta {
} }
} }
itemTag.put(FIREWORKS, new Fireworks(power, effects)); itemTag.put(FIREWORKS, new Fireworks(this.getPower(), effects));
} }
static IntList addColors(List<Color> colors) { static IntList addColors(List<Color> colors) {
@ -218,7 +219,7 @@ class CraftMetaFirework extends CraftMetaItem implements FireworkMeta {
} }
boolean hasPower() { boolean hasPower() {
return power != 0; return this.power != null;
} }
@Override @Override
@ -229,7 +230,7 @@ class CraftMetaFirework extends CraftMetaItem implements FireworkMeta {
if (meta instanceof CraftMetaFirework that) { if (meta instanceof CraftMetaFirework that) {
return (hasPower() ? that.hasPower() && this.power == that.power : !that.hasPower()) return (Objects.equals(this.power, that.power))
&& (hasEffects() ? that.hasEffects() && this.effects.equals(that.effects) : !that.hasEffects()); && (hasEffects() ? that.hasEffects() && this.effects.equals(that.effects) : !that.hasEffects());
} }
@ -339,13 +340,13 @@ class CraftMetaFirework extends CraftMetaItem implements FireworkMeta {
@Override @Override
public int getPower() { public int getPower() {
return hasPower() ? this.power : 0; return hasPower() ? this.power : 1;
} }
@Override @Override
public void setPower(int power) { public void setPower(int power) {
Preconditions.checkArgument(power >= 0, "power cannot be less than zero: %s", power); Preconditions.checkArgument(power >= 0, "power cannot be less than zero: %s", power);
Preconditions.checkArgument(power < 0x80, "power cannot be more than 127: %s", power); Preconditions.checkArgument(power <= 255, "power cannot be more than 255: %s", power);
this.power = power; this.power = power;
} }
} }

Datei anzeigen

@ -66,7 +66,7 @@ import org.junit.jupiter.api.Test;
public class ItemMetaTest extends AbstractTestingBase { public class ItemMetaTest extends AbstractTestingBase {
static final int MAX_FIREWORK_POWER = 127; // Please update ItemStackFireworkTest if/when this gets changed. static final int MAX_FIREWORK_POWER = 255; // Please update ItemStackFireworkTest if/when this gets changed.
@Test @Test
public void testPowerLimitExact() { public void testPowerLimitExact() {