-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provided support for 1.20.5 and 1.20.6 #55
- Loading branch information
Showing
3 changed files
with
136 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
src/main/java/dev/xdpxi/xdlib/api/mod/customClass/custom0.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package dev.xdpxi.xdlib.api.mod.customClass; | ||
|
||
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup; | ||
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents; | ||
import net.minecraft.block.AbstractBlock; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.MapColor; | ||
import net.minecraft.item.*; | ||
import net.minecraft.registry.Registries; | ||
import net.minecraft.registry.Registry; | ||
import net.minecraft.registry.RegistryKey; | ||
import net.minecraft.registry.entry.RegistryEntry; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Identifier; | ||
|
||
import java.util.List; | ||
|
||
public class custom0 { | ||
public static void ItemGroup(String itemGroupID, String modID, Item itemIconID, List<Item> itemsToAdd) { | ||
itemGroupID = itemGroupID.toLowerCase(); | ||
modID = modID.toLowerCase(); | ||
RegistryKey<ItemGroup> ITEM_GROUP_KEY = RegistryKey.of(Registries.ITEM_GROUP.getKey(), new Identifier(modID, itemGroupID)); | ||
|
||
ItemGroup ITEM_GROUP = FabricItemGroup.builder() | ||
.displayName(Text.translatable("itemGroup." + modID + "." + itemGroupID)) | ||
.icon(() -> new ItemStack(itemIconID != null ? itemIconID : Items.STONE)) | ||
.build(); | ||
|
||
Registry.register(Registries.ITEM_GROUP, ITEM_GROUP_KEY, ITEM_GROUP); | ||
|
||
ItemGroupEvents.modifyEntriesEvent(ITEM_GROUP_KEY).register(itemGroup -> { | ||
for (Item item : itemsToAdd) { | ||
itemGroup.add(item); | ||
} | ||
}); | ||
} | ||
|
||
public static void AddToItemGroup(String itemGroupID, String modID, List<Item> itemsToAdd) { | ||
ItemGroup(itemGroupID, modID, null, itemsToAdd); | ||
} | ||
|
||
public static Item Item(String itemID, String modID, RegistryKey<ItemGroup> itemGroup) { | ||
if (itemID == null || modID == null) { | ||
throw new IllegalArgumentException("itemID or modID is null"); | ||
} | ||
itemID = itemID.toLowerCase(); | ||
modID = modID.toLowerCase(); | ||
Identifier identifier = new Identifier(modID, itemID); | ||
|
||
Item item = new Item(new Item.Settings()); | ||
Registry.register(Registries.ITEM, identifier, item); | ||
|
||
if (itemGroup != null) { | ||
ItemGroupEvents.modifyEntriesEvent(itemGroup).register(entries -> entries.add(item)); | ||
} | ||
|
||
return item; | ||
} | ||
|
||
public static Item Item(String itemID, String modID) { | ||
return Item(itemID, modID, null); | ||
} | ||
|
||
public static BlockItem Block(String blockID, String modID, RegistryKey<ItemGroup> itemGroup) { | ||
blockID = blockID.toLowerCase(); | ||
modID = modID.toLowerCase(); | ||
Identifier blockIdentifier = new Identifier(modID, blockID); | ||
|
||
Block block = new Block(AbstractBlock.Settings.create().mapColor(MapColor.STONE_GRAY).strength(1.5F, 6.0F)); | ||
Block registeredBlock = Registry.register(Registries.BLOCK, blockIdentifier, block); | ||
BlockItem blockItem = new BlockItem(registeredBlock, new Item.Settings()); | ||
|
||
Registry.register(Registries.ITEM, blockIdentifier, blockItem); | ||
|
||
if (itemGroup != null) { | ||
ItemGroupEvents.modifyEntriesEvent(itemGroup).register(entries -> entries.add(blockItem)); | ||
} | ||
|
||
return blockItem; | ||
} | ||
|
||
public static BlockItem Block(String blockID, String modID) { | ||
return Block(blockID, modID, null); | ||
} | ||
|
||
public static Item Weapon(String weaponID, String modID, ToolMaterial material, RegistryKey<ItemGroup> itemGroup) { | ||
weaponID = weaponID.toLowerCase(); | ||
modID = modID.toLowerCase(); | ||
Identifier identifier = new Identifier(modID, weaponID); | ||
|
||
SwordItem weapon = new SwordItem(material, new Item.Settings().maxDamage(material.getDurability())); | ||
Registry.register(Registries.ITEM, identifier, weapon); | ||
|
||
if (itemGroup != null) { | ||
ItemGroupEvents.modifyEntriesEvent(itemGroup).register(entries -> entries.add(weapon)); | ||
} | ||
|
||
return weapon; | ||
} | ||
|
||
public static Item Weapon(String weaponID, String modID, ToolMaterial material) { | ||
return Weapon(weaponID, modID, material, null); | ||
} | ||
|
||
public static Item Armor(String armorID, String modID, RegistryEntry<ArmorMaterial> armorType, ArmorItem.Type armorPart, RegistryKey<ItemGroup> itemGroup) { | ||
armorID = armorID.toLowerCase(); | ||
modID = modID.toLowerCase(); | ||
Identifier identifier = new Identifier(modID, armorID); | ||
|
||
ArmorItem armor = new ArmorItem(armorType, armorPart, new Item.Settings()); | ||
Registry.register(Registries.ITEM, identifier, armor); | ||
|
||
if (itemGroup != null) { | ||
ItemGroupEvents.modifyEntriesEvent(itemGroup).register(entries -> entries.add(armor)); | ||
} | ||
|
||
return armor; | ||
} | ||
|
||
public static Item Armor(String armorID, String modID, RegistryEntry<ArmorMaterial> armorType, ArmorItem.Type armorPart) { | ||
return Armor(armorID, modID, armorType, armorPart, null); | ||
} | ||
} |