diff --git a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/BlockRegistryImpl.java b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/BlockRegistryImpl.java index 442a7d38..d3e4dee3 100644 --- a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/BlockRegistryImpl.java +++ b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/BlockRegistryImpl.java @@ -64,6 +64,7 @@ public static void init() { } VanillaBlocks.init(); + BlockEvents.REGISTER_BLOCKS.invoker().run(); initialized = true; } diff --git a/libraries/items/README.md b/libraries/items/README.md new file mode 100644 index 00000000..0566ce42 --- /dev/null +++ b/libraries/items/README.md @@ -0,0 +1,41 @@ +# Items API + +The Items API provides events and utilities for registering and working with items. + +## Registering Custom Items + +Item registration should be done in a listener to the `REGISTER_ITEMS` event. The `ItemRegistry` class provides utility methods for registering items. + +An example is shown below. + +```java +package com.example; + +import net.ornithemc.osl.entrypoints.api.ModInitializer; +import net.ornithemc.osl.items.api.ItemEvents; + +public class ExampleInitializer implements ModInitializer { + + @Override + public void init() { + ItemEvents.REGISTER_ITEMS.register(ExampleItems::init); + } +} +``` + +```java +package com.example; + +import net.minecraft.item.Item; + +import net.ornithemc.osl.core.util.NamespacedIdentifiers; +import net.ornithemc.osl.items.api.ItemRegistry; + +public final class ExampleItems { + + public static final CookieItem COOKIE = ItemRegistry.register(NamespacedIdentifiers.from("example", "cookie"), new CookieItem()); + + public static void init() { + } +} +``` diff --git a/libraries/items/build.gradle b/libraries/items/build.gradle new file mode 100644 index 00000000..e98ba2c6 --- /dev/null +++ b/libraries/items/build.gradle @@ -0,0 +1 @@ +setUpLibrary(project) diff --git a/libraries/items/gradle.properties b/libraries/items/gradle.properties new file mode 100644 index 00000000..a3ddc062 --- /dev/null +++ b/libraries/items/gradle.properties @@ -0,0 +1,6 @@ +library_id = items +library_name = Items +library_description = Items API and events. +library_version = 0.1.0-alpha.1 + +osl_dependencies = core:>=0.7.0,blocks:>=0.1.0- diff --git a/libraries/items/items-mc13w36a-mc14w25b/build.gradle b/libraries/items/items-mc13w36a-mc14w25b/build.gradle new file mode 100644 index 00000000..0a350fdb --- /dev/null +++ b/libraries/items/items-mc13w36a-mc14w25b/build.gradle @@ -0,0 +1 @@ +setUpModule(project) diff --git a/libraries/items/items-mc13w36a-mc14w25b/gradle.properties b/libraries/items/items-mc13w36a-mc14w25b/gradle.properties new file mode 100644 index 00000000..fd8d10fb --- /dev/null +++ b/libraries/items/items-mc13w36a-mc14w25b/gradle.properties @@ -0,0 +1,8 @@ +min_mc_version = 13w36a +max_mc_version = 14w25b +minecraft_dependency = >=1.7-alpha.13.36.a <=1.8-alpha.14.25.b + +minecraft_version = 1.7.2 +raven_build = 1 +sparrow_build = 1 +nests_build = 3 diff --git a/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/api/ItemEvents.java b/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/api/ItemEvents.java new file mode 100644 index 00000000..4d0923b9 --- /dev/null +++ b/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/api/ItemEvents.java @@ -0,0 +1,34 @@ +package net.ornithemc.osl.items.api; + +import net.ornithemc.osl.core.api.events.Event; + +/** + * Events related to the items lifecycle. + */ +public final class ItemEvents { + + /** + * This event is invoked upon game start-up, after Vanilla item registration is finished. + * + *
+ * Custom item registration should be done in a listener of this event. + * Helper methods for registering items can be found in the {@linkplain + * ItemRegistry} class. + * + *
+ * Listeners to this event should be registered in your mod's entrypoint, + * and can be done as follows: + * + *
+ * {@code
+ * ItemEvents.REGISTER_ITEMS.register(() -> {
+ * ItemRegistry.register(999, NamespacedIdentifiers.from("example", "cookie"), new CookieItem());
+ * });
+ * }
+ *
+ *
+ * @see ItemRegistry
+ */
+ public static final Event+ * Custom item registration should be done in a listener of this event. + * Helper methods for registering items can be found in the {@linkplain + * ItemRegistry} class. + * + *
+ * Listeners to this event should be registered in your mod's entrypoint, + * and can be done as follows: + * + *
+ * {@code
+ * ItemEvents.REGISTER_ITEMS.register(() -> {
+ * ItemRegistry.register(999, NamespacedIdentifiers.from("example", "cookie"), new CookieItem());
+ * });
+ * }
+ *
+ *
+ * @see ItemRegistry
+ */
+ public static final Event+ * Custom item registration should be done in a listener of this event. + * Helper methods for registering items can be found in the {@linkplain + * ItemRegistry} class. + * + *
+ * Listeners to this event should be registered in your mod's entrypoint, + * and can be done as follows: + * + *
+ * {@code
+ * ItemEvents.REGISTER_ITEMS.register(() -> {
+ * ItemRegistry.register(NamespacedIdentifiers.from("example", "cookie"), new CookieItem());
+ * });
+ * }
+ *
+ *
+ * @see ItemRegistry
+ */
+ public static final Event+ * Custom item registration should be done in a listener of this event. + * Helper methods for registering items can be found in the {@linkplain + * ItemRegistry} class. + * + *
+ * Listeners to this event should be registered in your mod's entrypoint, + * and can be done as follows: + * + *
+ * {@code
+ * ItemEvents.REGISTER_ITEMS.register(() -> {
+ * ItemRegistry.register(NamespacedIdentifiers.from("example", "cookie"), new CookieItem());
+ * });
+ * }
+ *
+ *
+ * @see ItemRegistry
+ */
+ public static final Event+ * Custom item registration should be done in a listener of this event. + * Helper methods for registering items can be found in the {@linkplain + * ItemRegistry} class. + * + *
+ * Listeners to this event should be registered in your mod's entrypoint, + * and can be done as follows: + * + *
+ * {@code
+ * ItemEvents.REGISTER_ITEMS.register(() -> {
+ * ItemRegistry.register(NamespacedIdentifiers.from("example", "cookie"), new CookieItem());
+ * });
+ * }
+ *
+ *
+ * @see ItemRegistry
+ */
+ public static final Event+ * Custom item registration should be done in a listener of this event. + * Helper methods for registering items can be found in the {@linkplain + * ItemRegistry} class. + * + *
+ * Listeners to this event should be registered in your mod's entrypoint, + * and can be done as follows: + * + *
+ * {@code
+ * ItemEvents.REGISTER_ITEMS.register(() -> {
+ * ItemRegistry.register(999, NamespacedIdentifiers.from("example", "cookie"), new CookieItem(999));
+ * });
+ * }
+ *
+ *
+ * @see ItemRegistry
+ */
+ public static final Event+ * Custom block item registration should be done in a listener of this event. + * Helper methods for registering block items can be found in the {@linkplain + * ItemRegistry} class. + * + *
+ * Listeners to this event should be registered in your mod's entrypoint, + * and can be done as follows: + * + *
+ * {@code
+ * ItemEvents.REGISTER_BLOCK_ITEMS.register(() -> {
+ * ItemRegistry.register(COOKIE_BLOCK, new CookieItem(999));
+ * });
+ * }
+ *
+ *
+ * @see ItemRegistry
+ */
+ public static final Event
+ * Note that in 1.7 snapshots the IDs went through several changes.
+ * The IDs used here match those used in Release 1.7.2.
+ */
+ private static final String[] IDENTIFIERS = {
+ // grouped per 10 for easier lookup
+
+ "iron_shovel",
+ "iron_pickaxe",
+ "iron_axe",
+ "flint_and_steel",
+ "apple",
+ "bow",
+ "arrow",
+ "coal",
+ "diamond",
+ "iron_ingot",
+
+ "gold_ingot",
+ "iron_sword",
+ "wooden_sword",
+ "wooden_shovel",
+ "wooden_pickaxe",
+ "wooden_axe",
+ "stone_sword",
+ "stone_shovel",
+ "stone_pickaxe",
+ "stone_axe",
+
+ "diamond_sword",
+ "diamond_shovel",
+ "diamond_pickaxe",
+ "diamond_axe",
+ "stick",
+ "bowl",
+ "mushroom_stew",
+ "golden_sword",
+ "golden_shovel",
+ "golden_pickaxe",
+
+ "golden_axe",
+ "string",
+ "feather",
+ "gunpowder",
+ "wooden_hoe",
+ "stone_hoe",
+ "iron_hoe",
+ "diamond_hoe",
+ "golden_hoe",
+ "wheat_seeds",
+
+ "wheat",
+ "bread",
+ "leather_helmet",
+ "leather_chestplate",
+ "leather_leggings",
+ "leather_boots",
+ "chainmail_helmet",
+ "chainmail_chestplate",
+ "chainmail_leggings",
+ "chainmail_boots",
+
+ "iron_helmet",
+ "iron_chestplate",
+ "iron_leggings",
+ "iron_boots",
+ "diamond_helmet",
+ "diamond_chestplate",
+ "diamond_leggings",
+ "diamond_boots",
+ "golden_helmet",
+ "golden_chestplate",
+
+ "golden_leggings",
+ "golden_boots",
+ "flint",
+ "porkchop",
+ "cooked_porkchop",
+ "painting",
+ "golden_apple",
+ "sign",
+ "wooden_door",
+ "bucket",
+
+ "water_bucket",
+ "lava_bucket",
+ "minecart",
+ "saddle",
+ "iron_door",
+ "redstone",
+ "snowball",
+ "boat",
+ "leather",
+ "milk_bucket",
+
+ "brick",
+ "clay_ball",
+ "reeds",
+ "paper",
+ "book",
+ "slime_ball",
+ "chest_minecart",
+ "furnace_minecart",
+ "egg",
+ "compass",
+
+ "fishing_rod",
+ "clock",
+ "glowstone_dust",
+ "fish",
+ "cooked_fished",
+ "dye",
+ "bone",
+ "sugar",
+ "cake",
+ "bed",
+
+ "repeater",
+ "cookie",
+ "filled_map",
+ "shears",
+ "melon",
+ "pumpkin_seeds",
+ "melon_seeds",
+ "beef",
+ "cooked_beef",
+ "chicken",
+
+ "cooked_chicken",
+ "rotten_flesh",
+ "ender_pearl",
+ "blaze_rod",
+ "ghast_tear",
+ "gold_nugget",
+ "nether_wart",
+ "potion",
+ "glass_bottle",
+ "spider_eye",
+
+ "fermented_spider_eye",
+ "blaze_powder",
+ "magma_cream",
+ "brewing_stand",
+ "cauldron",
+ "ender_eye",
+ "speckled_melon",
+ "spawn_egg",
+ "experience_bottle",
+ "fire_charge",
+
+ "writable_book",
+ "written_book",
+ "emerald",
+ "item_frame",
+ "flower_pot",
+ "carrot",
+ "potato",
+ "baked_potato",
+ "poisonous_potato",
+ "map",
+
+ "golden_carrot",
+ "skull",
+ "carrot_on_a_stick",
+ "nether_star",
+ "pumpkin_pie",
+ "fireworks",
+ "firework_charge",
+ "enchanted_book",
+ "comparator",
+ "netherbrick",
+
+ "quartz",
+ "tnt_minecart",
+ "hopper_minecart",
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+
+ null,
+ "iron_horse_armor",
+ "golden_horse_armor",
+ "diamond_horse_armor",
+ "lead",
+ "name_tag",
+ "command_block_minecart"
+ };
+ private static final String[] DISC_IDENTIFIERS = {
+ "record_13",
+ "record_cat",
+ "record_blocks",
+ "record_chirp",
+ "record_far",
+ "record_mall",
+ "record_mellohi",
+ "record_stal",
+ "record_strad",
+ "record_ward",
+
+ "record_11",
+ "record_wait"
+ };
+
+ static final int ITEM_ID_OFFSET = 256;
+ static final int DISC_ITEM_ID_OFFSET = 2000 + ITEM_ID_OFFSET;
+
+ static void init() {
+ for (Field f : Item.class.getDeclaredFields()) {
+ if (Modifier.isStatic(f.getModifiers()) && Item.class.isAssignableFrom(f.getType())) {
+ try {
+ Item item = (Item) f.get(null);
+
+ if (item != null) {
+ String identifier = null;
+
+ if (item.id >= DISC_ITEM_ID_OFFSET) {
+ int id = item.id - DISC_ITEM_ID_OFFSET;
+
+ if (id >= 0 && id < DISC_IDENTIFIERS.length) {
+ identifier = DISC_IDENTIFIERS[id];
+ }
+ } else if (item.id >= ITEM_ID_OFFSET) {
+ int id = item.id - ITEM_ID_OFFSET;
+
+ if (id >= 0 && id < IDENTIFIERS.length) {
+ identifier = IDENTIFIERS[id];
+ }
+ }
+
+ if (identifier != null) {
+ ItemRegistryImpl.register(item.id, NamespacedIdentifiers.from(identifier), item);
+ }
+ }
+ } catch (Throwable t) {
+ }
+ }
+ }
+ }
+}
diff --git a/libraries/items/items-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/items/impl/item/ItemExtensionImpl.java b/libraries/items/items-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/items/impl/item/ItemExtensionImpl.java
new file mode 100644
index 00000000..52a911cd
--- /dev/null
+++ b/libraries/items/items-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/items/impl/item/ItemExtensionImpl.java
@@ -0,0 +1,6 @@
+package net.ornithemc.osl.items.impl.item;
+
+import net.ornithemc.osl.items.api.item.ItemExtension;
+
+public interface ItemExtensionImpl extends ItemExtension {
+}
diff --git a/libraries/items/items-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/items/impl/mixin/common/BlockItemAccess.java b/libraries/items/items-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/items/impl/mixin/common/BlockItemAccess.java
new file mode 100644
index 00000000..4d2224a9
--- /dev/null
+++ b/libraries/items/items-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/items/impl/mixin/common/BlockItemAccess.java
@@ -0,0 +1,14 @@
+package net.ornithemc.osl.items.impl.mixin.common;
+
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.gen.Accessor;
+
+import net.minecraft.item.BlockItem;
+
+@Mixin(BlockItem.class)
+public interface BlockItemAccess {
+
+ @Accessor("block")
+ int accessBlock();
+
+}
diff --git a/libraries/items/items-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/items/impl/mixin/common/BlockMixin.java b/libraries/items/items-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/items/impl/mixin/common/BlockMixin.java
new file mode 100644
index 00000000..61efe4bd
--- /dev/null
+++ b/libraries/items/items-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/items/impl/mixin/common/BlockMixin.java
@@ -0,0 +1,117 @@
+package net.ornithemc.osl.items.impl.mixin.common;
+
+import org.objectweb.asm.Opcodes;
+
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.Slice;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
+import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
+import com.llamalad7.mixinextras.sugar.Share;
+import com.llamalad7.mixinextras.sugar.ref.LocalBooleanRef;
+import com.llamalad7.mixinextras.sugar.ref.LocalRef;
+
+import net.minecraft.block.Block;
+import net.minecraft.item.BlockItem;
+import net.minecraft.item.Item;
+
+import net.ornithemc.osl.items.impl.ItemRegistryImpl;
+
+@Mixin(Block.class)
+public class BlockMixin {
+
+ /*
+ * Block and Item initialization is cursed AF prior to 13w36a.
+ * There are no registries, only arrays, and all initialization
+ * happens in the static initializer instead of a dedicated init
+ * method.
+ *
+ * In general the order of operations is as follows:
+ * 1. Block::