Skip to content

Commit 2b4b9e9

Browse files
committed
Mojmapped
1 parent 3ac71e1 commit 2b4b9e9

85 files changed

Lines changed: 1615 additions & 1684 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ loom {
5656
dependencies {
5757
// To change the versions see the gradle.properties file
5858
minecraft "com.mojang:minecraft:${project.minecraft_version}"
59-
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
59+
mappings loom.officialMojangMappings()
6060
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
6161

6262
// Fabric API. This is technically optional, but you probably want it anyway.

src/main/java/eu/pb4/graves/GenericModInfo.java

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
import net.fabricmc.loader.api.ModContainer;
44
import net.fabricmc.loader.api.metadata.Person;
5-
import net.minecraft.text.*;
6-
import net.minecraft.util.Formatting;
7-
5+
import net.minecraft.ChatFormatting;
6+
import net.minecraft.network.chat.ClickEvent;
7+
import net.minecraft.network.chat.Component;
8+
import net.minecraft.network.chat.HoverEvent;
9+
import net.minecraft.network.chat.MutableComponent;
10+
import net.minecraft.network.chat.Style;
811
import javax.imageio.ImageIO;
912
import java.net.URI;
1013
import java.nio.file.Files;
@@ -14,19 +17,19 @@
1417
import java.util.stream.Collectors;
1518

1619
public class GenericModInfo {
17-
private static Text[] icon = new Text[0];
18-
private static Text[] about = new Text[0];
19-
private static Text[] consoleAbout = new Text[0];
20+
private static Component[] icon = new Component[0];
21+
private static Component[] about = new Component[0];
22+
private static Component[] consoleAbout = new Component[0];
2023

2124
public static void build(ModContainer container) {
2225
{
2326
final String chr = "█";
24-
var icon = new ArrayList<MutableText>();
27+
var icon = new ArrayList<MutableComponent>();
2528
try {
2629
var source = ImageIO.read(Files.newInputStream(container.getPath("assets/logo_mini.png")));
2730

2831
for (int y = 0; y < source.getHeight(); y++) {
29-
var base = Text.literal("");
32+
var base = Component.literal("");
3033
int line = 0;
3134
int color = source.getRGB(0, y) & 0xFFFFFF;
3235
for (int x = 0; x < source.getWidth(); x++) {
@@ -35,52 +38,52 @@ public static void build(ModContainer container) {
3538
if (color == colorPixel) {
3639
line++;
3740
} else {
38-
base.append(Text.literal(chr.repeat(line)).setStyle(Style.EMPTY.withColor(color)));
41+
base.append(Component.literal(chr.repeat(line)).setStyle(Style.EMPTY.withColor(color)));
3942
color = colorPixel;
4043
line = 1;
4144
}
4245
}
4346

44-
base.append(Text.literal(chr.repeat(line)).setStyle(Style.EMPTY.withColor(color)));
47+
base.append(Component.literal(chr.repeat(line)).setStyle(Style.EMPTY.withColor(color)));
4548
icon.add(base);
4649
}
4750
} catch (Throwable e) {
4851
e.printStackTrace();
4952
while (icon.size() < 16) {
50-
icon.add(Text.literal("/!\\ [ Invalid icon file ] /!\\").setStyle(Style.EMPTY.withColor(0xFF0000).withItalic(true)));
53+
icon.add(Component.literal("/!\\ [ Invalid icon file ] /!\\").setStyle(Style.EMPTY.withColor(0xFF0000).withItalic(true)));
5154
}
5255
}
5356

54-
GenericModInfo.icon = icon.toArray(new Text[0]);
57+
GenericModInfo.icon = icon.toArray(new Component[0]);
5558
}
5659

5760
{
58-
var about = new ArrayList<Text>();
59-
var aboutBasic = new ArrayList<Text>();
60-
var output = new ArrayList<Text>();
61+
var about = new ArrayList<Component>();
62+
var aboutBasic = new ArrayList<Component>();
63+
var output = new ArrayList<Component>();
6164

6265
try {
63-
about.add(Text.literal(container.getMetadata().getName()).setStyle(Style.EMPTY.withColor(0x00e6b4).withBold(true).withClickEvent(new ClickEvent.OpenUrl(URI.create(container.getMetadata().getContact().get("github").orElse("https://pb4.eu"))))));
64-
about.add(Text.translatable("text.graves.about.version", Text.literal(container.getMetadata().getVersion().getFriendlyString()).setStyle(Style.EMPTY.withColor(Formatting.WHITE))).setStyle(Style.EMPTY.withColor(0xf7e1a7)));
66+
about.add(Component.literal(container.getMetadata().getName()).setStyle(Style.EMPTY.withColor(0x00e6b4).withBold(true).withClickEvent(new ClickEvent.OpenUrl(URI.create(container.getMetadata().getContact().get("github").orElse("https://pb4.eu"))))));
67+
about.add(Component.translatable("text.graves.about.version", Component.literal(container.getMetadata().getVersion().getFriendlyString()).setStyle(Style.EMPTY.withColor(ChatFormatting.WHITE))).setStyle(Style.EMPTY.withColor(0xf7e1a7)));
6568

6669
aboutBasic.addAll(about);
67-
aboutBasic.add(Text.empty());
68-
aboutBasic.add(Text.of(container.getMetadata().getDescription()));
70+
aboutBasic.add(Component.empty());
71+
aboutBasic.add(Component.nullToEmpty(container.getMetadata().getDescription()));
6972

7073
var contributors = new ArrayList<String>();
7174
contributors.addAll(container.getMetadata().getAuthors().stream().map(Person::getName).toList());
7275
contributors.addAll(container.getMetadata().getContributors().stream().map(Person::getName).toList());
7376

74-
about.add(Text.literal("")
75-
.append(Text.translatable("text.graves.about.contributors")
76-
.setStyle(Style.EMPTY.withColor(Formatting.AQUA)
77+
about.add(Component.literal("")
78+
.append(Component.translatable("text.graves.about.contributors")
79+
.setStyle(Style.EMPTY.withColor(ChatFormatting.AQUA)
7780
.withHoverEvent(new HoverEvent.ShowText(
78-
Text.literal(String.join(", ", contributors)
81+
Component.literal(String.join(", ", contributors)
7982
))
8083
)))
8184
.append("")
82-
.setStyle(Style.EMPTY.withColor(Formatting.DARK_GRAY)));
83-
about.add(Text.empty());
85+
.setStyle(Style.EMPTY.withColor(ChatFormatting.DARK_GRAY)));
86+
about.add(Component.empty());
8487

8588
var desc = new ArrayList<>(List.of(container.getMetadata().getDescription().split(" ")));
8689

@@ -90,21 +93,21 @@ public static void build(ModContainer container) {
9093
(descPart.isEmpty() ? descPart : descPart.append(" ")).append(desc.remove(0));
9194

9295
if (descPart.length() > 16) {
93-
about.add(Text.literal(descPart.toString()).setStyle(Style.EMPTY.withColor(Formatting.GRAY)));
96+
about.add(Component.literal(descPart.toString()).setStyle(Style.EMPTY.withColor(ChatFormatting.GRAY)));
9497
descPart = new StringBuilder();
9598
}
9699
}
97100

98101
if (descPart.length() > 0) {
99-
about.add(Text.literal(descPart.toString()).setStyle(Style.EMPTY.withColor(Formatting.GRAY)));
102+
about.add(Component.literal(descPart.toString()).setStyle(Style.EMPTY.withColor(ChatFormatting.GRAY)));
100103
}
101104
}
102105

103106
if (icon.length > about.size() + 2) {
104107
int a = 0;
105108
for (int i = 0; i < icon.length; i++) {
106109
if (i == (icon.length - about.size() - 1) / 2 + a && a < about.size()) {
107-
output.add(icon[i].copy().append(Text.literal(" ").setStyle(Style.EMPTY.withItalic(false)).append(about.get(a++))));
110+
output.add(icon[i].copy().append(Component.literal(" ").setStyle(Style.EMPTY.withItalic(false)).append(about.get(a++))));
108111
} else {
109112
output.add(icon[i]);
110113
}
@@ -115,26 +118,26 @@ public static void build(ModContainer container) {
115118
}
116119
} catch (Throwable e) {
117120
e.printStackTrace();
118-
var invalid = Text.literal("/!\\ [ Invalid about mod info ] /!\\").setStyle(Style.EMPTY.withColor(0xFF0000).withItalic(true));
121+
var invalid = Component.literal("/!\\ [ Invalid about mod info ] /!\\").setStyle(Style.EMPTY.withColor(0xFF0000).withItalic(true));
119122

120123
output.add(invalid);
121124
about.add(invalid);
122125
}
123126

124-
GenericModInfo.about = output.toArray(new Text[0]);
125-
GenericModInfo.consoleAbout = aboutBasic.toArray(new Text[0]);
127+
GenericModInfo.about = output.toArray(new Component[0]);
128+
GenericModInfo.consoleAbout = aboutBasic.toArray(new Component[0]);
126129
}
127130
}
128131

129-
public static Text[] getIcon() {
132+
public static Component[] getIcon() {
130133
return icon;
131134
}
132135

133-
public static Text[] getAboutFull() {
136+
public static Component[] getAboutFull() {
134137
return about;
135138
}
136139

137-
public static Text[] getAboutConsole() {
140+
public static Component[] getAboutConsole() {
138141
return consoleAbout;
139142
}
140143
}

src/main/java/eu/pb4/graves/GraveTextures.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,34 @@
33
import com.google.common.base.Suppliers;
44
import eu.pb4.polymer.networking.api.server.PolymerServerNetworking;
55
import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils;
6-
import net.minecraft.nbt.NbtByte;
7-
import net.minecraft.nbt.NbtInt;
8-
import net.minecraft.server.network.ServerPlayerEntity;
9-
import net.minecraft.text.Style;
10-
import net.minecraft.text.StyleSpriteSource;
11-
import net.minecraft.text.Text;
12-
import net.minecraft.util.Formatting;
13-
import net.minecraft.util.Identifier;
146
import org.jetbrains.annotations.Nullable;
157

168
import java.util.function.Supplier;
9+
import net.minecraft.ChatFormatting;
10+
import net.minecraft.nbt.IntTag;
11+
import net.minecraft.network.chat.Component;
12+
import net.minecraft.network.chat.FontDescription;
13+
import net.minecraft.network.chat.Style;
14+
import net.minecraft.resources.Identifier;
15+
import net.minecraft.server.level.ServerPlayer;
1716

1817

1918
public final class GraveTextures {
20-
private static final Identifier IDENTIFIER = Identifier.of("universal_graves", "has_rp");
21-
private static final Supplier<Text> DEV_TEXTURE = () -> Text.literal("-1.").setStyle(Style.EMPTY.withColor(Formatting.WHITE).withFont(new StyleSpriteSource.Font(Identifier.of("universal_graves", "gui"))));
22-
private static final Supplier<Text> TEXTURE = GravesMod.DEV ? DEV_TEXTURE : Suppliers.memoize(DEV_TEXTURE::get);
19+
private static final Identifier IDENTIFIER = Identifier.fromNamespaceAndPath("universal_graves", "has_rp");
20+
private static final Supplier<Component> DEV_TEXTURE = () -> Component.literal("-1.").setStyle(Style.EMPTY.withColor(ChatFormatting.WHITE).withFont(new FontDescription.Resource(Identifier.fromNamespaceAndPath("universal_graves", "gui"))));
21+
private static final Supplier<Component> TEXTURE = GravesMod.DEV ? DEV_TEXTURE : Suppliers.memoize(DEV_TEXTURE::get);
2322

24-
public static Text get(ServerPlayerEntity player, Text text) {
25-
return hasGuiTexture(player) ? Text.empty().append(TEXTURE.get()).append(text) : text;
23+
public static Component get(ServerPlayer player, Component text) {
24+
return hasGuiTexture(player) ? Component.empty().append(TEXTURE.get()).append(text) : text;
2625
}
2726

28-
public static boolean hasGuiTexture(@Nullable ServerPlayerEntity player) {
29-
var mata = player != null ? PolymerServerNetworking.getMetadata(player.networkHandler, IDENTIFIER, NbtInt.TYPE) : null;
27+
public static boolean hasGuiTexture(@Nullable ServerPlayer player) {
28+
var mata = player != null ? PolymerServerNetworking.getMetadata(player.connection, IDENTIFIER, IntTag.TYPE) : null;
3029
return PolymerResourcePackUtils.hasMainPack(player)
31-
|| (player != null && player.networkHandler != null && mata != null && mata.intValue() == 1);
30+
|| (player != null && player.connection != null && mata != null && mata.intValue() == 1);
3231
}
3332

3433
public static void initialize() {
35-
PolymerServerNetworking.setServerMetadata(IDENTIFIER, NbtInt.of(1));
34+
PolymerServerNetworking.setServerMetadata(IDENTIFIER, IntTag.valueOf(1));
3635
}
3736
}

src/main/java/eu/pb4/graves/GravesApi.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
import eu.pb4.graves.other.Location;
1414
import eu.pb4.graves.other.VanillaInventoryMask;
1515
import net.fabricmc.fabric.api.event.Event;
16-
import net.minecraft.component.EnchantmentEffectComponentTypes;
17-
import net.minecraft.enchantment.EnchantmentHelper;
18-
import net.minecraft.item.ItemStack;
19-
import net.minecraft.server.network.ServerPlayerEntity;
20-
import net.minecraft.util.ActionResult;
21-
import net.minecraft.util.Identifier;
22-
import net.minecraft.util.math.BlockPos;
16+
import net.minecraft.core.BlockPos;
17+
import net.minecraft.resources.Identifier;
18+
import net.minecraft.server.level.ServerPlayer;
19+
import net.minecraft.world.InteractionResult;
20+
import net.minecraft.world.item.ItemStack;
21+
import net.minecraft.world.item.enchantment.EnchantmentEffectComponents;
22+
import net.minecraft.world.item.enchantment.EnchantmentHelper;
2323
import org.jetbrains.annotations.Nullable;
2424

2525
import java.util.*;
@@ -44,11 +44,11 @@ public static Collection<Grave> getAllGraves() {
4444
return ImmutableList.copyOf(GraveManager.INSTANCE.getAll());
4545
}
4646

47-
public static boolean canAddItem(ServerPlayerEntity player, ItemStack itemStack) {
47+
public static boolean canAddItem(ServerPlayer player, ItemStack itemStack) {
4848
return !itemStack.isEmpty()
49-
&& PlayerGraveItemAddedEvent.EVENT.invoker().canAddItem(player, itemStack) != ActionResult.FAIL
49+
&& PlayerGraveItemAddedEvent.EVENT.invoker().canAddItem(player, itemStack) != InteractionResult.FAIL
5050
&& !GraveUtils.hasSkippedEnchantment(itemStack)
51-
&& !EnchantmentHelper.hasAnyEnchantmentsWith(itemStack, EnchantmentEffectComponentTypes.PREVENT_EQUIPMENT_DROP);
51+
&& !EnchantmentHelper.has(itemStack, EnchantmentEffectComponents.PREVENT_EQUIPMENT_DROP);
5252
}
5353

5454
@Nullable

src/main/java/eu/pb4/graves/GravesMod.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@
2121
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
2222
import net.fabricmc.loader.api.FabricLoader;
2323
import net.fabricmc.loader.api.ModContainer;
24-
import net.minecraft.block.entity.BlockEntityType;
25-
import net.minecraft.item.ItemGroups;
26-
import net.minecraft.registry.Registries;
27-
import net.minecraft.registry.Registry;
28-
import net.minecraft.util.Identifier;
24+
import net.minecraft.resources.Identifier;
25+
import net.minecraft.world.item.CreativeModeTabs;
2926
import org.apache.logging.log4j.LogManager;
3027
import org.apache.logging.log4j.Logger;
3128

@@ -49,8 +46,8 @@ public void onInitialize() {
4946
GravesRegistry.register();
5047
Commands.register();
5148

52-
ItemGroupEvents.modifyEntriesEvent(ItemGroups.FUNCTIONAL).register((e) -> {
53-
e.add(GravesRegistry.CONTAINER_GRAVE_ITEM);
49+
ItemGroupEvents.modifyEntriesEvent(CreativeModeTabs.FUNCTIONAL_BLOCKS).register((e) -> {
50+
e.accept(GravesRegistry.CONTAINER_GRAVE_ITEM);
5451
});
5552

5653
GraveTextures.initialize();
@@ -60,9 +57,9 @@ public void onInitialize() {
6057
PolymerResourcePackUtils.addModAssets("universal-graves");
6158
}
6259

63-
CommonProtection.register(Identifier.of("universal_graves", "graves"), GraveProtectionProvider.INSTANCE);
60+
CommonProtection.register(Identifier.fromNamespaceAndPath("universal_graves", "graves"), GraveProtectionProvider.INSTANCE);
6461

65-
GravesApi.registerInventoryMask(Identifier.of("vanilla"), VanillaInventoryMask.INSTANCE);
62+
GravesApi.registerInventoryMask(Identifier.parse("vanilla"), VanillaInventoryMask.INSTANCE);
6663

6764
if (loader.isModLoaded("goml")) {
6865
GomlCompat.register();
@@ -82,7 +79,7 @@ public void onInitialize() {
8279
SaveGearOnDeathCompat.register();
8380
}
8481

85-
ServerLifecycleEvents.SERVER_STARTING.register((server) -> ConfigManager.loadConfig(server.getRegistryManager()));
82+
ServerLifecycleEvents.SERVER_STARTING.register((server) -> ConfigManager.loadConfig(server.registryAccess()));
8683
ServerLifecycleEvents.SERVER_STOPPED.register((server) -> {
8784
GraveManager.INSTANCE = null;
8885
ConfigManager.clearConfig();
@@ -92,8 +89,8 @@ public void onInitialize() {
9289
});
9390

9491
ServerWorldEvents.LOAD.register(((server, world) -> {
95-
if (world == server.getOverworld()) {
96-
GraveManager.INSTANCE = world.getPersistentStateManager().getOrCreate(GraveManager.getType(world));
92+
if (world == server.overworld()) {
93+
GraveManager.INSTANCE = world.getDataStorage().computeIfAbsent(GraveManager.getType(world));
9794
GraveManager.INSTANCE.setServer(server);
9895
}
9996
}));

0 commit comments

Comments
 (0)