Init
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package de.foxgalaxy.villa;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
|
||||
import net.fabricmc.fabric.api.attachment.v1.AttachmentRegistry;
|
||||
import net.fabricmc.fabric.api.attachment.v1.AttachmentType;
|
||||
import net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class VillaMod implements ModInitializer {
|
||||
public static final String MOD_ID = "villa";
|
||||
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
||||
|
||||
public static final TagKey<Item> SOULBOUND = TagKey.create(Registries.ITEM, Identifier.fromNamespaceAndPath(MOD_ID, "soulbound"));
|
||||
public static final AttachmentType<Boolean> HAS_JOINED = AttachmentRegistry.create(Identifier.fromNamespaceAndPath(MOD_ID, "joined"), builder ->
|
||||
builder.initializer(() -> false)
|
||||
.persistent(Codec.BOOL)
|
||||
.copyOnDeath()
|
||||
);
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
ServerPlayerEvents.JOIN.register((player) -> {
|
||||
if(!player.getAttachedOrCreate(HAS_JOINED)) {
|
||||
player.setAttached(HAS_JOINED, true);
|
||||
giveEquipment(player);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void giveEquipment(ServerPlayer player) {
|
||||
Inventory inv = player.getInventory();
|
||||
inv.add(new ItemStack(Items.IRON_PICKAXE));
|
||||
inv.add(new ItemStack(Items.IRON_AXE));
|
||||
inv.add(new ItemStack(Items.IRON_SHOVEL));
|
||||
inv.add(new ItemStack(Items.BUCKET));
|
||||
inv.add(new ItemStack(Items.BREAD, 32));
|
||||
|
||||
player.setItemSlot(EquipmentSlot.OFFHAND, new ItemStack(Items.SHIELD));
|
||||
player.setItemSlot(EquipmentSlot.HEAD, new ItemStack(Items.IRON_HELMET));
|
||||
player.setItemSlot(EquipmentSlot.CHEST, new ItemStack(Items.IRON_CHESTPLATE));
|
||||
player.setItemSlot(EquipmentSlot.LEGS, new ItemStack(Items.IRON_LEGGINGS));
|
||||
player.setItemSlot(EquipmentSlot.FEET, new ItemStack(Items.IRON_BOOTS));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user