Skip to content

Commit 20721aa

Browse files
committed
Dangerous Clipboards
- Fix old clipboard schematics causing issues #9462 - Update NBTProcessors - Update Ponder
1 parent 5f1b407 commit 20721aa

File tree

12 files changed

+56
-62
lines changed

12 files changed

+56
-62
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ registrate_version = MC1.21-1.3.0+67
3030

3131
# Ponder
3232
# https://maven.createmod.net/net/createmod/ponder/
33-
ponder_version = 1.0.64
33+
ponder_version = 1.0.66
3434

3535
# Flywheel & Vanillin
3636
# https://maven.createmod.net/dev/engine-room/flywheel/

src/main/java/com/simibubi/create/content/equipment/potatoCannon/PotatoCannonItem.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.simibubi.create.content.equipment.potatoCannon;
22

33
import java.util.List;
4-
import java.util.Optional;
54
import java.util.function.Consumer;
65
import java.util.function.Predicate;
76

@@ -56,6 +55,9 @@
5655
import net.neoforged.neoforge.client.extensions.common.IClientItemExtensions;
5756

5857
public class PotatoCannonItem extends ProjectileWeaponItem implements CustomArmPoseItem {
58+
private static final Predicate<ItemStack> AMMO_PREDICATE = s ->
59+
PotatoCannonProjectileType.getTypeForItem(GlobalRegistryAccess.getOrThrow(), s.getItem()).isPresent();
60+
5961
public PotatoCannonItem(Properties properties) {
6062
super(properties);
6163
}
@@ -67,19 +69,18 @@ public static Ammo getAmmo(Player player, ItemStack heldStack) {
6769
return null;
6870
}
6971

70-
Optional<Holder.Reference<PotatoCannonProjectileType>> optionalType = PotatoCannonProjectileType.getTypeForItem(player.level().registryAccess(), ammoStack.getItem());
71-
if (optionalType.isEmpty()) {
72-
return null;
73-
}
74-
75-
return new Ammo(ammoStack, optionalType.get().value());
72+
return PotatoCannonProjectileType.getTypeForItem(player.level().registryAccess(), ammoStack.getItem())
73+
.map(r -> new Ammo(ammoStack, r.value()))
74+
.orElse(null);
7675
}
7776

7877
@Override
79-
protected void shootProjectile(LivingEntity shooter, Projectile projectile, int index, float velocity, float inaccuracy, float angle, @Nullable LivingEntity target) {}
78+
protected void shootProjectile(LivingEntity shooter, Projectile projectile, int index, float velocity, float inaccuracy, float angle, @Nullable LivingEntity target) {
79+
}
8080

8181
@Override
82-
protected void shoot(ServerLevel level, LivingEntity shooter, InteractionHand hand, ItemStack weapon, List<ItemStack> projectileItems, float velocity, float inaccuracy, boolean isCrit, @Nullable LivingEntity target) {}
82+
protected void shoot(ServerLevel level, LivingEntity shooter, InteractionHand hand, ItemStack weapon, List<ItemStack> projectileItems, float velocity, float inaccuracy, boolean isCrit, @Nullable LivingEntity target) {
83+
}
8384

