-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMod.java
More file actions
94 lines (82 loc) · 4.71 KB
/
Mod.java
File metadata and controls
94 lines (82 loc) · 4.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package de.rubixdev.enchantedshulkers;
import com.chocohead.mm.api.ClassTinkerers;
import de.rubixdev.enchantedshulkers.config.ConfigCommand;
import de.rubixdev.enchantedshulkers.config.WorldConfig;
import de.rubixdev.enchantedshulkers.enchantment.RefillEnchantment;
import de.rubixdev.enchantedshulkers.enchantment.SiphonEnchantment;
import de.rubixdev.enchantedshulkers.interfaces.HasClientMod;
import de.rubixdev.enchantedshulkers.interfaces.InventoryState;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.api.resource.ResourcePackActivationType;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.Version;
import net.fabricmc.loader.api.metadata.ModMetadata;
import net.minecraft.enchantment.EnchantmentTarget;
import net.minecraft.item.Item;
import net.minecraft.network.packet.c2s.play.CustomPayloadC2SPacket;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.util.Identifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Mod implements ModInitializer {
public static final String MOD_ID = "enchantedshulkers";
public static final String MOD_NAME;
public static final Version MOD_VERSION;
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
static {
ModMetadata metadata = FabricLoader.getInstance()
.getModContainer(MOD_ID)
.orElseThrow(RuntimeException::new)
.getMetadata();
MOD_NAME = metadata.getName();
MOD_VERSION = metadata.getVersion();
}
public static final TagKey<Item> PORTABLE_CONTAINER_TAG =
TagKey.of(RegistryKeys.ITEM, new Identifier(MOD_ID, "portable_container"));
public static final EnchantmentTarget PORTABLE_CONTAINER_TARGET =
ClassTinkerers.getEnum(EnchantmentTarget.class, "PORTABLE_CONTAINER");
public static final SiphonEnchantment SIPHON_ENCHANTMENT = new SiphonEnchantment();
public static final RefillEnchantment REFILL_ENCHANTMENT = new RefillEnchantment();
public static final Identifier CLIENT_INSTALLED_PACKET_ID = new Identifier(MOD_ID, "client_installed");
public static final Identifier INVENTORY_OPEN_PACKET_ID = new Identifier(MOD_ID, "inventory_open");
public static final Identifier INVENTORY_CLOSE_PACKET_ID = new Identifier(MOD_ID, "inventory_close");
@Override
public void onInitialize() {
Registry.register(Registries.ENCHANTMENT, new Identifier(MOD_ID, "siphon"), SIPHON_ENCHANTMENT);
Registry.register(Registries.ENCHANTMENT, new Identifier(MOD_ID, "refill"), REFILL_ENCHANTMENT);
// Add enchanted_ender_chest data pack when enabled in config
FabricLoader.getInstance()
.getModContainer(MOD_ID)
.ifPresent(modContainer -> ResourceManagerHelper.registerBuiltinResourcePack(
new Identifier(MOD_ID, "enchanted_ender_chest"),
modContainer,
ResourcePackActivationType.NORMAL));
// Register event hooks and command
ServerLifecycleEvents.SERVER_STARTED.register(WorldConfig::attachServer);
ServerLifecycleEvents.SERVER_STOPPED.register(server -> WorldConfig.detachServer());
CommandRegistrationCallback.EVENT.register(
(dispatcher, registryAccess, environment) -> ConfigCommand.register(dispatcher));
// Register packet listeners
ServerPlayNetworking.registerGlobalReceiver(
CLIENT_INSTALLED_PACKET_ID,
(server, player, handler, buf, responseSender) -> ((HasClientMod) player).setTrue());
ServerPlayNetworking.registerGlobalReceiver(
CustomPayloadC2SPacket.BRAND,
// at this point a modded client would have sent a `CLIENT_INSTALLED_PACKET_ID` packet
(server, player, handler, buf, responseSender) -> ((HasClientMod) player).submit());
ServerPlayNetworking.registerGlobalReceiver(
INVENTORY_OPEN_PACKET_ID,
(server, player, handler, buf, responseSender) -> ((InventoryState) player).setOpen());
ServerPlayNetworking.registerGlobalReceiver(
INVENTORY_CLOSE_PACKET_ID,
(server, player, handler, buf, responseSender) -> ((InventoryState) player).setClosed());
LOGGER.info(MOD_NAME + " v" + MOD_VERSION.getFriendlyString() + " loaded");
}
}