8485
@Override
8586
public InteractionResult useOn(UseOnContext context) {
@@ -233,8 +234,7 @@ public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStac
233234

234235
@Override
235236
public Predicate<ItemStack> getAllSupportedProjectiles() {
236-
return stack -> PotatoCannonProjectileType.getTypeForItem(GlobalRegistryAccess.getOrThrow(), stack.getItem())
237-
.isPresent();
237+
return AMMO_PREDICATE;
238238
}
239239

240240
@Override

src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/ItemAttribute.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static CompoundTag saveStatic(ItemAttribute attribute, HolderLookup.Provider reg
3636

3737
@Nullable
3838
static ItemAttribute loadStatic(CompoundTag nbt, HolderLookup.Provider registries) {
39-
return CatnipCodecUtils.decode(CODEC, registries, nbt.get("attribute")).orElse(null);
39+
return CatnipCodecUtils.decodeOrNull(CODEC, registries, nbt.get("attribute"));
4040
}
4141

4242
static List<ItemAttribute> getAllAttributes(ItemStack stack, Level level) {

src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/attributes/ItemNameAttribute.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import com.simibubi.create.content.logistics.item.filter.attribute.ItemAttributeType;
1414

1515
import io.netty.buffer.ByteBuf;
16-
import net.minecraft.core.RegistryAccess;
1716
import net.minecraft.core.component.DataComponents;
1817
import net.minecraft.network.RegistryFriendlyByteBuf;
1918
import net.minecraft.network.chat.Component;
@@ -30,12 +29,13 @@ public record ItemNameAttribute(String itemName) implements ItemAttribute {
3029
public static final StreamCodec<ByteBuf, ItemNameAttribute> STREAM_CODEC = ByteBufCodecs.STRING_UTF8
3130
.map(ItemNameAttribute::new, ItemNameAttribute::itemName);
3231

33-
private static String extractCustomName(ItemStack stack) {
32+
private static String extractCustomName(ItemStack stack, Level level) {
3433
if (stack.has(DataComponents.CUSTOM_NAME)) {
3534
try {
36-
Component itextcomponent = Component.Serializer.fromJson(stack.getOrDefault(DataComponents.CUSTOM_NAME, Component.empty()).getString(), RegistryAccess.EMPTY);
37-
if (itextcomponent != null) {
38-
return itextcomponent.getString();
35+
String customName = stack.getOrDefault(DataComponents.CUSTOM_NAME, Component.empty()).getString();
36+
Component component = Component.Serializer.fromJson(customName, level.registryAccess());
37+
if (component != null) {
38+
return component.getString();
3939
}
4040
} catch (JsonParseException ignored) {
4141
}
@@ -45,7 +45,7 @@ private static String extractCustomName(ItemStack stack) {
4545

4646
@Override
4747
public boolean appliesTo(ItemStack itemStack, Level level) {
48-
return extractCustomName(itemStack).equals(itemName);
48+
return extractCustomName(itemStack, level).equals(itemName);
4949
}
5050

5151
@Override
@@ -73,7 +73,7 @@ public static class Type implements ItemAttributeType {
7373
public List<ItemAttribute> getAllAttributes(ItemStack stack, Level level) {
7474
List<ItemAttribute> list = new ArrayList<>();
7575

76-
String name = extractCustomName(stack);
76+
String name = extractCustomName(stack, level);
7777
if (!name.isEmpty()) {
7878
list.add(new ItemNameAttribute(name));
7979
}

src/main/java/com/simibubi/create/content/logistics/packagePort/PackagePortBlockEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ protected void read(CompoundTag tag, HolderLookup.Provider registries, boolean c
9494
super.read(tag, registries, clientPacket);
9595
inventory.deserializeNBT(registries, tag.getCompound("Inventory"));
9696
PackagePortTarget prevTarget = target;
97-
target = CatnipCodecUtils.decode(PackagePortTarget.CODEC, registries, tag.getCompound("Target")).orElse(null);
97+
target = CatnipCodecUtils.decodeOrNull(PackagePortTarget.CODEC, registries, tag.getCompound("Target"));
9898
addressFilter = tag.getString("AddressFilter");
9999
acceptsPackages = tag.getBoolean("AcceptsPackages");
100100
if (clientPacket && prevTarget != target)

src/main/java/com/simibubi/create/content/logistics/packager/PackagerBlockEntity.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,8 +590,7 @@ protected void read(CompoundTag compound, HolderLookup.Provider registries, bool
590590
c -> CatnipCodecUtils.decode(BigItemStack.CODEC, registries, c)
591591
.orElseThrow());
592592
if (compound.contains("LastSummary"))
593-
availableItems = CatnipCodecUtils.decode(InventorySummary.CODEC, registries, compound.getCompound("LastSummary"))
594-
.orElse(null);
593+
availableItems = CatnipCodecUtils.decodeOrNull(InventorySummary.CODEC, registries, compound.getCompound("LastSummary"));
595594
}
596595

597596
@Override

src/main/java/com/simibubi/create/content/redstone/nixieTube/NixieTubeBlockEntity.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import net.minecraft.core.BlockPos;
2424
import net.minecraft.core.Direction;
2525
import net.minecraft.core.HolderLookup;
26-
import net.minecraft.core.RegistryAccess;
2726
import net.minecraft.nbt.CompoundTag;
2827
import net.minecraft.network.chat.Component;
2928
import net.minecraft.network.chat.MutableComponent;
@@ -80,7 +79,7 @@ public byte[] encode() {
8079
}
8180

8281
private static final Couple<String> EMPTY = Couple.create("", "");
83-
private static final String EMPTY_COMPONENT_JSON = Component.Serializer.toJson(Component.literal(""), RegistryAccess.EMPTY);
82+
private static final String EMPTY_COMPONENT_JSON = "\"\""; // Same as Component.literal("")
8483

8584
private int redstoneStrength;
8685
private Optional<DynamicComponent> customText;

src/main/java/com/simibubi/create/content/schematics/SchematicProcessor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import org.jetbrains.annotations.Nullable;
66

7-
import com.mojang.serialization.Codec;
87
import com.mojang.serialization.MapCodec;
98
import com.simibubi.create.AllStructureProcessorTypes;
109

@@ -23,10 +22,12 @@
2322
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
2423

2524
public class SchematicProcessor extends StructureProcessor {
26-
2725
public static final SchematicProcessor INSTANCE = new SchematicProcessor();
2826
public static final MapCodec<SchematicProcessor> CODEC = MapCodec.unit(() -> INSTANCE);
2927

28+
private SchematicProcessor() {
29+
}
30+
3031
@Nullable
3132
@Override
3233
public StructureTemplate.StructureBlockInfo process(LevelReader world, BlockPos pos, BlockPos anotherPos, StructureTemplate.StructureBlockInfo rawInfo,
@@ -61,5 +62,4 @@ public StructureTemplate.StructureEntityInfo processEntity(LevelReader world, Bl
6162
protected StructureProcessorType<?> getType() {
6263
return AllStructureProcessorTypes.SCHEMATIC.get();
6364
}
64-
6565
}

src/main/java/com/simibubi/create/content/trains/display/FlapDisplayBlockEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ protected void read(CompoundTag tag, HolderLookup.Provider registries, boolean c
251251
List<FlapDisplayLayout> lines = getLines();
252252
for (int i = 0; i < lines.size(); i++)
253253
lines.get(i)
254-
.read(tag.getCompound("Display" + i));
254+
.read(tag.getCompound("Display" + i), registries);
255255
}
256256

257257
public int getLineIndexAt(double yCoord) {

src/main/java/com/simibubi/create/content/trains/display/FlapDisplayLayout.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ public CompoundTag write(HolderLookup.Provider registries) {
4141
return tag;
4242
}
4343

44-
public void read(CompoundTag tag) {
44+
public void read(CompoundTag tag, HolderLookup.Provider registries) {
4545
String prevKey = layoutKey;
4646
layoutKey = tag.getString("Key");
4747
ListTag sectionsTag = tag.getList("Sections", Tag.TAG_COMPOUND);
4848

4949
if (!prevKey.equals(layoutKey)) {
50-
sections = NBTHelper.readCompoundList(sectionsTag, FlapDisplaySection::load);
50+
sections = NBTHelper.readCompoundList(sectionsTag, i -> FlapDisplaySection.load(i, registries));
5151
return;
5252
}
5353

5454
MutableInt index = new MutableInt(0);
5555
NBTHelper.iterateCompoundList(sectionsTag, nbt -> sections.get(index.getAndIncrement())
56-
.update(nbt));
56+
.update(nbt, registries));
5757
}
5858

5959
public List<FlapDisplaySection> getSections() {

0 commit comments

Comments
 (0)