diff --git a/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/blocks/api/BlockEvents.java b/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/blocks/api/BlockEvents.java
index c2d7af638..9a76f18be 100644
--- a/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/blocks/api/BlockEvents.java
+++ b/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/blocks/api/BlockEvents.java
@@ -22,7 +22,7 @@ public final class BlockEvents {
*
* {@code
* BlockEvents.REGISTER_BLOCKS.register(() -> {
- * BlockRegistry.register(99, NamespacedIdentifiers.from("example", "cookie"), new CookieBlock());
+ * BlockRegistry.register(NamespacedIdentifiers.from("example", "cookie"), new CookieBlock());
* });
* }
*
diff --git a/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/blocks/api/BlockRegistry.java b/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/blocks/api/BlockRegistry.java
index 003e6ec54..ae6522ef9 100644
--- a/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/blocks/api/BlockRegistry.java
+++ b/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/blocks/api/BlockRegistry.java
@@ -6,12 +6,16 @@
import net.ornithemc.osl.blocks.impl.BlockRegistryImpl;
import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.registries.api.registry.DefaultedRegistry;
+import net.ornithemc.osl.registries.api.registry.ResourceKey;
/**
* Public access to the Blocks registry.
*/
public final class BlockRegistry {
+ public static final DefaultedRegistry REGISTRY = BlockRegistryImpl.REGISTRY;
+
/**
* @return the numerical ID assigned to the given block.
*/
@@ -22,7 +26,14 @@ public static int getId(Block block) {
/**
* @return the namespaced ID assigned to the given block.
*/
- public static NamespacedIdentifier getKey(Block block) {
+ public static NamespacedIdentifier getIdentifier(Block block) {
+ return BlockRegistryImpl.getIdentifier(block);
+ }
+
+ /**
+ * @return the resource key assigned to the given block.
+ */
+ public static ResourceKey getKey(Block block) {
return BlockRegistryImpl.getKey(block);
}
@@ -36,24 +47,62 @@ public static Block getBlock(int id) {
/**
* @return the block mapped to the given namespaced ID.
*/
- public static Block getBlock(NamespacedIdentifier key) {
+ public static Block getBlock(NamespacedIdentifier identifier) {
+ return BlockRegistryImpl.getBlock(identifier);
+ }
+
+ /**
+ * @return the block mapped to the given resource key.
+ */
+ public static Block getBlock(ResourceKey key) {
return BlockRegistryImpl.getBlock(key);
}
/**
* @return a set containing all namespaced IDs in the registry.
*/
- public static Set keySet() {
+ public static Set identifierSet() {
+ return BlockRegistryImpl.identifierSet();
+ }
+
+ /**
+ * @return a set containing all resource keys in the registry.
+ */
+ public static Set> keySet() {
return BlockRegistryImpl.keySet();
}
+ /**
+ * @param the block type.
+ * @param identifier the namespaced ID of the block.
+ * @param block the block to register.
+ * @return the registered block.
+ */
+ public static T register(NamespacedIdentifier identifier, T block) {
+ return BlockRegistryImpl.register(identifier, block);
+ }
+
+ /**
+ * @param the block type.
+ * @param key the resource key of the block.
+ * @param block the block to register.
+ * @return the registered block.
+ */
+ public static T register(ResourceKey key, T block) {
+ return BlockRegistryImpl.register(key, block);
+ }
+
/**
* @param the block type.
* @param id the numerical ID of the block.
* @param key the namespaced ID of the block.
* @param block the block to register.
* @return the registered block.
+ *
+ * @deprecated use {@linkplain #register(NamespacedIdentifier, Block)}
+ * or {@linkplain #register(ResourceKey, Block)} instead.
*/
+ @Deprecated
public static T register(int id, NamespacedIdentifier key, T block) {
return BlockRegistryImpl.register(id, key, block);
}
diff --git a/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/blocks/impl/BlockRegistryImpl.java b/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/blocks/impl/BlockRegistryImpl.java
index d8244fc98..51569a41a 100644
--- a/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/blocks/impl/BlockRegistryImpl.java
+++ b/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/blocks/impl/BlockRegistryImpl.java
@@ -1,72 +1,90 @@
package net.ornithemc.osl.blocks.impl;
import java.util.Set;
-import java.util.stream.Collectors;
import net.minecraft.block.Block;
import net.ornithemc.osl.blocks.api.BlockEvents;
import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
-import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
+import net.ornithemc.osl.registries.api.registry.DefaultedRegistry;
+import net.ornithemc.osl.registries.api.registry.Registry;
+import net.ornithemc.osl.registries.api.registry.RegistryKeys;
+import net.ornithemc.osl.registries.api.registry.ResourceKey;
+import net.ornithemc.osl.registries.api.registry.SyncedRegistries;
+import net.ornithemc.osl.registries.impl.registry.VanillaRegistries;
public final class BlockRegistryImpl {
+ public static final DefaultedRegistry REGISTRY = VanillaRegistries.registerDefaulted(RegistryKeys.BLOCK, Block.REGISTRY);
+
private static boolean locked = true;
- private static boolean initialized = false;
public static int getId(Block block) {
- return Block.REGISTRY.getId(block);
+ return REGISTRY.getId(block);
+ }
+
+ public static NamespacedIdentifier getIdentifier(Block block) {
+ return REGISTRY.getIdentifier(block);
}
- public static NamespacedIdentifier getKey(Block block) {
- String key = Block.REGISTRY.getKey(block);
- return key == null ? null : NamespacedIdentifiers.parse(key);
+ public static ResourceKey getKey(Block block) {
+ return REGISTRY.getKey(block);
}
public static Block getBlock(int id) {
- return Block.REGISTRY.get(id);
+ return REGISTRY.get(id);
}
- public static Block getBlock(NamespacedIdentifier key) {
- return Block.REGISTRY.get(key.toString());
+ public static Block getBlock(NamespacedIdentifier identifier) {
+ return REGISTRY.get(identifier);
}
- public static Set keySet() {
- return Block.REGISTRY.keySet().stream().map(NamespacedIdentifiers::parse).collect(Collectors.toSet());
+ public static Block getBlock(ResourceKey key) {
+ return REGISTRY.get(key);
}
- public static T register(int id, NamespacedIdentifier key, T block) {
+ public static Set identifierSet() {
+ return REGISTRY.identifierSet();
+ }
+
+ public static Set> keySet() {
+ return REGISTRY.keySet();
+ }
+
+ public static T register(NamespacedIdentifier identifier, T block) {
if (locked) {
- throw new IllegalStateException("register called too " + (initialized ? "late" : "early") + ": registry locked!");
+ throw new IllegalStateException("register called too early: registry locked!");
} else {
- Block.REGISTRY.register(id, key.toString(), block);
+ return Registry.register(REGISTRY, identifier, block);
}
+ }
- return block;
+ public static T register(ResourceKey key, T block) {
+ if (locked) {
+ throw new IllegalStateException("register called too early: registry locked!");
+ } else {
+ return Registry.register(REGISTRY, key, block);
+ }
}
- public static void lock() {
- if (!initialized) {
- throw new IllegalStateException("cannot lock block registry unless it's been initialized!");
+ @Deprecated
+ public static T register(int id, NamespacedIdentifier key, T block) {
+ if (locked) {
+ throw new IllegalStateException("register called too early: registry locked!");
+ } else {
+ return Registry.register(REGISTRY, id, key, block);
}
+ }
- locked = true;
+ public static void init() {
+ SyncedRegistries.register(RegistryKeys.BLOCK);
}
public static void unlock() {
- if (initialized) {
- throw new IllegalStateException("cannot unlock block registry once it's been initialized!");
- }
-
locked = false;
}
- public static void init() {
- if (locked) {
- throw new IllegalStateException("cannot initialize block registry when it's locked!");
- }
-
+ public static void registerBlocks() {
BlockEvents.REGISTER_BLOCKS.invoker().run();
- initialized = true;
}
}
diff --git a/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/blocks/impl/block/AirBlock.java b/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/blocks/impl/block/AirBlock.java
index 183b3ac0d..d597e30c5 100644
--- a/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/blocks/impl/block/AirBlock.java
+++ b/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/blocks/impl/block/AirBlock.java
@@ -11,6 +11,11 @@ public AirBlock() {
super(Material.AIR);
}
+ @Override
+ public boolean isAir() {
+ return true;
+ }
+
@Override
public int getRenderType() {
return -1;
diff --git a/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockPostInit.java b/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockPostInit.java
new file mode 100644
index 000000000..1c4cdcef4
--- /dev/null
+++ b/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockPostInit.java
@@ -0,0 +1,7 @@
+package net.ornithemc.osl.blocks.impl.block;
+
+public interface BlockPostInit {
+
+ void osl$blocks$postInit();
+
+}
diff --git a/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin.java b/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin.java
index 407274083..83f2b2e54 100644
--- a/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin.java
+++ b/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin.java
@@ -1,20 +1,34 @@
package net.ornithemc.osl.blocks.impl.mixin.common;
import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import net.minecraft.block.Block;
+import net.minecraft.entity.living.mob.monster.EndermanEntity;
+import net.ornithemc.osl.blocks.api.BlockRegistry;
import net.ornithemc.osl.blocks.api.block.BlockExtension;
import net.ornithemc.osl.blocks.impl.BlockRegistryImpl;
import net.ornithemc.osl.blocks.impl.BlocksMixinPlugin;
import net.ornithemc.osl.blocks.impl.block.AirBlock;
+import net.ornithemc.osl.blocks.impl.block.BlockPostInit;
+import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
+import net.ornithemc.osl.core.impl.util.Util;
+import net.ornithemc.osl.registries.api.registry.RegistryKeys;
+import net.ornithemc.osl.registries.api.registry.SyncedRegistries;
+import net.ornithemc.osl.registries.api.registry.sync.BooleanArrayMapper;
@Mixin(Block.class)
public class BlockMixin implements BlockExtension {
+ @Shadow
+ private String key;
+
@Inject(
method = "init",
at = @At(
@@ -36,14 +50,47 @@ public class BlockMixin implements BlockExtension {
target = "Lnet/minecraft/util/registry/IdRegistry;iterator()Ljava/util/Iterator;"
)
)
- private static void osl$blocks$initAndLockBlockRegistry(CallbackInfo ci) {
- BlockRegistryImpl.init();
- BlockRegistryImpl.lock();
+ private static void osl$blocks$registerBlocks(CallbackInfo ci) {
+ BlockRegistryImpl.registerBlocks();
+
+ for (Block block : Block.REGISTRY) {
+ if (block instanceof BlockPostInit) {
+ ((BlockPostInit) block).osl$blocks$postInit();
+ }
+ }
+ }
+
+ @Inject(
+ method = "init",
+ at = @At(
+ value = "TAIL"
+ )
+ )
+ private static void osl$blocks$registerArrayMappers(CallbackInfo ci) {
+ SyncedRegistries.registerMapper(RegistryKeys.BLOCK, NamespacedIdentifiers.from("block/enderman_holdable"), BooleanArrayMapper.of(EndermanEntity.HOLDABLE_BLOCKS));
+ }
+
+ @Inject(
+ method = "getTranslationKey",
+ at = @At(
+ value = "HEAD"
+ )
+ )
+ private void osl$blocks$autoAssignTranslationKey(CallbackInfoReturnable cir) {
+ if (this.key == null) {
+ NamespacedIdentifier identifier = BlockRegistry.getIdentifier((Block) (Object) this);
+
+ if (identifier == null) {
+ this.key = "unknown";
+ } else {
+ this.key = Util.makeTranslationKey(identifier);
+ }
+ }
}
@Override
public String toString() {
- return "Block{" + BlockRegistryImpl.getKey((Block) (Object) this) + "}";
+ return "Block{" + BlockRegistryImpl.getIdentifier((Block) (Object) this) + "}";
}
@Override
diff --git a/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/EndermanEntityMixin.java b/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/EndermanEntityMixin.java
new file mode 100644
index 000000000..7547898bf
--- /dev/null
+++ b/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/EndermanEntityMixin.java
@@ -0,0 +1,48 @@
+package net.ornithemc.osl.blocks.impl.mixin.common;
+
+import org.objectweb.asm.Opcodes;
+
+import org.spongepowered.asm.mixin.Final;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Mutable;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.At.Shift;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import net.minecraft.block.Block;
+import net.minecraft.entity.living.mob.monster.EndermanEntity;
+
+import net.ornithemc.osl.registries.api.registry.sync.DynamicArrays;
+
+@Mixin(EndermanEntity.class)
+public class EndermanEntityMixin {
+
+ // what the fuck, mojang?
+ @Shadow @Final @Mutable
+ private static boolean[] HOLDABLE_BLOCKS;
+
+ @Inject(
+ method = "",
+ at = @At(
+ value = "FIELD",
+ target = "Lnet/minecraft/entity/living/mob/monster/EndermanEntity;HOLDABLE_BLOCKS:[Z",
+ opcode = Opcodes.PUTSTATIC,
+ shift = Shift.AFTER
+ )
+ )
+ private static void osl$blocks$growArray(CallbackInfo ci) {
+ int capacity = HOLDABLE_BLOCKS.length;
+
+ for (Block block : Block.REGISTRY) {
+ int required = Block.getId(block) + 1;
+
+ if (required > capacity) {
+ capacity = required;
+ }
+ }
+
+ HOLDABLE_BLOCKS = DynamicArrays.grow(HOLDABLE_BLOCKS, capacity);
+ }
+}
diff --git a/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/FireBlockMixin.java b/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/FireBlockMixin.java
new file mode 100644
index 000000000..5db1b443b
--- /dev/null
+++ b/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/FireBlockMixin.java
@@ -0,0 +1,53 @@
+package net.ornithemc.osl.blocks.impl.mixin.common;
+
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import net.minecraft.block.FireBlock;
+
+import net.ornithemc.osl.blocks.api.BlockRegistry;
+import net.ornithemc.osl.blocks.impl.block.BlockPostInit;
+import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.registries.api.registry.RegistryKeys;
+import net.ornithemc.osl.registries.api.registry.SyncedRegistries;
+import net.ornithemc.osl.registries.api.registry.sync.DynamicArrays;
+import net.ornithemc.osl.registries.api.registry.sync.IntArrayMapper;
+import net.ornithemc.osl.registries.impl.registry.RegistriesImpl;
+
+@Mixin(FireBlock.class)
+public class FireBlockMixin implements BlockPostInit {
+
+ @Shadow
+ private int[] flammability;
+ @Shadow
+ private int[] burnChance;
+
+ @Inject(
+ method = "setFlammable",
+ at = @At(
+ value = "HEAD"
+ )
+ )
+ private void osl$blocks$growArrays(int block, int flammability, int burnChance, CallbackInfo ci) {
+ int capacity = block + 1;
+
+ this.flammability = DynamicArrays.grow(this.flammability, capacity);
+ this.burnChance = DynamicArrays.grow(this.burnChance, capacity);
+ }
+
+ @Override
+ public void osl$blocks$postInit() {
+ FireBlock block = (FireBlock) (Object) this;
+ NamespacedIdentifier identifier = BlockRegistry.getIdentifier(block);
+
+ if (identifier == null) {
+ RegistriesImpl.LOGGER.warn("Unable to register FireBlock array mappers for unregistered block {}", block);
+ } else {
+ SyncedRegistries.registerMapper(RegistryKeys.BLOCK, identifier.suffixed("/flammability"), IntArrayMapper.of(this.flammability));
+ SyncedRegistries.registerMapper(RegistryKeys.BLOCK, identifier.suffixed("/burn_chance"), IntArrayMapper.of(this.burnChance));
+ }
+ }
+}
diff --git a/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/StatsMixin.java b/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/StatsMixin.java
new file mode 100644
index 000000000..880fc854d
--- /dev/null
+++ b/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/StatsMixin.java
@@ -0,0 +1,44 @@
+package net.ornithemc.osl.blocks.impl.mixin.common;
+
+import java.util.Map;
+
+import org.spongepowered.asm.mixin.Final;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import net.minecraft.stat.Stat;
+import net.minecraft.stat.Stats;
+
+import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
+import net.ornithemc.osl.core.impl.util.MinecraftVersion;
+import net.ornithemc.osl.registries.api.registry.RegistryKeys;
+import net.ornithemc.osl.registries.api.registry.SyncedRegistries;
+import net.ornithemc.osl.registries.api.registry.sync.ObjectArrayMapper;
+import net.ornithemc.osl.registries.impl.registry.sync.StatsMapper;
+
+@Mixin(Stats.class)
+public class StatsMixin {
+
+ @Shadow @Final
+ private static Map BY_KEY;
+ @Shadow @Final
+ private static Stat[] BLOCKS_MINED;
+
+ @Inject(
+ // inject at init instead of in case the arrays are resized...
+ method = "init",
+ at = @At(
+ value = "TAIL"
+ )
+ )
+ private static void osl$items$registerStatsMapper(CallbackInfo ci) {
+ if (MinecraftVersion.resolve().compareTo("14w06a") < 0) {
+ SyncedRegistries.registerMapper(RegistryKeys.BLOCK, NamespacedIdentifiers.from("stats/mined"), StatsMapper.of(BY_KEY, BLOCKS_MINED));
+ } else {
+ SyncedRegistries.registerMapper(RegistryKeys.BLOCK, NamespacedIdentifiers.from("stats/mined"), ObjectArrayMapper.of(BLOCKS_MINED));
+ }
+ }
+}
diff --git a/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/resources/fabric.mod.json b/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/resources/fabric.mod.json
index 2730c538b..d63ce5ab3 100644
--- a/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/resources/fabric.mod.json
+++ b/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/resources/fabric.mod.json
@@ -3,6 +3,11 @@
"id": "osl-blocks",
"version": "0.1.1+mc13w36a-mc14w26c",
"environment": "*",
+ "entrypoints": {
+ "init": [
+ "net.ornithemc.osl.blocks.impl.BlockRegistryImpl::init"
+ ]
+ },
"mixins": [
"osl.blocks.mixins.json"
],
@@ -10,7 +15,14 @@
"depends": {
"fabricloader": "\u003e\u003d0.18.0",
"minecraft": "\u003e\u003d1.7-alpha.13.36.a \u003c\u003d1.8-alpha.14.26.c",
- "osl-core": "\u003e\u003d0.9.0"
+ "osl-core": "\u003e\u003d0.9.0",
+ "osl-entrypoints": "\u003e\u003d0.5.0",
+ "osl-lifecycle-events": "\u003e\u003d0.6.0",
+ "osl-executors": "\u003e\u003d0.1.0",
+ "osl-text-components": "\u003e\u003d0.1.0-",
+ "osl-networking": "\u003e\u003d0.9.0",
+ "osl-networking-impl": "\u003e\u003d0.1.0",
+ "osl-registries": "\u003e\u003d0.1.0-"
},
"name": "OSL Blocks",
"description": "Blocks API and events.",
diff --git a/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/resources/osl.blocks.classtweaker b/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/resources/osl.blocks.classtweaker
index e8fc2dcbf..7ea8571ed 100644
--- a/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/resources/osl.blocks.classtweaker
+++ b/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/resources/osl.blocks.classtweaker
@@ -12,4 +12,7 @@ transitive-accessible method net/minecraft/block/Block setCreativeModeTab (Lnet/
transitive-accessible method net/minecraft/block/Block setSpriteName (Ljava/lang/String;)Lnet/minecraft/block/Block;
transitive-inject-interface net/minecraft/block/Block net/ornithemc/osl/blocks/impl/block/BlockExtensionImpl
-transitive-inject-interface net/minecraft/block/Blocks net/ornithemc/osl/blocks/impl/block/BlocksExtensionImpl
\ No newline at end of file
+transitive-inject-interface net/minecraft/block/Blocks net/ornithemc/osl/blocks/impl/block/BlocksExtensionImpl
+
+accessible field net/minecraft/entity/living/mob/monster/EndermanEntity HOLDABLE_BLOCKS [Z
+
diff --git a/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/resources/osl.blocks.mixins.json b/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/resources/osl.blocks.mixins.json
index be211c149..f6bd4d28c 100644
--- a/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/resources/osl.blocks.mixins.json
+++ b/libraries/blocks/blocks-mc13w36a-mc14w26c/src/main/resources/osl.blocks.mixins.json
@@ -7,7 +7,10 @@
"mixins": [
"common.AirBlockMixin",
"common.BlockMixin",
- "common.BlocksMixin"
+ "common.BlocksMixin",
+ "common.EndermanEntityMixin",
+ "common.FireBlockMixin",
+ "common.StatsMixin"
],
"client": [
],
diff --git a/libraries/blocks/blocks-mc14w27a-mc17w46a/build.gradle b/libraries/blocks/blocks-mc14w27a-mc15w35a/build.gradle
similarity index 100%
rename from libraries/blocks/blocks-mc14w27a-mc17w46a/build.gradle
rename to libraries/blocks/blocks-mc14w27a-mc15w35a/build.gradle
diff --git a/libraries/blocks/blocks-mc14w27a-mc15w35a/gradle.properties b/libraries/blocks/blocks-mc14w27a-mc15w35a/gradle.properties
new file mode 100644
index 000000000..7b3826dbc
--- /dev/null
+++ b/libraries/blocks/blocks-mc14w27a-mc15w35a/gradle.properties
@@ -0,0 +1,5 @@
+min_mc_version = 14w27a
+max_mc_version = 15w35a
+minecraft_dependency = >=1.8-alpha.14.27.a <=1.9-alpha.15.35.a
+
+minecraft_version = 1.8.9
diff --git a/libraries/blocks/blocks-mc14w27a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/api/BlockEvents.java b/libraries/blocks/blocks-mc14w27a-mc15w35a/src/main/java/net/ornithemc/osl/blocks/api/BlockEvents.java
similarity index 88%
rename from libraries/blocks/blocks-mc14w27a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/api/BlockEvents.java
rename to libraries/blocks/blocks-mc14w27a-mc15w35a/src/main/java/net/ornithemc/osl/blocks/api/BlockEvents.java
index c2d7af638..9a76f18be 100644
--- a/libraries/blocks/blocks-mc14w27a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/api/BlockEvents.java
+++ b/libraries/blocks/blocks-mc14w27a-mc15w35a/src/main/java/net/ornithemc/osl/blocks/api/BlockEvents.java
@@ -22,7 +22,7 @@ public final class BlockEvents {
*
* {@code
* BlockEvents.REGISTER_BLOCKS.register(() -> {
- * BlockRegistry.register(99, NamespacedIdentifiers.from("example", "cookie"), new CookieBlock());
+ * BlockRegistry.register(NamespacedIdentifiers.from("example", "cookie"), new CookieBlock());
* });
* }
*
diff --git a/libraries/blocks/blocks-mc14w27a-mc15w35a/src/main/java/net/ornithemc/osl/blocks/api/BlockRegistry.java b/libraries/blocks/blocks-mc14w27a-mc15w35a/src/main/java/net/ornithemc/osl/blocks/api/BlockRegistry.java
new file mode 100644
index 000000000..ae6522ef9
--- /dev/null
+++ b/libraries/blocks/blocks-mc14w27a-mc15w35a/src/main/java/net/ornithemc/osl/blocks/api/BlockRegistry.java
@@ -0,0 +1,109 @@
+package net.ornithemc.osl.blocks.api;
+
+import java.util.Set;
+
+import net.minecraft.block.Block;
+
+import net.ornithemc.osl.blocks.impl.BlockRegistryImpl;
+import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.registries.api.registry.DefaultedRegistry;
+import net.ornithemc.osl.registries.api.registry.ResourceKey;
+
+/**
+ * Public access to the Blocks registry.
+ */
+public final class BlockRegistry {
+
+ public static final DefaultedRegistry REGISTRY = BlockRegistryImpl.REGISTRY;
+
+ /**
+ * @return the numerical ID assigned to the given block.
+ */
+ public static int getId(Block block) {
+ return BlockRegistryImpl.getId(block);
+ }
+
+ /**
+ * @return the namespaced ID assigned to the given block.
+ */
+ public static NamespacedIdentifier getIdentifier(Block block) {
+ return BlockRegistryImpl.getIdentifier(block);
+ }
+
+ /**
+ * @return the resource key assigned to the given block.
+ */
+ public static ResourceKey getKey(Block block) {
+ return BlockRegistryImpl.getKey(block);
+ }
+
+ /**
+ * @return the block mapped to the given numerical ID.
+ */
+ public static Block getBlock(int id) {
+ return BlockRegistryImpl.getBlock(id);
+ }
+
+ /**
+ * @return the block mapped to the given namespaced ID.
+ */
+ public static Block getBlock(NamespacedIdentifier identifier) {
+ return BlockRegistryImpl.getBlock(identifier);
+ }
+
+ /**
+ * @return the block mapped to the given resource key.
+ */
+ public static Block getBlock(ResourceKey key) {
+ return BlockRegistryImpl.getBlock(key);
+ }
+
+ /**
+ * @return a set containing all namespaced IDs in the registry.
+ */
+ public static Set identifierSet() {
+ return BlockRegistryImpl.identifierSet();
+ }
+
+ /**
+ * @return a set containing all resource keys in the registry.
+ */
+ public static Set> keySet() {
+ return BlockRegistryImpl.keySet();
+ }
+
+ /**
+ * @param the block type.
+ * @param identifier the namespaced ID of the block.
+ * @param block the block to register.
+ * @return the registered block.
+ */
+ public static T register(NamespacedIdentifier identifier, T block) {
+ return BlockRegistryImpl.register(identifier, block);
+ }
+
+ /**
+ * @param the block type.
+ * @param key the resource key of the block.
+ * @param block the block to register.
+ * @return the registered block.
+ */
+ public static T register(ResourceKey key, T block) {
+ return BlockRegistryImpl.register(key, block);
+ }
+
+ /**
+ * @param the block type.
+ * @param id the numerical ID of the block.
+ * @param key the namespaced ID of the block.
+ * @param block the block to register.
+ * @return the registered block.
+ *
+ * @deprecated use {@linkplain #register(NamespacedIdentifier, Block)}
+ * or {@linkplain #register(ResourceKey, Block)} instead.
+ */
+ @Deprecated
+ public static T register(int id, NamespacedIdentifier key, T block) {
+ return BlockRegistryImpl.register(id, key, block);
+ }
+}
diff --git a/libraries/blocks/blocks-mc14w27a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/api/block/BlockExtension.java b/libraries/blocks/blocks-mc14w27a-mc15w35a/src/main/java/net/ornithemc/osl/blocks/api/block/BlockExtension.java
similarity index 100%
rename from libraries/blocks/blocks-mc14w27a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/api/block/BlockExtension.java
rename to libraries/blocks/blocks-mc14w27a-mc15w35a/src/main/java/net/ornithemc/osl/blocks/api/block/BlockExtension.java
diff --git a/libraries/blocks/blocks-mc14w27a-mc15w35a/src/main/java/net/ornithemc/osl/blocks/impl/BlockRegistryImpl.java b/libraries/blocks/blocks-mc14w27a-mc15w35a/src/main/java/net/ornithemc/osl/blocks/impl/BlockRegistryImpl.java
new file mode 100644
index 000000000..3707a727b
--- /dev/null
+++ b/libraries/blocks/blocks-mc14w27a-mc15w35a/src/main/java/net/ornithemc/osl/blocks/impl/BlockRegistryImpl.java
@@ -0,0 +1,93 @@
+package net.ornithemc.osl.blocks.impl;
+
+import java.util.Set;
+
+import net.minecraft.block.Block;
+
+import net.ornithemc.osl.blocks.api.BlockEvents;
+import net.ornithemc.osl.blocks.impl.block.BlockStateRegistryFixer;
+import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
+import net.ornithemc.osl.registries.api.registry.DefaultedRegistry;
+import net.ornithemc.osl.registries.api.registry.Registry;
+import net.ornithemc.osl.registries.api.registry.RegistryKeys;
+import net.ornithemc.osl.registries.api.registry.ResourceKey;
+import net.ornithemc.osl.registries.api.registry.SyncedRegistries;
+import net.ornithemc.osl.registries.impl.registry.VanillaRegistries;
+
+public final class BlockRegistryImpl {
+
+ public static final DefaultedRegistry REGISTRY = VanillaRegistries.registerDefaulted(RegistryKeys.BLOCK, Block.REGISTRY);
+
+ private static boolean locked = true;
+
+ public static int getId(Block block) {
+ return REGISTRY.getId(block);
+ }
+
+ public static NamespacedIdentifier getIdentifier(Block block) {
+ return REGISTRY.getIdentifier(block);
+ }
+
+ public static ResourceKey getKey(Block block) {
+ return REGISTRY.getKey(block);
+ }
+
+ public static Block getBlock(int id) {
+ return REGISTRY.get(id);
+ }
+
+ public static Block getBlock(NamespacedIdentifier identifier) {
+ return REGISTRY.get(identifier);
+ }
+
+ public static Block getBlock(ResourceKey key) {
+ return REGISTRY.get(key);
+ }
+
+ public static Set identifierSet() {
+ return REGISTRY.identifierSet();
+ }
+
+ public static Set> keySet() {
+ return REGISTRY.keySet();
+ }
+
+ public static T register(NamespacedIdentifier identifier, T block) {
+ if (locked) {
+ throw new IllegalStateException("register called too early: registry locked!");
+ } else {
+ return Registry.register(REGISTRY, identifier, block);
+ }
+ }
+
+ public static T register(ResourceKey key, T block) {
+ if (locked) {
+ throw new IllegalStateException("register called too early: registry locked!");
+ } else {
+ return Registry.register(REGISTRY, key, block);
+ }
+ }
+
+ @Deprecated
+ public static T register(int id, NamespacedIdentifier key, T block) {
+ if (locked) {
+ throw new IllegalStateException("register called too early: registry locked!");
+ } else {
+ return Registry.register(REGISTRY, id, key, block);
+ }
+ }
+
+ public static void init() {
+ SyncedRegistries.register(RegistryKeys.BLOCK);
+ SyncedRegistries.registerFixer(RegistryKeys.BLOCK, NamespacedIdentifiers.from("blockstate"), new BlockStateRegistryFixer());
+ }
+
+ public static void unlock() {
+ locked = false;
+ }
+
+ public static void registerBlocks() {
+ BlockEvents.REGISTER_BLOCKS.invoker().run();
+ }
+}
diff --git a/libraries/blocks/blocks-mc14w27a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockExtensionImpl.java b/libraries/blocks/blocks-mc14w27a-mc15w35a/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockExtensionImpl.java
similarity index 100%
rename from libraries/blocks/blocks-mc14w27a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockExtensionImpl.java
rename to libraries/blocks/blocks-mc14w27a-mc15w35a/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockExtensionImpl.java
diff --git a/libraries/blocks/blocks-mc14w27a-mc15w35a/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockStateRegistryFixer.java b/libraries/blocks/blocks-mc14w27a-mc15w35a/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockStateRegistryFixer.java
new file mode 100644
index 000000000..9f42817d0
--- /dev/null
+++ b/libraries/blocks/blocks-mc14w27a-mc15w35a/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockStateRegistryFixer.java
@@ -0,0 +1,26 @@
+package net.ornithemc.osl.blocks.impl.block;
+
+import net.minecraft.block.Block;
+import net.minecraft.block.state.BlockState;
+import net.ornithemc.osl.blocks.api.BlockRegistry;
+import net.ornithemc.osl.registries.api.registry.sync.IdFixer;
+import net.ornithemc.osl.registries.impl.access.Clearable;
+
+public class BlockStateRegistryFixer implements IdFixer {
+
+ @Override
+ public void apply() {
+ Clearable.clear(Block.STATE_REGISTRY);
+
+ for (Block block : BlockRegistry.REGISTRY) {
+ int blockId = BlockRegistry.getId(block);
+
+ for (BlockState state : block.stateDefinition().all()) {
+ int metadata = block.getMetadataFromState(state);
+ int stateId = blockId << 4 | metadata;
+
+ Block.STATE_REGISTRY.put(state, stateId);
+ }
+ }
+ }
+}
diff --git a/libraries/blocks/blocks-mc14w27a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/AirBlockMixin.java b/libraries/blocks/blocks-mc14w27a-mc15w35a/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/AirBlockMixin.java
similarity index 100%
rename from libraries/blocks/blocks-mc14w27a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/AirBlockMixin.java
rename to libraries/blocks/blocks-mc14w27a-mc15w35a/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/AirBlockMixin.java
diff --git a/libraries/blocks/blocks-mc14w27a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin.java b/libraries/blocks/blocks-mc14w27a-mc15w35a/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin.java
similarity index 51%
rename from libraries/blocks/blocks-mc14w27a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin.java
rename to libraries/blocks/blocks-mc14w27a-mc15w35a/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin.java
index 6b4e6bf51..95961cce2 100644
--- a/libraries/blocks/blocks-mc14w27a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin.java
+++ b/libraries/blocks/blocks-mc14w27a-mc15w35a/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin.java
@@ -1,18 +1,26 @@
package net.ornithemc.osl.blocks.impl.mixin.common;
import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import net.minecraft.block.Block;
+import net.ornithemc.osl.blocks.api.BlockRegistry;
import net.ornithemc.osl.blocks.api.block.BlockExtension;
import net.ornithemc.osl.blocks.impl.BlockRegistryImpl;
+import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.core.impl.util.Util;
@Mixin(Block.class)
public class BlockMixin implements BlockExtension {
+ @Shadow
+ private String key;
+
@Inject(
method = "init",
at = @At(
@@ -30,9 +38,26 @@ public class BlockMixin implements BlockExtension {
target = "Lnet/minecraft/util/registry/DefaultedIdRegistry;validate()V"
)
)
- private static void osl$blocks$initAndLockBlockRegistry(CallbackInfo ci) {
- BlockRegistryImpl.init();
- BlockRegistryImpl.lock();
+ private static void osl$blocks$registerBlocks(CallbackInfo ci) {
+ BlockRegistryImpl.registerBlocks();
+ }
+
+ @Inject(
+ method = "getTranslationKey",
+ at = @At(
+ value = "HEAD"
+ )
+ )
+ private void osl$blocks$autoAssignTranslationKey(CallbackInfoReturnable cir) {
+ if (this.key == null) {
+ NamespacedIdentifier identifier = BlockRegistry.getIdentifier((Block) (Object) this);
+
+ if (identifier == null) {
+ this.key = "unknown";
+ } else {
+ this.key = Util.makeTranslationKey(identifier);
+ }
+ }
}
@Override
diff --git a/libraries/blocks/blocks-mc14w27a-mc15w35a/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/StatsMixin.java b/libraries/blocks/blocks-mc14w27a-mc15w35a/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/StatsMixin.java
new file mode 100644
index 000000000..019e93566
--- /dev/null
+++ b/libraries/blocks/blocks-mc14w27a-mc15w35a/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/StatsMixin.java
@@ -0,0 +1,34 @@
+package net.ornithemc.osl.blocks.impl.mixin.common;
+
+import org.spongepowered.asm.mixin.Final;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import net.minecraft.stat.Stat;
+import net.minecraft.stat.Stats;
+
+import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
+import net.ornithemc.osl.registries.api.registry.RegistryKeys;
+import net.ornithemc.osl.registries.api.registry.SyncedRegistries;
+import net.ornithemc.osl.registries.api.registry.sync.ObjectArrayMapper;
+
+@Mixin(Stats.class)
+public class StatsMixin {
+
+ @Shadow @Final
+ private static Stat[] BLOCKS_MINED;
+
+ @Inject(
+ // inject at init instead of in case the arrays are resized...
+ method = "init",
+ at = @At(
+ value = "TAIL"
+ )
+ )
+ private static void osl$items$registerStatsMapper(CallbackInfo ci) {
+ SyncedRegistries.registerMapper(RegistryKeys.BLOCK, NamespacedIdentifiers.from("stats/mined"), ObjectArrayMapper.of(BLOCKS_MINED));
+ }
+}
diff --git a/libraries/blocks/blocks-mc14w27a-mc15w35a/src/main/resources/fabric.mod.json b/libraries/blocks/blocks-mc14w27a-mc15w35a/src/main/resources/fabric.mod.json
new file mode 100644
index 000000000..bbd4042bc
--- /dev/null
+++ b/libraries/blocks/blocks-mc14w27a-mc15w35a/src/main/resources/fabric.mod.json
@@ -0,0 +1,38 @@
+{
+ "schemaVersion": 1,
+ "id": "osl-blocks",
+ "version": "0.1.1+mc14w27a-mc15w35a",
+ "environment": "*",
+ "entrypoints": {
+ "init": [
+ "net.ornithemc.osl.blocks.impl.BlockRegistryImpl::init"
+ ]
+ },
+ "mixins": [
+ "osl.blocks.mixins.json"
+ ],
+ "accessWidener": "osl.blocks.classtweaker",
+ "depends": {
+ "fabricloader": "\u003e\u003d0.18.0",
+ "minecraft": "\u003e\u003d1.8-alpha.14.27.a \u003c\u003d1.9-alpha.15.35.a",
+ "osl-core": "\u003e\u003d0.9.0",
+ "osl-entrypoints": "\u003e\u003d0.5.0",
+ "osl-lifecycle-events": "\u003e\u003d0.6.0",
+ "osl-executors": "\u003e\u003d0.1.0",
+ "osl-text-components": "\u003e\u003d0.1.0-",
+ "osl-networking": "\u003e\u003d0.9.0",
+ "osl-networking-impl": "\u003e\u003d0.1.0",
+ "osl-registries": "\u003e\u003d0.1.0-"
+ },
+ "name": "OSL Blocks",
+ "description": "Blocks API and events.",
+ "authors": [
+ "OrnitheMC"
+ ],
+ "contact": {
+ "homepage": "https://ornithemc.net/",
+ "issues": "https://github.com/OrnitheMC/ornithe-standard-libraries/issues",
+ "sources": "https://github.com/OrnitheMC/ornithe-standard-libraries"
+ },
+ "license": "Apache-2.0"
+}
\ No newline at end of file
diff --git a/libraries/blocks/blocks-mc14w27a-mc15w35a/src/main/resources/osl.blocks.classtweaker b/libraries/blocks/blocks-mc14w27a-mc15w35a/src/main/resources/osl.blocks.classtweaker
new file mode 100644
index 000000000..73c405d73
--- /dev/null
+++ b/libraries/blocks/blocks-mc14w27a-mc15w35a/src/main/resources/osl.blocks.classtweaker
@@ -0,0 +1,14 @@
+classTweaker v1 named
+
+transitive-accessible method net/minecraft/block/Block setSounds (Lnet/minecraft/block/Block$Sounds;)Lnet/minecraft/block/Block;
+transitive-accessible method net/minecraft/block/Block setOpacity (I)Lnet/minecraft/block/Block;
+transitive-accessible method net/minecraft/block/Block setLight (F)Lnet/minecraft/block/Block;
+transitive-accessible method net/minecraft/block/Block setBlastResistance (F)Lnet/minecraft/block/Block;
+transitive-accessible method net/minecraft/block/Block setStrength (F)Lnet/minecraft/block/Block;
+transitive-accessible method net/minecraft/block/Block setUnbreakable ()Lnet/minecraft/block/Block;
+transitive-accessible method net/minecraft/block/Block setTicksRandomly (Z)Lnet/minecraft/block/Block;
+transitive-accessible method net/minecraft/block/Block setKey (Ljava/lang/String;)Lnet/minecraft/block/Block;
+transitive-accessible method net/minecraft/block/Block disableStats ()Lnet/minecraft/block/Block;
+transitive-accessible method net/minecraft/block/Block setCreativeModeTab (Lnet/minecraft/item/CreativeModeTab;)Lnet/minecraft/block/Block;
+
+transitive-inject-interface net/minecraft/block/Block net/ornithemc/osl/blocks/impl/block/BlockExtensionImpl
\ No newline at end of file
diff --git a/libraries/blocks/blocks-mc14w27a-mc17w46a/src/main/resources/osl.blocks.mixins.json b/libraries/blocks/blocks-mc14w27a-mc15w35a/src/main/resources/osl.blocks.mixins.json
similarity index 84%
rename from libraries/blocks/blocks-mc14w27a-mc17w46a/src/main/resources/osl.blocks.mixins.json
rename to libraries/blocks/blocks-mc14w27a-mc15w35a/src/main/resources/osl.blocks.mixins.json
index 7f2c19c8f..0b4c0fa73 100644
--- a/libraries/blocks/blocks-mc14w27a-mc17w46a/src/main/resources/osl.blocks.mixins.json
+++ b/libraries/blocks/blocks-mc14w27a-mc15w35a/src/main/resources/osl.blocks.mixins.json
@@ -5,7 +5,8 @@
"compatibilityLevel": "JAVA_8",
"mixins": [
"common.AirBlockMixin",
- "common.BlockMixin"
+ "common.BlockMixin",
+ "common.StatsMixin"
],
"client": [
],
diff --git a/libraries/blocks/blocks-mc14w27a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/api/BlockRegistry.java b/libraries/blocks/blocks-mc14w27a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/api/BlockRegistry.java
deleted file mode 100644
index 003e6ec54..000000000
--- a/libraries/blocks/blocks-mc14w27a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/api/BlockRegistry.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package net.ornithemc.osl.blocks.api;
-
-import java.util.Set;
-
-import net.minecraft.block.Block;
-
-import net.ornithemc.osl.blocks.impl.BlockRegistryImpl;
-import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
-
-/**
- * Public access to the Blocks registry.
- */
-public final class BlockRegistry {
-
- /**
- * @return the numerical ID assigned to the given block.
- */
- public static int getId(Block block) {
- return BlockRegistryImpl.getId(block);
- }
-
- /**
- * @return the namespaced ID assigned to the given block.
- */
- public static NamespacedIdentifier getKey(Block block) {
- return BlockRegistryImpl.getKey(block);
- }
-
- /**
- * @return the block mapped to the given numerical ID.
- */
- public static Block getBlock(int id) {
- return BlockRegistryImpl.getBlock(id);
- }
-
- /**
- * @return the block mapped to the given namespaced ID.
- */
- public static Block getBlock(NamespacedIdentifier key) {
- return BlockRegistryImpl.getBlock(key);
- }
-
- /**
- * @return a set containing all namespaced IDs in the registry.
- */
- public static Set keySet() {
- return BlockRegistryImpl.keySet();
- }
-
- /**
- * @param the block type.
- * @param id the numerical ID of the block.
- * @param key the namespaced ID of the block.
- * @param block the block to register.
- * @return the registered block.
- */
- public static T register(int id, NamespacedIdentifier key, T block) {
- return BlockRegistryImpl.register(id, key, block);
- }
-}
diff --git a/libraries/blocks/blocks-mc14w27a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/BlockRegistryImpl.java b/libraries/blocks/blocks-mc14w27a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/BlockRegistryImpl.java
deleted file mode 100644
index 287364453..000000000
--- a/libraries/blocks/blocks-mc14w27a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/BlockRegistryImpl.java
+++ /dev/null
@@ -1,75 +0,0 @@
-package net.ornithemc.osl.blocks.impl;
-
-import java.util.Collections;
-import java.util.Set;
-
-import net.minecraft.block.Block;
-import net.minecraft.resource.Identifier;
-
-import net.ornithemc.osl.blocks.api.BlockEvents;
-import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
-
-public final class BlockRegistryImpl {
-
- private static boolean locked = true;
- private static boolean initialized = false;
-
- public static int getId(Block block) {
- return Block.REGISTRY.getId(block);
- }
-
- public static NamespacedIdentifier getKey(Block block) {
- return Block.REGISTRY.getKey(block);
- }
-
- public static Block getBlock(int id) {
- return Block.REGISTRY.get(id);
- }
-
- public static Block getBlock(NamespacedIdentifier key) {
- return Block.REGISTRY.get(identifier(key));
- }
-
- public static Set keySet() {
- return Collections.unmodifiableSet(Block.REGISTRY.keySet());
- }
-
- public static T register(int id, NamespacedIdentifier key, T block) {
- if (locked) {
- throw new IllegalStateException("register called too " + (initialized ? "late" : "early") + ": registry locked!");
- } else {
- Block.REGISTRY.register(id, identifier(key), block);
- }
-
- return block;
- }
-
- private static Identifier identifier(NamespacedIdentifier id) {
- return id instanceof Identifier ? (Identifier) id : new Identifier(id.namespace(), id.identifier());
- }
-
- public static void lock() {
- if (!initialized) {
- throw new IllegalStateException("cannot lock block registry unless it's been initialized!");
- }
-
- locked = true;
- }
-
- public static void unlock() {
- if (initialized) {
- throw new IllegalStateException("cannot unlock block registry once it's been initialized!");
- }
-
- locked = false;
- }
-
- public static void init() {
- if (locked) {
- throw new IllegalStateException("cannot initialize block registry when it's locked!");
- }
-
- BlockEvents.REGISTER_BLOCKS.invoker().run();
- initialized = true;
- }
-}
diff --git a/libraries/blocks/blocks-mc15w36a-mc17w46a/build.gradle b/libraries/blocks/blocks-mc15w36a-mc17w46a/build.gradle
new file mode 100644
index 000000000..0a350fdb3
--- /dev/null
+++ b/libraries/blocks/blocks-mc15w36a-mc17w46a/build.gradle
@@ -0,0 +1 @@
+setUpModule(project)
diff --git a/libraries/blocks/blocks-mc15w36a-mc17w46a/gradle.properties b/libraries/blocks/blocks-mc15w36a-mc17w46a/gradle.properties
new file mode 100644
index 000000000..a313c7528
--- /dev/null
+++ b/libraries/blocks/blocks-mc15w36a-mc17w46a/gradle.properties
@@ -0,0 +1,7 @@
+min_mc_version = 15w36a
+max_mc_version = 17w46a
+minecraft_dependency = >=1.9-alpha.15.36.a <=1.13-alpha.17.46.a
+
+minecraft_version = 1.12.2
+raven_build = 1
+sparrow_build = 1
diff --git a/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/api/BlockEvents.java b/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/api/BlockEvents.java
new file mode 100644
index 000000000..9a76f18be
--- /dev/null
+++ b/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/api/BlockEvents.java
@@ -0,0 +1,34 @@
+package net.ornithemc.osl.blocks.api;
+
+import net.ornithemc.osl.core.api.events.Event;
+
+/**
+ * Events related to the blocks lifecycle.
+ */
+public final class BlockEvents {
+
+ /**
+ * This event is invoked upon game start-up, after Vanilla block registration is finished.
+ *
+ *
+ * Custom block registration should be done in a listener of this event.
+ * Helper methods for registering blocks can be found in the {@linkplain
+ * BlockRegistry} class.
+ *
+ *
+ * Listeners to this event should be registered in your mod's entrypoint,
+ * and can be done as follows:
+ *
+ *
+ * {@code
+ * BlockEvents.REGISTER_BLOCKS.register(() -> {
+ * BlockRegistry.register(NamespacedIdentifiers.from("example", "cookie"), new CookieBlock());
+ * });
+ * }
+ *
+ *
+ * @see BlockRegistry
+ */
+ public static final Event REGISTER_BLOCKS = Event.runnable();
+
+}
diff --git a/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/api/BlockRegistry.java b/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/api/BlockRegistry.java
new file mode 100644
index 000000000..ae6522ef9
--- /dev/null
+++ b/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/api/BlockRegistry.java
@@ -0,0 +1,109 @@
+package net.ornithemc.osl.blocks.api;
+
+import java.util.Set;
+
+import net.minecraft.block.Block;
+
+import net.ornithemc.osl.blocks.impl.BlockRegistryImpl;
+import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.registries.api.registry.DefaultedRegistry;
+import net.ornithemc.osl.registries.api.registry.ResourceKey;
+
+/**
+ * Public access to the Blocks registry.
+ */
+public final class BlockRegistry {
+
+ public static final DefaultedRegistry REGISTRY = BlockRegistryImpl.REGISTRY;
+
+ /**
+ * @return the numerical ID assigned to the given block.
+ */
+ public static int getId(Block block) {
+ return BlockRegistryImpl.getId(block);
+ }
+
+ /**
+ * @return the namespaced ID assigned to the given block.
+ */
+ public static NamespacedIdentifier getIdentifier(Block block) {
+ return BlockRegistryImpl.getIdentifier(block);
+ }
+
+ /**
+ * @return the resource key assigned to the given block.
+ */
+ public static ResourceKey getKey(Block block) {
+ return BlockRegistryImpl.getKey(block);
+ }
+
+ /**
+ * @return the block mapped to the given numerical ID.
+ */
+ public static Block getBlock(int id) {
+ return BlockRegistryImpl.getBlock(id);
+ }
+
+ /**
+ * @return the block mapped to the given namespaced ID.
+ */
+ public static Block getBlock(NamespacedIdentifier identifier) {
+ return BlockRegistryImpl.getBlock(identifier);
+ }
+
+ /**
+ * @return the block mapped to the given resource key.
+ */
+ public static Block getBlock(ResourceKey key) {
+ return BlockRegistryImpl.getBlock(key);
+ }
+
+ /**
+ * @return a set containing all namespaced IDs in the registry.
+ */
+ public static Set identifierSet() {
+ return BlockRegistryImpl.identifierSet();
+ }
+
+ /**
+ * @return a set containing all resource keys in the registry.
+ */
+ public static Set> keySet() {
+ return BlockRegistryImpl.keySet();
+ }
+
+ /**
+ * @param the block type.
+ * @param identifier the namespaced ID of the block.
+ * @param block the block to register.
+ * @return the registered block.
+ */
+ public static T register(NamespacedIdentifier identifier, T block) {
+ return BlockRegistryImpl.register(identifier, block);
+ }
+
+ /**
+ * @param the block type.
+ * @param key the resource key of the block.
+ * @param block the block to register.
+ * @return the registered block.
+ */
+ public static T register(ResourceKey key, T block) {
+ return BlockRegistryImpl.register(key, block);
+ }
+
+ /**
+ * @param the block type.
+ * @param id the numerical ID of the block.
+ * @param key the namespaced ID of the block.
+ * @param block the block to register.
+ * @return the registered block.
+ *
+ * @deprecated use {@linkplain #register(NamespacedIdentifier, Block)}
+ * or {@linkplain #register(ResourceKey, Block)} instead.
+ */
+ @Deprecated
+ public static T register(int id, NamespacedIdentifier key, T block) {
+ return BlockRegistryImpl.register(id, key, block);
+ }
+}
diff --git a/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/api/block/BlockExtension.java b/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/api/block/BlockExtension.java
new file mode 100644
index 000000000..d3cc82edc
--- /dev/null
+++ b/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/api/block/BlockExtension.java
@@ -0,0 +1,10 @@
+package net.ornithemc.osl.blocks.api.block;
+
+public interface BlockExtension {
+
+ /**
+ * @return whether this block is air.
+ */
+ boolean isAir();
+
+}
diff --git a/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/BlockRegistryImpl.java b/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/BlockRegistryImpl.java
new file mode 100644
index 000000000..3707a727b
--- /dev/null
+++ b/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/BlockRegistryImpl.java
@@ -0,0 +1,93 @@
+package net.ornithemc.osl.blocks.impl;
+
+import java.util.Set;
+
+import net.minecraft.block.Block;
+
+import net.ornithemc.osl.blocks.api.BlockEvents;
+import net.ornithemc.osl.blocks.impl.block.BlockStateRegistryFixer;
+import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
+import net.ornithemc.osl.registries.api.registry.DefaultedRegistry;
+import net.ornithemc.osl.registries.api.registry.Registry;
+import net.ornithemc.osl.registries.api.registry.RegistryKeys;
+import net.ornithemc.osl.registries.api.registry.ResourceKey;
+import net.ornithemc.osl.registries.api.registry.SyncedRegistries;
+import net.ornithemc.osl.registries.impl.registry.VanillaRegistries;
+
+public final class BlockRegistryImpl {
+
+ public static final DefaultedRegistry REGISTRY = VanillaRegistries.registerDefaulted(RegistryKeys.BLOCK, Block.REGISTRY);
+
+ private static boolean locked = true;
+
+ public static int getId(Block block) {
+ return REGISTRY.getId(block);
+ }
+
+ public static NamespacedIdentifier getIdentifier(Block block) {
+ return REGISTRY.getIdentifier(block);
+ }
+
+ public static ResourceKey getKey(Block block) {
+ return REGISTRY.getKey(block);
+ }
+
+ public static Block getBlock(int id) {
+ return REGISTRY.get(id);
+ }
+
+ public static Block getBlock(NamespacedIdentifier identifier) {
+ return REGISTRY.get(identifier);
+ }
+
+ public static Block getBlock(ResourceKey key) {
+ return REGISTRY.get(key);
+ }
+
+ public static Set identifierSet() {
+ return REGISTRY.identifierSet();
+ }
+
+ public static Set> keySet() {
+ return REGISTRY.keySet();
+ }
+
+ public static T register(NamespacedIdentifier identifier, T block) {
+ if (locked) {
+ throw new IllegalStateException("register called too early: registry locked!");
+ } else {
+ return Registry.register(REGISTRY, identifier, block);
+ }
+ }
+
+ public static T register(ResourceKey key, T block) {
+ if (locked) {
+ throw new IllegalStateException("register called too early: registry locked!");
+ } else {
+ return Registry.register(REGISTRY, key, block);
+ }
+ }
+
+ @Deprecated
+ public static T register(int id, NamespacedIdentifier key, T block) {
+ if (locked) {
+ throw new IllegalStateException("register called too early: registry locked!");
+ } else {
+ return Registry.register(REGISTRY, id, key, block);
+ }
+ }
+
+ public static void init() {
+ SyncedRegistries.register(RegistryKeys.BLOCK);
+ SyncedRegistries.registerFixer(RegistryKeys.BLOCK, NamespacedIdentifiers.from("blockstate"), new BlockStateRegistryFixer());
+ }
+
+ public static void unlock() {
+ locked = false;
+ }
+
+ public static void registerBlocks() {
+ BlockEvents.REGISTER_BLOCKS.invoker().run();
+ }
+}
diff --git a/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/BlocksMixinPlugin.java b/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/BlocksMixinPlugin.java
new file mode 100644
index 000000000..4a1d09228
--- /dev/null
+++ b/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/BlocksMixinPlugin.java
@@ -0,0 +1,49 @@
+package net.ornithemc.osl.blocks.impl;
+
+import java.util.List;
+import java.util.Set;
+
+import org.objectweb.asm.tree.ClassNode;
+
+import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
+import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
+
+import net.ornithemc.osl.core.impl.util.MinecraftVersion;
+
+public class BlocksMixinPlugin implements IMixinConfigPlugin {
+
+ @Override
+ public void onLoad(String mixinPackage) {
+ }
+
+ @Override
+ public String getRefMapperConfig() {
+ return null;
+ }
+
+ @Override
+ public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
+ if ("net.ornithemc.osl.blocks.impl.mixin.client.BlockColorsMixin".equals(mixinClassName)) {
+ return MinecraftVersion.resolve().compareTo("16w02a") >= 0;
+ }
+
+ return true;
+ }
+
+ @Override
+ public void acceptTargets(Set myTargets, Set otherTargets) {
+ }
+
+ @Override
+ public List getMixins() {
+ return null;
+ }
+
+ @Override
+ public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
+ }
+
+ @Override
+ public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
+ }
+}
diff --git a/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockExtensionImpl.java b/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockExtensionImpl.java
new file mode 100644
index 000000000..5f35a77d9
--- /dev/null
+++ b/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockExtensionImpl.java
@@ -0,0 +1,11 @@
+package net.ornithemc.osl.blocks.impl.block;
+
+import net.ornithemc.osl.blocks.api.block.BlockExtension;
+
+public interface BlockExtensionImpl extends BlockExtension {
+
+ @Override
+ default boolean isAir() {
+ throw new AbstractMethodError();
+ }
+}
diff --git a/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockStateRegistryFixer.java b/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockStateRegistryFixer.java
new file mode 100644
index 000000000..9f42817d0
--- /dev/null
+++ b/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockStateRegistryFixer.java
@@ -0,0 +1,26 @@
+package net.ornithemc.osl.blocks.impl.block;
+
+import net.minecraft.block.Block;
+import net.minecraft.block.state.BlockState;
+import net.ornithemc.osl.blocks.api.BlockRegistry;
+import net.ornithemc.osl.registries.api.registry.sync.IdFixer;
+import net.ornithemc.osl.registries.impl.access.Clearable;
+
+public class BlockStateRegistryFixer implements IdFixer {
+
+ @Override
+ public void apply() {
+ Clearable.clear(Block.STATE_REGISTRY);
+
+ for (Block block : BlockRegistry.REGISTRY) {
+ int blockId = BlockRegistry.getId(block);
+
+ for (BlockState state : block.stateDefinition().all()) {
+ int metadata = block.getMetadataFromState(state);
+ int stateId = blockId << 4 | metadata;
+
+ Block.STATE_REGISTRY.put(state, stateId);
+ }
+ }
+ }
+}
diff --git a/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/mixin/client/BlockColorsMixin.java b/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/mixin/client/BlockColorsMixin.java
new file mode 100644
index 000000000..4cb0a6c32
--- /dev/null
+++ b/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/mixin/client/BlockColorsMixin.java
@@ -0,0 +1,34 @@
+package net.ornithemc.osl.blocks.impl.mixin.client;
+
+import org.spongepowered.asm.mixin.Final;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import net.minecraft.client.world.color.BlockColor;
+import net.minecraft.client.world.color.BlockColors;
+import net.minecraft.util.Id2ObjectBiMap;
+
+import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
+import net.ornithemc.osl.registries.api.registry.RegistryKeys;
+import net.ornithemc.osl.registries.api.registry.SyncedRegistries;
+import net.ornithemc.osl.registries.api.registry.sync.Id2ObjectBiMapMapper;
+
+@Mixin(BlockColors.class)
+public class BlockColorsMixin {
+
+ @Shadow @Final
+ private Id2ObjectBiMap registry;
+
+ @Inject(
+ method = "",
+ at = @At(
+ value = "TAIL"
+ )
+ )
+ private void osl$items$registerModelRegistryMapper(CallbackInfo ci) {
+ SyncedRegistries.registerMapper(RegistryKeys.BLOCK, NamespacedIdentifiers.from("block_color"), Id2ObjectBiMapMapper.of(this.registry));
+ }
+}
diff --git a/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/AirBlockMixin.java b/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/AirBlockMixin.java
new file mode 100644
index 000000000..0fd9972c5
--- /dev/null
+++ b/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/AirBlockMixin.java
@@ -0,0 +1,16 @@
+package net.ornithemc.osl.blocks.impl.mixin.common;
+
+import org.spongepowered.asm.mixin.Mixin;
+
+import net.minecraft.block.AirBlock;
+
+import net.ornithemc.osl.blocks.api.block.BlockExtension;
+
+@Mixin(AirBlock.class)
+public class AirBlockMixin implements BlockExtension {
+
+ @Override
+ public boolean isAir() {
+ return true;
+ }
+}
diff --git a/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin.java b/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin.java
new file mode 100644
index 000000000..95961cce2
--- /dev/null
+++ b/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin.java
@@ -0,0 +1,67 @@
+package net.ornithemc.osl.blocks.impl.mixin.common;
+
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
+
+import net.minecraft.block.Block;
+
+import net.ornithemc.osl.blocks.api.BlockRegistry;
+import net.ornithemc.osl.blocks.api.block.BlockExtension;
+import net.ornithemc.osl.blocks.impl.BlockRegistryImpl;
+import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.core.impl.util.Util;
+
+@Mixin(Block.class)
+public class BlockMixin implements BlockExtension {
+
+ @Shadow
+ private String key;
+
+ @Inject(
+ method = "init",
+ at = @At(
+ value = "HEAD"
+ )
+ )
+ private static void osl$blocks$unlockBlockRegistry(CallbackInfo ci) {
+ BlockRegistryImpl.unlock();
+ }
+
+ @Inject(
+ method = "init",
+ at = @At(
+ value = "INVOKE",
+ target = "Lnet/minecraft/util/registry/DefaultedIdRegistry;validate()V"
+ )
+ )
+ private static void osl$blocks$registerBlocks(CallbackInfo ci) {
+ BlockRegistryImpl.registerBlocks();
+ }
+
+ @Inject(
+ method = "getTranslationKey",
+ at = @At(
+ value = "HEAD"
+ )
+ )
+ private void osl$blocks$autoAssignTranslationKey(CallbackInfoReturnable cir) {
+ if (this.key == null) {
+ NamespacedIdentifier identifier = BlockRegistry.getIdentifier((Block) (Object) this);
+
+ if (identifier == null) {
+ this.key = "unknown";
+ } else {
+ this.key = Util.makeTranslationKey(identifier);
+ }
+ }
+ }
+
+ @Override
+ public boolean isAir() {
+ return false;
+ }
+}
diff --git a/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/StatsMixin.java b/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/StatsMixin.java
new file mode 100644
index 000000000..019e93566
--- /dev/null
+++ b/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/StatsMixin.java
@@ -0,0 +1,34 @@
+package net.ornithemc.osl.blocks.impl.mixin.common;
+
+import org.spongepowered.asm.mixin.Final;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import net.minecraft.stat.Stat;
+import net.minecraft.stat.Stats;
+
+import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
+import net.ornithemc.osl.registries.api.registry.RegistryKeys;
+import net.ornithemc.osl.registries.api.registry.SyncedRegistries;
+import net.ornithemc.osl.registries.api.registry.sync.ObjectArrayMapper;
+
+@Mixin(Stats.class)
+public class StatsMixin {
+
+ @Shadow @Final
+ private static Stat[] BLOCKS_MINED;
+
+ @Inject(
+ // inject at init instead of in case the arrays are resized...
+ method = "init",
+ at = @At(
+ value = "TAIL"
+ )
+ )
+ private static void osl$items$registerStatsMapper(CallbackInfo ci) {
+ SyncedRegistries.registerMapper(RegistryKeys.BLOCK, NamespacedIdentifiers.from("stats/mined"), ObjectArrayMapper.of(BLOCKS_MINED));
+ }
+}
diff --git a/libraries/blocks/blocks-mc14w27a-mc17w46a/src/main/resources/fabric.mod.json b/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/resources/fabric.mod.json
similarity index 50%
rename from libraries/blocks/blocks-mc14w27a-mc17w46a/src/main/resources/fabric.mod.json
rename to libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/resources/fabric.mod.json
index f5e589d41..77669c32f 100644
--- a/libraries/blocks/blocks-mc14w27a-mc17w46a/src/main/resources/fabric.mod.json
+++ b/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/resources/fabric.mod.json
@@ -1,16 +1,28 @@
{
"schemaVersion": 1,
"id": "osl-blocks",
- "version": "0.1.1+mc14w27a-mc17w46a",
+ "version": "0.1.1+mc15w36a-mc17w46a",
"environment": "*",
+ "entrypoints": {
+ "init": [
+ "net.ornithemc.osl.blocks.impl.BlockRegistryImpl::init"
+ ]
+ },
"mixins": [
"osl.blocks.mixins.json"
],
"accessWidener": "osl.blocks.classtweaker",
"depends": {
"fabricloader": "\u003e\u003d0.18.0",
- "minecraft": "\u003e\u003d1.8-alpha.14.27.a \u003c\u003d1.13-alpha.17.46.a",
- "osl-core": "\u003e\u003d0.9.0"
+ "minecraft": "\u003e\u003d1.9-alpha.15.36.a \u003c\u003d1.13-alpha.17.46.a",
+ "osl-core": "\u003e\u003d0.9.0",
+ "osl-entrypoints": "\u003e\u003d0.5.0",
+ "osl-lifecycle-events": "\u003e\u003d0.6.0",
+ "osl-executors": "\u003e\u003d0.1.0",
+ "osl-text-components": "\u003e\u003d0.1.0-",
+ "osl-networking": "\u003e\u003d0.9.0",
+ "osl-networking-impl": "\u003e\u003d0.1.0",
+ "osl-registries": "\u003e\u003d0.1.0-"
},
"name": "OSL Blocks",
"description": "Blocks API and events.",
diff --git a/libraries/blocks/blocks-mc14w27a-mc17w46a/src/main/resources/osl.blocks.classtweaker b/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/resources/osl.blocks.classtweaker
similarity index 100%
rename from libraries/blocks/blocks-mc14w27a-mc17w46a/src/main/resources/osl.blocks.classtweaker
rename to libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/resources/osl.blocks.classtweaker
diff --git a/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/resources/osl.blocks.mixins.json b/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/resources/osl.blocks.mixins.json
new file mode 100644
index 000000000..ff43e2f92
--- /dev/null
+++ b/libraries/blocks/blocks-mc15w36a-mc17w46a/src/main/resources/osl.blocks.mixins.json
@@ -0,0 +1,20 @@
+{
+ "required": true,
+ "minVersion": "0.8",
+ "package": "net.ornithemc.osl.blocks.impl.mixin",
+ "compatibilityLevel": "JAVA_8",
+ "plugin": "net.ornithemc.osl.blocks.impl.BlocksMixinPlugin",
+ "mixins": [
+ "common.AirBlockMixin",
+ "common.BlockMixin",
+ "common.StatsMixin"
+ ],
+ "client": [
+ "client.BlockColorsMixin"
+ ],
+ "server": [
+ ],
+ "injectors": {
+ "defaultRequire": 1
+ }
+}
diff --git a/libraries/blocks/blocks-mc17w47a-mc18w31a/src/main/java/net/ornithemc/osl/blocks/api/BlockRegistry.java b/libraries/blocks/blocks-mc17w47a-mc18w31a/src/main/java/net/ornithemc/osl/blocks/api/BlockRegistry.java
index 96500cd94..0f196b50e 100644
--- a/libraries/blocks/blocks-mc17w47a-mc18w31a/src/main/java/net/ornithemc/osl/blocks/api/BlockRegistry.java
+++ b/libraries/blocks/blocks-mc17w47a-mc18w31a/src/main/java/net/ornithemc/osl/blocks/api/BlockRegistry.java
@@ -6,12 +6,16 @@
import net.ornithemc.osl.blocks.impl.BlockRegistryImpl;
import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.registries.api.registry.DefaultedRegistry;
+import net.ornithemc.osl.registries.api.registry.ResourceKey;
/**
* Public access to the Blocks registry.
*/
public final class BlockRegistry {
+ public static final DefaultedRegistry REGISTRY = BlockRegistryImpl.REGISTRY;
+
/**
* @return the numerical ID assigned to the given block.
*/
@@ -22,7 +26,14 @@ public static int getId(Block block) {
/**
* @return the namespaced ID assigned to the given block.
*/
- public static NamespacedIdentifier getKey(Block block) {
+ public static NamespacedIdentifier getIdentifier(Block block) {
+ return BlockRegistryImpl.getIdentifier(block);
+ }
+
+ /**
+ * @return the resource key assigned to the given block.
+ */
+ public static ResourceKey getKey(Block block) {
return BlockRegistryImpl.getKey(block);
}
@@ -36,24 +47,48 @@ public static Block getBlock(int id) {
/**
* @return the block mapped to the given namespaced ID.
*/
- public static Block getBlock(NamespacedIdentifier key) {
+ public static Block getBlock(NamespacedIdentifier identifier) {
+ return BlockRegistryImpl.getBlock(identifier);
+ }
+
+ /**
+ * @return the block mapped to the given resource key.
+ */
+ public static Block getBlock(ResourceKey key) {
return BlockRegistryImpl.getBlock(key);
}
/**
* @return a set containing all namespaced IDs in the registry.
*/
- public static Set keySet() {
+ public static Set identifierSet() {
+ return BlockRegistryImpl.identifierSet();
+ }
+
+ /**
+ * @return a set containing all resource keys in the registry.
+ */
+ public static Set> keySet() {
return BlockRegistryImpl.keySet();
}
+ /**
+ * @param the block type.
+ * @param identifier the namespaced ID of the block.
+ * @param block the block to register.
+ * @return the registered block.
+ */
+ public static T register(NamespacedIdentifier identifier, T block) {
+ return BlockRegistryImpl.register(identifier, block);
+ }
+
/**
* @param the block type.
- * @param key the namespaced ID of the block.
+ * @param key the resource key of the block.
* @param block the block to register.
* @return the registered block.
*/
- public static T register(NamespacedIdentifier key, T block) {
+ public static T register(ResourceKey key, T block) {
return BlockRegistryImpl.register(key, block);
}
}
diff --git a/libraries/blocks/blocks-mc17w47a-mc18w31a/src/main/java/net/ornithemc/osl/blocks/impl/BlockRegistryImpl.java b/libraries/blocks/blocks-mc17w47a-mc18w31a/src/main/java/net/ornithemc/osl/blocks/impl/BlockRegistryImpl.java
index 3f168bd4e..f4466ec4b 100644
--- a/libraries/blocks/blocks-mc17w47a-mc18w31a/src/main/java/net/ornithemc/osl/blocks/impl/BlockRegistryImpl.java
+++ b/libraries/blocks/blocks-mc17w47a-mc18w31a/src/main/java/net/ornithemc/osl/blocks/impl/BlockRegistryImpl.java
@@ -1,75 +1,84 @@
package net.ornithemc.osl.blocks.impl;
-import java.util.Collections;
import java.util.Set;
import net.minecraft.block.Block;
-import net.minecraft.resource.Identifier;
import net.ornithemc.osl.blocks.api.BlockEvents;
+import net.ornithemc.osl.blocks.impl.block.BlockStateRegistryFixer;
import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
+import net.ornithemc.osl.registries.api.registry.DefaultedRegistry;
+import net.ornithemc.osl.registries.api.registry.Registry;
+import net.ornithemc.osl.registries.api.registry.RegistryKeys;
+import net.ornithemc.osl.registries.api.registry.ResourceKey;
+import net.ornithemc.osl.registries.api.registry.SyncedRegistries;
+import net.ornithemc.osl.registries.impl.registry.VanillaRegistries;
public final class BlockRegistryImpl {
+ public static final DefaultedRegistry REGISTRY = VanillaRegistries.registerDefaulted(RegistryKeys.BLOCK, Block.REGISTRY);
+
private static boolean locked = true;
- private static boolean initialized = false;
public static int getId(Block block) {
- return Block.REGISTRY.getId(block);
+ return REGISTRY.getId(block);
+ }
+
+ public static NamespacedIdentifier getIdentifier(Block block) {
+ return REGISTRY.getIdentifier(block);
}
- public static NamespacedIdentifier getKey(Block block) {
- return Block.REGISTRY.getKey(block);
+ public static ResourceKey getKey(Block block) {
+ return REGISTRY.getKey(block);
}
public static Block getBlock(int id) {
- return Block.REGISTRY.get(id);
+ return REGISTRY.get(id);
}
- public static Block getBlock(NamespacedIdentifier key) {
- return Block.REGISTRY.get(identifier(key));
+ public static Block getBlock(NamespacedIdentifier identifier) {
+ return REGISTRY.get(identifier);
}
- public static Set keySet() {
- return Collections.unmodifiableSet(Block.REGISTRY.entrySet());
+ public static Block getBlock(ResourceKey key) {
+ return REGISTRY.get(key);
}
- public static T register(NamespacedIdentifier key, T block) {
- if (locked) {
- throw new IllegalStateException("register called too " + (initialized ? "late" : "early") + ": registry locked!");
- } else {
- Block.REGISTRY.put(identifier(key), block);
- }
+ public static Set identifierSet() {
+ return REGISTRY.identifierSet();
+ }
- return block;
+ public static Set> keySet() {
+ return REGISTRY.keySet();
}
- private static Identifier identifier(NamespacedIdentifier id) {
- return id instanceof Identifier ? (Identifier) id : new Identifier(id.namespace(), id.identifier());
+ public static T register(NamespacedIdentifier identifier, T block) {
+ if (locked) {
+ throw new IllegalStateException("register called too early: registry locked!");
+ } else {
+ return Registry.register(REGISTRY, identifier, block);
+ }
}
- public static void lock() {
- if (!initialized) {
- throw new IllegalStateException("cannot lock block registry unless it's been initialized!");
+ public static T register(ResourceKey key, T block) {
+ if (locked) {
+ throw new IllegalStateException("register called too early: registry locked!");
+ } else {
+ return Registry.register(REGISTRY, key, block);
}
+ }
- locked = true;
+ public static void init() {
+ SyncedRegistries.register(RegistryKeys.BLOCK);
+ SyncedRegistries.registerFixer(RegistryKeys.BLOCK, NamespacedIdentifiers.from("blockstate"), new BlockStateRegistryFixer());
}
public static void unlock() {
- if (initialized) {
- throw new IllegalStateException("cannot unlock block registry once it's been initialized!");
- }
-
locked = false;
}
- public static void init() {
- if (locked) {
- throw new IllegalStateException("cannot initialize block registry when it's locked!");
- }
-
+ public static void registerBlocks() {
BlockEvents.REGISTER_BLOCKS.invoker().run();
- initialized = true;
}
}
diff --git a/libraries/blocks/blocks-mc17w47a-mc18w31a/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockStateRegistryFixer.java b/libraries/blocks/blocks-mc17w47a-mc18w31a/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockStateRegistryFixer.java
new file mode 100644
index 000000000..97a1f2372
--- /dev/null
+++ b/libraries/blocks/blocks-mc17w47a-mc18w31a/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockStateRegistryFixer.java
@@ -0,0 +1,22 @@
+package net.ornithemc.osl.blocks.impl.block;
+
+import net.minecraft.block.Block;
+import net.minecraft.block.state.BlockState;
+
+import net.ornithemc.osl.blocks.api.BlockRegistry;
+import net.ornithemc.osl.registries.api.registry.sync.IdFixer;
+import net.ornithemc.osl.registries.impl.access.Clearable;
+
+public class BlockStateRegistryFixer implements IdFixer {
+
+ @Override
+ public void apply() {
+ Clearable.clear(Block.STATE_REGISTRY);
+
+ for (Block block : BlockRegistry.REGISTRY) {
+ for (BlockState state : block.stateDefinition().all()) {
+ Block.STATE_REGISTRY.put(state);
+ }
+ }
+ }
+}
diff --git a/libraries/blocks/blocks-mc17w47a-mc18w31a/src/main/java/net/ornithemc/osl/blocks/impl/mixin/client/BlockColorsMixin.java b/libraries/blocks/blocks-mc17w47a-mc18w31a/src/main/java/net/ornithemc/osl/blocks/impl/mixin/client/BlockColorsMixin.java
new file mode 100644
index 000000000..4cb0a6c32
--- /dev/null
+++ b/libraries/blocks/blocks-mc17w47a-mc18w31a/src/main/java/net/ornithemc/osl/blocks/impl/mixin/client/BlockColorsMixin.java
@@ -0,0 +1,34 @@
+package net.ornithemc.osl.blocks.impl.mixin.client;
+
+import org.spongepowered.asm.mixin.Final;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import net.minecraft.client.world.color.BlockColor;
+import net.minecraft.client.world.color.BlockColors;
+import net.minecraft.util.Id2ObjectBiMap;
+
+import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
+import net.ornithemc.osl.registries.api.registry.RegistryKeys;
+import net.ornithemc.osl.registries.api.registry.SyncedRegistries;
+import net.ornithemc.osl.registries.api.registry.sync.Id2ObjectBiMapMapper;
+
+@Mixin(BlockColors.class)
+public class BlockColorsMixin {
+
+ @Shadow @Final
+ private Id2ObjectBiMap registry;
+
+ @Inject(
+ method = "",
+ at = @At(
+ value = "TAIL"
+ )
+ )
+ private void osl$items$registerModelRegistryMapper(CallbackInfo ci) {
+ SyncedRegistries.registerMapper(RegistryKeys.BLOCK, NamespacedIdentifiers.from("block_color"), Id2ObjectBiMapMapper.of(this.registry));
+ }
+}
diff --git a/libraries/blocks/blocks-mc17w47a-mc18w31a/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin.java b/libraries/blocks/blocks-mc17w47a-mc18w31a/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin.java
index 17924f839..c873c42c5 100644
--- a/libraries/blocks/blocks-mc17w47a-mc18w31a/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin.java
+++ b/libraries/blocks/blocks-mc17w47a-mc18w31a/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin.java
@@ -38,8 +38,7 @@ public class BlockMixin {
shift = Shift.AFTER
)
)
- private static void osl$blocks$initAndLockBlockRegistry(CallbackInfo ci) {
- BlockRegistryImpl.init();
- BlockRegistryImpl.lock();
+ private static void osl$blocks$registerBlocks(CallbackInfo ci) {
+ BlockRegistryImpl.registerBlocks();
}
}
diff --git a/libraries/blocks/blocks-mc17w47a-mc18w31a/src/main/resources/fabric.mod.json b/libraries/blocks/blocks-mc17w47a-mc18w31a/src/main/resources/fabric.mod.json
index d20c30df3..d9c99a844 100644
--- a/libraries/blocks/blocks-mc17w47a-mc18w31a/src/main/resources/fabric.mod.json
+++ b/libraries/blocks/blocks-mc17w47a-mc18w31a/src/main/resources/fabric.mod.json
@@ -3,13 +3,25 @@
"id": "osl-blocks",
"version": "0.1.1+mc17w47a-mc18w31a",
"environment": "*",
+ "entrypoints": {
+ "init": [
+ "net.ornithemc.osl.blocks.impl.BlockRegistryImpl::init"
+ ]
+ },
"mixins": [
"osl.blocks.mixins.json"
],
"depends": {
"fabricloader": "\u003e\u003d0.18.0",
"minecraft": "\u003e\u003d1.13-alpha.17.47.a \u003c\u003d1.13.1-alpha.18.31.a",
- "osl-core": "\u003e\u003d0.9.0"
+ "osl-core": "\u003e\u003d0.9.0",
+ "osl-entrypoints": "\u003e\u003d0.5.0",
+ "osl-lifecycle-events": "\u003e\u003d0.6.0",
+ "osl-executors": "\u003e\u003d0.1.0",
+ "osl-text-components": "\u003e\u003d0.1.0-",
+ "osl-networking": "\u003e\u003d0.9.0",
+ "osl-networking-impl": "\u003e\u003d0.1.0",
+ "osl-registries": "\u003e\u003d0.1.0-"
},
"name": "OSL Blocks",
"description": "Blocks API and events.",
diff --git a/libraries/blocks/blocks-mc17w47a-mc18w31a/src/main/resources/osl.blocks.mixins.json b/libraries/blocks/blocks-mc17w47a-mc18w31a/src/main/resources/osl.blocks.mixins.json
index bfd6b26fa..afa7739ac 100644
--- a/libraries/blocks/blocks-mc17w47a-mc18w31a/src/main/resources/osl.blocks.mixins.json
+++ b/libraries/blocks/blocks-mc17w47a-mc18w31a/src/main/resources/osl.blocks.mixins.json
@@ -7,6 +7,7 @@
"common.BlockMixin"
],
"client": [
+ "client.BlockColorsMixin"
],
"server": [
],
diff --git a/libraries/blocks/blocks-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/blocks/api/BlockRegistry.java b/libraries/blocks/blocks-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/blocks/api/BlockRegistry.java
index 96500cd94..0f196b50e 100644
--- a/libraries/blocks/blocks-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/blocks/api/BlockRegistry.java
+++ b/libraries/blocks/blocks-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/blocks/api/BlockRegistry.java
@@ -6,12 +6,16 @@
import net.ornithemc.osl.blocks.impl.BlockRegistryImpl;
import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.registries.api.registry.DefaultedRegistry;
+import net.ornithemc.osl.registries.api.registry.ResourceKey;
/**
* Public access to the Blocks registry.
*/
public final class BlockRegistry {
+ public static final DefaultedRegistry REGISTRY = BlockRegistryImpl.REGISTRY;
+
/**
* @return the numerical ID assigned to the given block.
*/
@@ -22,7 +26,14 @@ public static int getId(Block block) {
/**
* @return the namespaced ID assigned to the given block.
*/
- public static NamespacedIdentifier getKey(Block block) {
+ public static NamespacedIdentifier getIdentifier(Block block) {
+ return BlockRegistryImpl.getIdentifier(block);
+ }
+
+ /**
+ * @return the resource key assigned to the given block.
+ */
+ public static ResourceKey getKey(Block block) {
return BlockRegistryImpl.getKey(block);
}
@@ -36,24 +47,48 @@ public static Block getBlock(int id) {
/**
* @return the block mapped to the given namespaced ID.
*/
- public static Block getBlock(NamespacedIdentifier key) {
+ public static Block getBlock(NamespacedIdentifier identifier) {
+ return BlockRegistryImpl.getBlock(identifier);
+ }
+
+ /**
+ * @return the block mapped to the given resource key.
+ */
+ public static Block getBlock(ResourceKey key) {
return BlockRegistryImpl.getBlock(key);
}
/**
* @return a set containing all namespaced IDs in the registry.
*/
- public static Set keySet() {
+ public static Set identifierSet() {
+ return BlockRegistryImpl.identifierSet();
+ }
+
+ /**
+ * @return a set containing all resource keys in the registry.
+ */
+ public static Set> keySet() {
return BlockRegistryImpl.keySet();
}
+ /**
+ * @param the block type.
+ * @param identifier the namespaced ID of the block.
+ * @param block the block to register.
+ * @return the registered block.
+ */
+ public static T register(NamespacedIdentifier identifier, T block) {
+ return BlockRegistryImpl.register(identifier, block);
+ }
+
/**
* @param the block type.
- * @param key the namespaced ID of the block.
+ * @param key the resource key of the block.
* @param block the block to register.
* @return the registered block.
*/
- public static T register(NamespacedIdentifier key, T block) {
+ public static T register(ResourceKey key, T block) {
return BlockRegistryImpl.register(key, block);
}
}
diff --git a/libraries/blocks/blocks-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/blocks/impl/BlockRegistryImpl.java b/libraries/blocks/blocks-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/blocks/impl/BlockRegistryImpl.java
index 374e98f77..82b8d9436 100644
--- a/libraries/blocks/blocks-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/blocks/impl/BlockRegistryImpl.java
+++ b/libraries/blocks/blocks-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/blocks/impl/BlockRegistryImpl.java
@@ -1,76 +1,84 @@
package net.ornithemc.osl.blocks.impl;
-import java.util.Collections;
import java.util.Set;
import net.minecraft.block.Block;
-import net.minecraft.resource.Identifier;
-import net.minecraft.util.registry.Registry;
import net.ornithemc.osl.blocks.api.BlockEvents;
+import net.ornithemc.osl.blocks.impl.block.BlockStateRegistryFixer;
import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
+import net.ornithemc.osl.registries.api.registry.DefaultedRegistry;
+import net.ornithemc.osl.registries.api.registry.Registry;
+import net.ornithemc.osl.registries.api.registry.RegistryKeys;
+import net.ornithemc.osl.registries.api.registry.ResourceKey;
+import net.ornithemc.osl.registries.api.registry.SyncedRegistries;
+import net.ornithemc.osl.registries.impl.registry.VanillaRegistries;
public final class BlockRegistryImpl {
+ public static final DefaultedRegistry REGISTRY = VanillaRegistries.registerDefaulted(RegistryKeys.BLOCK, net.minecraft.util.registry.Registry.BLOCK);
+
private static boolean locked = true;
- private static boolean initialized = false;
public static int getId(Block block) {
- return Registry.BLOCK.getId(block);
+ return REGISTRY.getId(block);
+ }
+
+ public static NamespacedIdentifier getIdentifier(Block block) {
+ return REGISTRY.getIdentifier(block);
}
- public static NamespacedIdentifier getKey(Block block) {
- return Registry.BLOCK.getKey(block);
+ public static ResourceKey getKey(Block block) {
+ return REGISTRY.getKey(block);
}
public static Block getBlock(int id) {
- return Registry.BLOCK.get(id);
+ return REGISTRY.get(id);
}
- public static Block getBlock(NamespacedIdentifier key) {
- return Registry.BLOCK.get(identifier(key));
+ public static Block getBlock(NamespacedIdentifier identifier) {
+ return REGISTRY.get(identifier);
}
- public static Set keySet() {
- return Collections.unmodifiableSet(Registry.BLOCK.keySet());
+ public static Block getBlock(ResourceKey key) {
+ return REGISTRY.get(key);
}
- public static T register(NamespacedIdentifier key, T block) {
- if (locked) {
- throw new IllegalStateException("register called too " + (initialized ? "late" : "early") + ": registry locked!");
- } else {
- Registry.BLOCK.register(identifier(key), block);
- }
+ public static Set identifierSet() {
+ return REGISTRY.identifierSet();
+ }
- return block;
+ public static Set> keySet() {
+ return REGISTRY.keySet();
}
- private static Identifier identifier(NamespacedIdentifier id) {
- return id instanceof Identifier ? (Identifier) id : new Identifier(id.namespace(), id.identifier());
+ public static T register(NamespacedIdentifier identifier, T block) {
+ if (locked) {
+ throw new IllegalStateException("register called too early: registry locked!");
+ } else {
+ return Registry.register(REGISTRY, identifier, block);
+ }
}
- public static void lock() {
- if (!initialized) {
- throw new IllegalStateException("cannot lock block registry unless it's been initialized!");
+ public static T register(ResourceKey key, T block) {
+ if (locked) {
+ throw new IllegalStateException("register called too early: registry locked!");
+ } else {
+ return Registry.register(REGISTRY, key, block);
}
+ }
- locked = true;
+ public static void init() {
+ SyncedRegistries.register(RegistryKeys.BLOCK);
+ SyncedRegistries.registerFixer(RegistryKeys.BLOCK, NamespacedIdentifiers.from("blockstate"), new BlockStateRegistryFixer());
}
public static void unlock() {
- if (initialized) {
- throw new IllegalStateException("cannot unlock block registry once it's been initialized!");
- }
-
locked = false;
}
- public static void init() {
- if (locked) {
- throw new IllegalStateException("cannot initialize block registry when it's locked!");
- }
-
+ public static void registerBlocks() {
BlockEvents.REGISTER_BLOCKS.invoker().run();
- initialized = true;
}
}
diff --git a/libraries/blocks/blocks-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockStateRegistryFixer.java b/libraries/blocks/blocks-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockStateRegistryFixer.java
new file mode 100644
index 000000000..97a1f2372
--- /dev/null
+++ b/libraries/blocks/blocks-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockStateRegistryFixer.java
@@ -0,0 +1,22 @@
+package net.ornithemc.osl.blocks.impl.block;
+
+import net.minecraft.block.Block;
+import net.minecraft.block.state.BlockState;
+
+import net.ornithemc.osl.blocks.api.BlockRegistry;
+import net.ornithemc.osl.registries.api.registry.sync.IdFixer;
+import net.ornithemc.osl.registries.impl.access.Clearable;
+
+public class BlockStateRegistryFixer implements IdFixer {
+
+ @Override
+ public void apply() {
+ Clearable.clear(Block.STATE_REGISTRY);
+
+ for (Block block : BlockRegistry.REGISTRY) {
+ for (BlockState state : block.stateDefinition().all()) {
+ Block.STATE_REGISTRY.put(state);
+ }
+ }
+ }
+}
diff --git a/libraries/blocks/blocks-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/blocks/impl/mixin/client/BlockColorsMixin.java b/libraries/blocks/blocks-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/blocks/impl/mixin/client/BlockColorsMixin.java
new file mode 100644
index 000000000..4cb0a6c32
--- /dev/null
+++ b/libraries/blocks/blocks-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/blocks/impl/mixin/client/BlockColorsMixin.java
@@ -0,0 +1,34 @@
+package net.ornithemc.osl.blocks.impl.mixin.client;
+
+import org.spongepowered.asm.mixin.Final;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import net.minecraft.client.world.color.BlockColor;
+import net.minecraft.client.world.color.BlockColors;
+import net.minecraft.util.Id2ObjectBiMap;
+
+import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
+import net.ornithemc.osl.registries.api.registry.RegistryKeys;
+import net.ornithemc.osl.registries.api.registry.SyncedRegistries;
+import net.ornithemc.osl.registries.api.registry.sync.Id2ObjectBiMapMapper;
+
+@Mixin(BlockColors.class)
+public class BlockColorsMixin {
+
+ @Shadow @Final
+ private Id2ObjectBiMap registry;
+
+ @Inject(
+ method = "",
+ at = @At(
+ value = "TAIL"
+ )
+ )
+ private void osl$items$registerModelRegistryMapper(CallbackInfo ci) {
+ SyncedRegistries.registerMapper(RegistryKeys.BLOCK, NamespacedIdentifiers.from("block_color"), Id2ObjectBiMapMapper.of(this.registry));
+ }
+}
diff --git a/libraries/blocks/blocks-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin.java b/libraries/blocks/blocks-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin.java
index 17924f839..c873c42c5 100644
--- a/libraries/blocks/blocks-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin.java
+++ b/libraries/blocks/blocks-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin.java
@@ -38,8 +38,7 @@ public class BlockMixin {
shift = Shift.AFTER
)
)
- private static void osl$blocks$initAndLockBlockRegistry(CallbackInfo ci) {
- BlockRegistryImpl.init();
- BlockRegistryImpl.lock();
+ private static void osl$blocks$registerBlocks(CallbackInfo ci) {
+ BlockRegistryImpl.registerBlocks();
}
}
diff --git a/libraries/blocks/blocks-mc18w32a-mc1.13.2/src/main/resources/fabric.mod.json b/libraries/blocks/blocks-mc18w32a-mc1.13.2/src/main/resources/fabric.mod.json
index 5ea18e8d0..1f0dd16be 100644
--- a/libraries/blocks/blocks-mc18w32a-mc1.13.2/src/main/resources/fabric.mod.json
+++ b/libraries/blocks/blocks-mc18w32a-mc1.13.2/src/main/resources/fabric.mod.json
@@ -3,13 +3,25 @@
"id": "osl-blocks",
"version": "0.1.1+mc18w32a-mc1.13.2",
"environment": "*",
+ "entrypoints": {
+ "init": [
+ "net.ornithemc.osl.blocks.impl.BlockRegistryImpl::init"
+ ]
+ },
"mixins": [
"osl.blocks.mixins.json"
],
"depends": {
"fabricloader": "\u003e\u003d0.18.0",
"minecraft": "\u003e\u003d1.13.1-alpha.18.32.a \u003c\u003d1.13.2",
- "osl-core": "\u003e\u003d0.9.0"
+ "osl-core": "\u003e\u003d0.9.0",
+ "osl-entrypoints": "\u003e\u003d0.5.0",
+ "osl-lifecycle-events": "\u003e\u003d0.6.0",
+ "osl-executors": "\u003e\u003d0.1.0",
+ "osl-text-components": "\u003e\u003d0.1.0-",
+ "osl-networking": "\u003e\u003d0.9.0",
+ "osl-networking-impl": "\u003e\u003d0.1.0",
+ "osl-registries": "\u003e\u003d0.1.0-"
},
"name": "OSL Blocks",
"description": "Blocks API and events.",
diff --git a/libraries/blocks/blocks-mc18w32a-mc1.13.2/src/main/resources/osl.blocks.mixins.json b/libraries/blocks/blocks-mc18w32a-mc1.13.2/src/main/resources/osl.blocks.mixins.json
index bfd6b26fa..afa7739ac 100644
--- a/libraries/blocks/blocks-mc18w32a-mc1.13.2/src/main/resources/osl.blocks.mixins.json
+++ b/libraries/blocks/blocks-mc18w32a-mc1.13.2/src/main/resources/osl.blocks.mixins.json
@@ -7,6 +7,7 @@
"common.BlockMixin"
],
"client": [
+ "client.BlockColorsMixin"
],
"server": [
],
diff --git a/libraries/blocks/blocks-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/blocks/api/BlockRegistry.java b/libraries/blocks/blocks-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/blocks/api/BlockRegistry.java
index 96500cd94..0f196b50e 100644
--- a/libraries/blocks/blocks-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/blocks/api/BlockRegistry.java
+++ b/libraries/blocks/blocks-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/blocks/api/BlockRegistry.java
@@ -6,12 +6,16 @@
import net.ornithemc.osl.blocks.impl.BlockRegistryImpl;
import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.registries.api.registry.DefaultedRegistry;
+import net.ornithemc.osl.registries.api.registry.ResourceKey;
/**
* Public access to the Blocks registry.
*/
public final class BlockRegistry {
+ public static final DefaultedRegistry REGISTRY = BlockRegistryImpl.REGISTRY;
+
/**
* @return the numerical ID assigned to the given block.
*/
@@ -22,7 +26,14 @@ public static int getId(Block block) {
/**
* @return the namespaced ID assigned to the given block.
*/
- public static NamespacedIdentifier getKey(Block block) {
+ public static NamespacedIdentifier getIdentifier(Block block) {
+ return BlockRegistryImpl.getIdentifier(block);
+ }
+
+ /**
+ * @return the resource key assigned to the given block.
+ */
+ public static ResourceKey getKey(Block block) {
return BlockRegistryImpl.getKey(block);
}
@@ -36,24 +47,48 @@ public static Block getBlock(int id) {
/**
* @return the block mapped to the given namespaced ID.
*/
- public static Block getBlock(NamespacedIdentifier key) {
+ public static Block getBlock(NamespacedIdentifier identifier) {
+ return BlockRegistryImpl.getBlock(identifier);
+ }
+
+ /**
+ * @return the block mapped to the given resource key.
+ */
+ public static Block getBlock(ResourceKey key) {
return BlockRegistryImpl.getBlock(key);
}
/**
* @return a set containing all namespaced IDs in the registry.
*/
- public static Set keySet() {
+ public static Set identifierSet() {
+ return BlockRegistryImpl.identifierSet();
+ }
+
+ /**
+ * @return a set containing all resource keys in the registry.
+ */
+ public static Set> keySet() {
return BlockRegistryImpl.keySet();
}
+ /**
+ * @param the block type.
+ * @param identifier the namespaced ID of the block.
+ * @param block the block to register.
+ * @return the registered block.
+ */
+ public static T register(NamespacedIdentifier identifier, T block) {
+ return BlockRegistryImpl.register(identifier, block);
+ }
+
/**
* @param the block type.
- * @param key the namespaced ID of the block.
+ * @param key the resource key of the block.
* @param block the block to register.
* @return the registered block.
*/
- public static T register(NamespacedIdentifier key, T block) {
+ public static T register(ResourceKey key, T block) {
return BlockRegistryImpl.register(key, block);
}
}
diff --git a/libraries/blocks/blocks-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/blocks/impl/BlockRegistryImpl.java b/libraries/blocks/blocks-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/blocks/impl/BlockRegistryImpl.java
index 790b4b721..82b8d9436 100644
--- a/libraries/blocks/blocks-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/blocks/impl/BlockRegistryImpl.java
+++ b/libraries/blocks/blocks-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/blocks/impl/BlockRegistryImpl.java
@@ -1,74 +1,84 @@
package net.ornithemc.osl.blocks.impl;
-import java.util.Collections;
import java.util.Set;
import net.minecraft.block.Block;
-import net.minecraft.resource.Identifier;
-import net.minecraft.util.registry.Registry;
import net.ornithemc.osl.blocks.api.BlockEvents;
+import net.ornithemc.osl.blocks.impl.block.BlockStateRegistryFixer;
import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
+import net.ornithemc.osl.registries.api.registry.DefaultedRegistry;
+import net.ornithemc.osl.registries.api.registry.Registry;
+import net.ornithemc.osl.registries.api.registry.RegistryKeys;
+import net.ornithemc.osl.registries.api.registry.ResourceKey;
+import net.ornithemc.osl.registries.api.registry.SyncedRegistries;
+import net.ornithemc.osl.registries.impl.registry.VanillaRegistries;
public final class BlockRegistryImpl {
+ public static final DefaultedRegistry REGISTRY = VanillaRegistries.registerDefaulted(RegistryKeys.BLOCK, net.minecraft.util.registry.Registry.BLOCK);
+
private static boolean locked = true;
- private static boolean initialized = false;
public static int getId(Block block) {
- return Registry.BLOCK.getId(block);
+ return REGISTRY.getId(block);
+ }
+
+ public static NamespacedIdentifier getIdentifier(Block block) {
+ return REGISTRY.getIdentifier(block);
}
- public static NamespacedIdentifier getKey(Block block) {
- return Registry.BLOCK.getKey(block);
+ public static ResourceKey getKey(Block block) {
+ return REGISTRY.getKey(block);
}
public static Block getBlock(int id) {
- return Registry.BLOCK.get(id);
+ return REGISTRY.get(id);
+ }
+
+ public static Block getBlock(NamespacedIdentifier identifier) {
+ return REGISTRY.get(identifier);
}
- public static Block getBlock(NamespacedIdentifier key) {
- return Registry.BLOCK.getOrDefault(identifier(key));
+ public static Block getBlock(ResourceKey key) {
+ return REGISTRY.get(key);
}
- public static Set keySet() {
- return Collections.unmodifiableSet(Registry.BLOCK.keySet());
+ public static Set identifierSet() {
+ return REGISTRY.identifierSet();
}
- public static T register(NamespacedIdentifier key, T block) {
+ public static Set> keySet() {
+ return REGISTRY.keySet();
+ }
+
+ public static T register(NamespacedIdentifier identifier, T block) {
if (locked) {
- throw new IllegalStateException("register called too " + (initialized ? "late" : "early") + ": registry locked!");
+ throw new IllegalStateException("register called too early: registry locked!");
} else {
- return Registry.BLOCK.m_30368144(identifier(key), block);
+ return Registry.register(REGISTRY, identifier, block);
}
}
- private static Identifier identifier(NamespacedIdentifier id) {
- return id instanceof Identifier ? (Identifier) id : new Identifier(id.namespace(), id.identifier());
- }
-
- public static void lock() {
- if (!initialized) {
- throw new IllegalStateException("cannot lock block registry unless it's been initialized!");
+ public static T register(ResourceKey key, T block) {
+ if (locked) {
+ throw new IllegalStateException("register called too early: registry locked!");
+ } else {
+ return Registry.register(REGISTRY, key, block);
}
+ }
- locked = true;
+ public static void init() {
+ SyncedRegistries.register(RegistryKeys.BLOCK);
+ SyncedRegistries.registerFixer(RegistryKeys.BLOCK, NamespacedIdentifiers.from("blockstate"), new BlockStateRegistryFixer());
}
public static void unlock() {
- if (initialized) {
- throw new IllegalStateException("cannot unlock block registry once it's been initialized!");
- }
-
locked = false;
}
- public static void init() {
- if (locked) {
- throw new IllegalStateException("cannot initialize block registry when it's locked!");
- }
-
+ public static void registerBlocks() {
BlockEvents.REGISTER_BLOCKS.invoker().run();
- initialized = true;
}
}
diff --git a/libraries/blocks/blocks-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockStateRegistryFixer.java b/libraries/blocks/blocks-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockStateRegistryFixer.java
new file mode 100644
index 000000000..97a1f2372
--- /dev/null
+++ b/libraries/blocks/blocks-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockStateRegistryFixer.java
@@ -0,0 +1,22 @@
+package net.ornithemc.osl.blocks.impl.block;
+
+import net.minecraft.block.Block;
+import net.minecraft.block.state.BlockState;
+
+import net.ornithemc.osl.blocks.api.BlockRegistry;
+import net.ornithemc.osl.registries.api.registry.sync.IdFixer;
+import net.ornithemc.osl.registries.impl.access.Clearable;
+
+public class BlockStateRegistryFixer implements IdFixer {
+
+ @Override
+ public void apply() {
+ Clearable.clear(Block.STATE_REGISTRY);
+
+ for (Block block : BlockRegistry.REGISTRY) {
+ for (BlockState state : block.stateDefinition().all()) {
+ Block.STATE_REGISTRY.put(state);
+ }
+ }
+ }
+}
diff --git a/libraries/blocks/blocks-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/client/BlockColorsMixin.java b/libraries/blocks/blocks-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/client/BlockColorsMixin.java
new file mode 100644
index 000000000..4cb0a6c32
--- /dev/null
+++ b/libraries/blocks/blocks-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/client/BlockColorsMixin.java
@@ -0,0 +1,34 @@
+package net.ornithemc.osl.blocks.impl.mixin.client;
+
+import org.spongepowered.asm.mixin.Final;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import net.minecraft.client.world.color.BlockColor;
+import net.minecraft.client.world.color.BlockColors;
+import net.minecraft.util.Id2ObjectBiMap;
+
+import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
+import net.ornithemc.osl.registries.api.registry.RegistryKeys;
+import net.ornithemc.osl.registries.api.registry.SyncedRegistries;
+import net.ornithemc.osl.registries.api.registry.sync.Id2ObjectBiMapMapper;
+
+@Mixin(BlockColors.class)
+public class BlockColorsMixin {
+
+ @Shadow @Final
+ private Id2ObjectBiMap registry;
+
+ @Inject(
+ method = "",
+ at = @At(
+ value = "TAIL"
+ )
+ )
+ private void osl$items$registerModelRegistryMapper(CallbackInfo ci) {
+ SyncedRegistries.registerMapper(RegistryKeys.BLOCK, NamespacedIdentifiers.from("block_color"), Id2ObjectBiMapMapper.of(this.registry));
+ }
+}
diff --git a/libraries/blocks/blocks-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlocksMixin.java b/libraries/blocks/blocks-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlocksMixin.java
index 27b3d23c0..608abdb99 100644
--- a/libraries/blocks/blocks-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlocksMixin.java
+++ b/libraries/blocks/blocks-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlocksMixin.java
@@ -29,8 +29,7 @@ public class BlocksMixin {
target = "Lnet/minecraft/util/registry/Registry;BLOCK:Lnet/minecraft/util/registry/DefaultedIdRegistry;"
)
)
- private static void osl$blocks$initAndLockBlockRegistry(CallbackInfo ci) {
- BlockRegistryImpl.init();
- BlockRegistryImpl.lock();
+ private static void osl$blocks$registerBlocks(CallbackInfo ci) {
+ BlockRegistryImpl.registerBlocks();
}
}
diff --git a/libraries/blocks/blocks-mc18w43a-mc1.14.4/src/main/resources/fabric.mod.json b/libraries/blocks/blocks-mc18w43a-mc1.14.4/src/main/resources/fabric.mod.json
index 110b40cd9..7dbbc4da5 100644
--- a/libraries/blocks/blocks-mc18w43a-mc1.14.4/src/main/resources/fabric.mod.json
+++ b/libraries/blocks/blocks-mc18w43a-mc1.14.4/src/main/resources/fabric.mod.json
@@ -3,13 +3,25 @@
"id": "osl-blocks",
"version": "0.1.1+mc18w43a-mc1.14.4",
"environment": "*",
+ "entrypoints": {
+ "init": [
+ "net.ornithemc.osl.blocks.impl.BlockRegistryImpl::init"
+ ]
+ },
"mixins": [
"osl.blocks.mixins.json"
],
"depends": {
"fabricloader": "\u003e\u003d0.18.0",
"minecraft": "\u003e\u003d1.14-alpha.18.43.a \u003c\u003d1.14.4",
- "osl-core": "\u003e\u003d0.9.0"
+ "osl-core": "\u003e\u003d0.9.0",
+ "osl-entrypoints": "\u003e\u003d0.5.0",
+ "osl-lifecycle-events": "\u003e\u003d0.6.0",
+ "osl-executors": "\u003e\u003d0.1.0",
+ "osl-text-components": "\u003e\u003d0.1.0-",
+ "osl-networking": "\u003e\u003d0.9.0",
+ "osl-networking-impl": "\u003e\u003d0.1.0",
+ "osl-registries": "\u003e\u003d0.1.0-"
},
"name": "OSL Blocks",
"description": "Blocks API and events.",
diff --git a/libraries/blocks/blocks-mc18w43a-mc1.14.4/src/main/resources/osl.blocks.mixins.json b/libraries/blocks/blocks-mc18w43a-mc1.14.4/src/main/resources/osl.blocks.mixins.json
index c958d77d3..9ab75017c 100644
--- a/libraries/blocks/blocks-mc18w43a-mc1.14.4/src/main/resources/osl.blocks.mixins.json
+++ b/libraries/blocks/blocks-mc18w43a-mc1.14.4/src/main/resources/osl.blocks.mixins.json
@@ -7,6 +7,7 @@
"common.BlocksMixin"
],
"client": [
+ "client.BlockColorsMixin"
],
"server": [
],
diff --git a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/api/BlockRegistry.java b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/api/BlockRegistry.java
index 003e6ec54..ae6522ef9 100644
--- a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/api/BlockRegistry.java
+++ b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/api/BlockRegistry.java
@@ -6,12 +6,16 @@
import net.ornithemc.osl.blocks.impl.BlockRegistryImpl;
import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.registries.api.registry.DefaultedRegistry;
+import net.ornithemc.osl.registries.api.registry.ResourceKey;
/**
* Public access to the Blocks registry.
*/
public final class BlockRegistry {
+ public static final DefaultedRegistry REGISTRY = BlockRegistryImpl.REGISTRY;
+
/**
* @return the numerical ID assigned to the given block.
*/
@@ -22,7 +26,14 @@ public static int getId(Block block) {
/**
* @return the namespaced ID assigned to the given block.
*/
- public static NamespacedIdentifier getKey(Block block) {
+ public static NamespacedIdentifier getIdentifier(Block block) {
+ return BlockRegistryImpl.getIdentifier(block);
+ }
+
+ /**
+ * @return the resource key assigned to the given block.
+ */
+ public static ResourceKey getKey(Block block) {
return BlockRegistryImpl.getKey(block);
}
@@ -36,24 +47,62 @@ public static Block getBlock(int id) {
/**
* @return the block mapped to the given namespaced ID.
*/
- public static Block getBlock(NamespacedIdentifier key) {
+ public static Block getBlock(NamespacedIdentifier identifier) {
+ return BlockRegistryImpl.getBlock(identifier);
+ }
+
+ /**
+ * @return the block mapped to the given resource key.
+ */
+ public static Block getBlock(ResourceKey key) {
return BlockRegistryImpl.getBlock(key);
}
/**
* @return a set containing all namespaced IDs in the registry.
*/
- public static Set keySet() {
+ public static Set identifierSet() {
+ return BlockRegistryImpl.identifierSet();
+ }
+
+ /**
+ * @return a set containing all resource keys in the registry.
+ */
+ public static Set> keySet() {
return BlockRegistryImpl.keySet();
}
+ /**
+ * @param the block type.
+ * @param identifier the namespaced ID of the block.
+ * @param block the block to register.
+ * @return the registered block.
+ */
+ public static T register(NamespacedIdentifier identifier, T block) {
+ return BlockRegistryImpl.register(identifier, block);
+ }
+
+ /**
+ * @param the block type.
+ * @param key the resource key of the block.
+ * @param block the block to register.
+ * @return the registered block.
+ */
+ public static T register(ResourceKey key, T block) {
+ return BlockRegistryImpl.register(key, block);
+ }
+
/**
* @param the block type.
* @param id the numerical ID of the block.
* @param key the namespaced ID of the block.
* @param block the block to register.
* @return the registered block.
+ *
+ * @deprecated use {@linkplain #register(NamespacedIdentifier, Block)}
+ * or {@linkplain #register(ResourceKey, Block)} instead.
*/
+ @Deprecated
public static T register(int id, NamespacedIdentifier key, T block) {
return BlockRegistryImpl.register(id, key, block);
}
diff --git a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/api/block/BlockExtension.java b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/api/block/BlockExtension.java
index 152e77faa..8d70e623b 100644
--- a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/api/block/BlockExtension.java
+++ b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/api/block/BlockExtension.java
@@ -2,12 +2,13 @@
import net.minecraft.block.Block;
-import net.ornithemc.osl.core.api.registry.DefaultedIdRegistry;
-import net.ornithemc.osl.core.api.registry.SimpleIdRegistry;
+import net.ornithemc.osl.blocks.impl.BlockRegistryImpl;
+import net.ornithemc.osl.registries.api.registry.DefaultedRegistry;
public interface BlockExtension {
- SimpleIdRegistry REGISTRY = new DefaultedIdRegistry<>("air");
+ DefaultedRegistry REGISTRY = BlockRegistryImpl.REGISTRY;
+ int AUTO_ASSIGN_ID = -172;
/**
* @return whether this block is air.
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 d3e4dee39..2d48ebc18 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
@@ -5,67 +5,108 @@
import net.minecraft.block.Block;
import net.ornithemc.osl.blocks.api.BlockEvents;
+import net.ornithemc.osl.blocks.impl.block.BlockIdFixer;
import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
+import net.ornithemc.osl.registries.api.registry.DefaultedRegistry;
+import net.ornithemc.osl.registries.api.registry.Registries;
+import net.ornithemc.osl.registries.api.registry.Registry;
+import net.ornithemc.osl.registries.api.registry.RegistryKeys;
+import net.ornithemc.osl.registries.api.registry.ResourceKey;
+import net.ornithemc.osl.registries.api.registry.SyncedRegistries;
+import net.ornithemc.osl.registries.impl.registry.RegistriesImpl;
public final class BlockRegistryImpl {
+ public static final DefaultedRegistry REGISTRY = Registries.registerDefaulted(RegistryKeys.BLOCK, NamespacedIdentifiers.from("air"), () -> Block.BY_ID.getClass());
+
private static boolean locked = true;
- private static boolean initialized = false;
public static int getId(Block block) {
- return Block.REGISTRY.getId(block);
+ return REGISTRY.getId(block);
+ }
+
+ public static NamespacedIdentifier getIdentifier(Block block) {
+ return REGISTRY.getIdentifier(block);
}
- public static NamespacedIdentifier getKey(Block block) {
- return Block.REGISTRY.getKey(block);
+ public static ResourceKey getKey(Block block) {
+ return REGISTRY.getKey(block);
}
public static Block getBlock(int id) {
- return Block.REGISTRY.get(id);
+ return REGISTRY.get(id);
}
- public static Block getBlock(NamespacedIdentifier key) {
- return Block.REGISTRY.get(key);
+ public static Block getBlock(NamespacedIdentifier identifier) {
+ return REGISTRY.get(identifier);
}
- public static Set keySet() {
- return Block.REGISTRY.keySet();
+ public static Block getBlock(ResourceKey key) {
+ return REGISTRY.get(key);
}
- public static T register(int id, NamespacedIdentifier key, T block) {
+ public static Set identifierSet() {
+ return REGISTRY.identifierSet();
+ }
+
+ public static Set> keySet() {
+ return REGISTRY.keySet();
+ }
+
+ @SuppressWarnings("deprecation")
+ public static T register(NamespacedIdentifier identifier, T block) {
if (locked) {
- throw new IllegalStateException("register called too " + (initialized ? "late" : "early") + ": registry locked!");
+ throw new IllegalStateException("register called too early: registry locked!");
} else {
- Block.REGISTRY.register(id, key, block);
+ return Registry.register(REGISTRY, block.id, identifier, block);
}
+ }
- return block;
+ @SuppressWarnings("deprecation")
+ public static T register(ResourceKey key, T block) {
+ if (locked) {
+ throw new IllegalStateException("register called too early: registry locked!");
+ } else {
+ return Registry.register(REGISTRY, block.id, key, block);
+ }
}
- public static void lock() {
- if (!initialized) {
- throw new IllegalStateException("cannot lock block registry unless it's been initialized!");
+ @Deprecated
+ public static T register(int id, NamespacedIdentifier key, T block) {
+ if (locked) {
+ throw new IllegalStateException("register called too early: registry locked!");
+ } else {
+ if (block.id != id) {
+ throw new IllegalArgumentException("ID " + id + " does not match block ID " + block.id + " for " + key);
+ }
+
+ return Registry.register(REGISTRY, id, key, block);
}
+ }
- locked = true;
+ public static void init() {
+ SyncedRegistries.register(RegistryKeys.BLOCK);
+ SyncedRegistries.registerFixer(RegistryKeys.BLOCK, NamespacedIdentifiers.from("block/id"), new BlockIdFixer());
}
public static void unlock() {
- if (initialized) {
- throw new IllegalStateException("cannot unlock block registry once it's been initialized!");
- }
-
locked = false;
}
- public static void init() {
- if (locked) {
- throw new IllegalStateException("cannot initialize block registry when it's locked!");
- }
-
+ public static void registerBlocks() {
VanillaBlocks.init();
-
BlockEvents.REGISTER_BLOCKS.invoker().run();
- initialized = true;
+ }
+
+ public static void registerUnknownBlocks() {
+ for (Block block : Block.BY_ID) {
+ if (block != null && block.id != 0 && REGISTRY.getIdentifier(block) == REGISTRY.getDefaultIdentifier()) {
+ NamespacedIdentifier identifier = NamespacedIdentifiers.from("osl", "block_" + block.id);
+
+ RegistriesImpl.LOGGER.warn("Block {}/{}", block.id, block.getClass().getSimpleName() + " was not registered to OSL's Block registry! Adding it as '" + identifier + "'...");
+ BlockRegistryImpl.register(identifier, block);
+ }
+ }
}
}
diff --git a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/BlocksMixinPlugin.java b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/BlocksMixinPlugin.java
index 8b15e1628..1cd18f87c 100644
--- a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/BlocksMixinPlugin.java
+++ b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/BlocksMixinPlugin.java
@@ -8,10 +8,14 @@
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
+import net.fabricmc.api.EnvType;
+import net.fabricmc.loader.api.FabricLoader;
+
import net.ornithemc.osl.core.impl.util.MinecraftVersion;
public class BlocksMixinPlugin implements IMixinConfigPlugin {
+ public static final boolean CLIENT_SIDE = FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT;
public static final boolean BLOCK_IS_METHOD_PRESENT = MinecraftVersion.resolve().compareTo("13w01a") >= 0;
@Override
@@ -37,9 +41,39 @@ public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
if ("net.ornithemc.osl.blocks.impl.mixin.common.RepeaterBlockMixin".equals(mixinClassName)) {
return !BLOCK_IS_METHOD_PRESENT && MinecraftVersion.resolve().compareTo("b1.3") >= 0;
}
+ if ("net.ornithemc.osl.blocks.impl.mixin.common.BlockMixin_1_3_1_13w01a".equals(mixinClassName)) {
+ return MinecraftVersion.resolve().compareTo("1.3.1") >= 0 && MinecraftVersion.resolve().compareTo("13w01a") <= 0;
+ }
+ if ("net.ornithemc.osl.blocks.impl.mixin.common.BlockMixin_12w06a".equals(mixinClassName)) {
+ return MinecraftVersion.resolve().compareTo("12w06a") <= 0;
+ }
+ if ("net.ornithemc.osl.blocks.impl.mixin.common.BlockMixin_12w40a".equals(mixinClassName)) {
+ return MinecraftVersion.resolve().compareTo("12w40a") >= 0;
+ }
+ if ("net.ornithemc.osl.blocks.impl.mixin.common.BlockMixin_13w02a".equals(mixinClassName)) {
+ return MinecraftVersion.resolve().compareTo("13w02a") >= 0;
+ }
+ if ("net.ornithemc.osl.blocks.impl.mixin.common.BlockMixin_a1_1_0_12w06a".equals(mixinClassName)) {
+ return MinecraftVersion.resolve().compareTo(CLIENT_SIDE ? "a1.1.0" : "a0.2.0") >= 0 && MinecraftVersion.resolve().compareTo("12w06a") <= 0;
+ }
+ if ("net.ornithemc.osl.blocks.impl.mixin.common.BlockMixin_b1_0_1_3".equals(mixinClassName)) {
+ return MinecraftVersion.resolve().compareTo("b1.0") >= 0 && MinecraftVersion.resolve().compareTo("1.3") <= 0;
+ }
+ if ("net.ornithemc.osl.blocks.impl.mixin.common.BlockMixin_b1_6_tb3_1_4_7".equals(mixinClassName)) {
+ return MinecraftVersion.resolve().compareTo("b1.6-tb3") >= 0 && MinecraftVersion.resolve().compareTo("1.4.7") <= 0;
+ }
+ if ("net.ornithemc.osl.blocks.impl.mixin.common.BlockMixin_b1_9_pre5_12w38b".equals(mixinClassName)) {
+ return MinecraftVersion.resolve().compareTo("b1.9-pre5") >= 0 && MinecraftVersion.resolve().compareTo("12w38b") <= 0;
+ }
if ("net.ornithemc.osl.blocks.impl.mixin.common.WorldMixin".equals(mixinClassName)) {
return MinecraftVersion.resolve().compareTo("12w03a") <= 0;
}
+ if ("net.ornithemc.osl.blocks.impl.mixin.common.EndermanEntityMixin".equals(mixinClassName)) {
+ return MinecraftVersion.resolve().compareTo("b1.8") >= 0;
+ }
+ if ("net.ornithemc.osl.blocks.impl.mixin.common.StatsMixin".equals(mixinClassName)) {
+ return MinecraftVersion.resolve().compareTo("b1.4") >= 0;
+ }
return true;
}
diff --git a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/VanillaBlocks.java b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/VanillaBlocks.java
index b5f66e7ac..51c098c68 100644
--- a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/VanillaBlocks.java
+++ b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/VanillaBlocks.java
@@ -8,7 +8,7 @@
import net.ornithemc.osl.blocks.api.block.Blocks;
import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
-final class VanillaBlocks {
+public final class VanillaBlocks {
/**
* Namespaced IDs were introduced in 1.7. Before then, the numerical IDs
@@ -215,6 +215,8 @@ final class VanillaBlocks {
"coal_block"
};
+ public static final int MAX_ID = 255;
+
static void init() {
// Air block added by OSL
register(Blocks.AIR);
@@ -233,6 +235,7 @@ static void init() {
}
}
+ @SuppressWarnings("deprecation")
private static void register(Block block) {
if (block.id >= 0 && block.id < IDENTIFIERS.length) {
String identifier = IDENTIFIERS[block.id];
diff --git a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockIdFixer.java b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockIdFixer.java
new file mode 100644
index 000000000..97be5ac91
--- /dev/null
+++ b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockIdFixer.java
@@ -0,0 +1,19 @@
+package net.ornithemc.osl.blocks.impl.block;
+
+import net.minecraft.block.Block;
+
+import net.ornithemc.osl.registries.api.registry.sync.IdFixer;
+
+public class BlockIdFixer implements IdFixer {
+
+ @Override
+ public void apply() {
+ for (int id = 0; id < Block.BY_ID.length; id++) {
+ Block block = Block.BY_ID[id];
+
+ if (block != null) {
+ block.id = id;
+ }
+ }
+ }
+}
diff --git a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockItemsMapper.java b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockItemsMapper.java
new file mode 100644
index 000000000..b1fed95be
--- /dev/null
+++ b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockItemsMapper.java
@@ -0,0 +1,72 @@
+package net.ornithemc.osl.blocks.impl.block;
+
+import java.util.Collections;
+import java.util.IdentityHashMap;
+import java.util.Set;
+
+import it.unimi.dsi.fastutil.ints.Int2IntFunction;
+
+import net.minecraft.item.BlockItem;
+import net.minecraft.item.Item;
+
+import net.ornithemc.osl.blocks.impl.mixin.common.BlockItemAccess;
+import net.ornithemc.osl.registries.api.registry.sync.IdMapper;
+import net.ornithemc.osl.registries.api.registry.sync.RegistryMappings;
+
+public class BlockItemsMapper implements IdMapper {
+
+ public static BlockItemsMapper of(Item[] items) {
+ return new BlockItemsMapper(items);
+ }
+
+ private final Item[] items;
+ private final Set- missing;
+
+ private boolean applied;
+
+ private BlockItemsMapper(Item[] items) {
+ this.items = items;
+ this.missing = Collections.newSetFromMap(new IdentityHashMap<>());
+ }
+
+ @Override
+ public void apply(RegistryMappings mappings) {
+ this.missing.clear();
+ this.fixBlockItems(mappings::remap, true);
+
+ this.applied = true;
+ }
+
+ @Override
+ public void undo(RegistryMappings mappings) {
+ if (this.applied) {
+ this.fixBlockItems(mappings::unmap, false);
+ this.missing.clear();
+ }
+
+ this.applied = false;
+ }
+
+ private void fixBlockItems(Int2IntFunction mapper, boolean storeMissing) {
+ for (Item item : this.items) {
+ if (item == null || !(item instanceof BlockItem)) {
+ continue;
+ }
+
+ BlockItemAccess blockItem = (BlockItemAccess) item;
+
+ if (this.missing.contains(item)) {
+ continue;
+ }
+
+ int oldId = blockItem.accessBlock();
+ int newId = mapper.applyAsInt(oldId);
+
+ if (newId >= 0) {
+ blockItem.setBlock(newId);
+ } else if (storeMissing) {
+ this.missing.add(item);
+ }
+ }
+ }
+}
diff --git a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockPostInit.java b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockPostInit.java
new file mode 100644
index 000000000..1c4cdcef4
--- /dev/null
+++ b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/block/BlockPostInit.java
@@ -0,0 +1,7 @@
+package net.ornithemc.osl.blocks.impl.block;
+
+public interface BlockPostInit {
+
+ void osl$blocks$postInit();
+
+}
diff --git a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockItemAccess.java b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockItemAccess.java
new file mode 100644
index 000000000..3d2ab0c1a
--- /dev/null
+++ b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockItemAccess.java
@@ -0,0 +1,17 @@
+package net.ornithemc.osl.blocks.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();
+
+ @Accessor("block")
+ void setBlock(int block);
+
+}
diff --git a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin.java b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin.java
index 22634ed5c..00bbf4b18 100644
--- a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin.java
+++ b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin.java
@@ -2,21 +2,46 @@
import org.objectweb.asm.Opcodes;
+import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Mutable;
+import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.At.Shift;
import org.spongepowered.asm.mixin.injection.Inject;
-import org.spongepowered.asm.mixin.injection.Slice;
+import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
-import com.llamalad7.mixinextras.sugar.Share;
-import com.llamalad7.mixinextras.sugar.ref.LocalBooleanRef;
-
import net.minecraft.block.Block;
+import net.minecraft.block.material.Material;
+import net.minecraft.entity.living.mob.monster.EndermanEntity;
+import net.ornithemc.osl.blocks.api.block.BlockExtension;
import net.ornithemc.osl.blocks.impl.BlockRegistryImpl;
+import net.ornithemc.osl.blocks.impl.VanillaBlocks;
+import net.ornithemc.osl.blocks.impl.block.BlockPostInit;
+import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
+import net.ornithemc.osl.core.impl.util.MinecraftVersion;
+import net.ornithemc.osl.registries.api.registry.RegistryKeys;
+import net.ornithemc.osl.registries.api.registry.SyncedRegistries;
+import net.ornithemc.osl.registries.api.registry.sync.BooleanArrayMapper;
+import net.ornithemc.osl.registries.api.registry.sync.DynamicArrays;
+import net.ornithemc.osl.registries.api.registry.sync.IntArrayMapper;
+import net.ornithemc.osl.registries.api.registry.sync.ObjectArrayMapper;
@Mixin(Block.class)
-public class BlockMixin {
+public abstract class BlockMixin implements BlockExtension {
+
+ @Shadow @Final @Mutable
+ private static Block[] BY_ID;
+ @Shadow @Final @Mutable
+ private static boolean[] IS_SOLID_RENDER;
+ @Shadow @Final @Mutable
+ private static int[] OPACITIES;
+ @Shadow @Final @Mutable
+ private static boolean[] IS_TRANSLUCENT;
+ @Shadow @Final @Mutable
+ private static int[] LIGHT;
@Inject(
method = "",
@@ -30,31 +55,98 @@ public class BlockMixin {
@Inject(
method = "",
- slice = @Slice(
- from = @At(
- value = "FIELD",
- opcode = Opcodes.PUTSTATIC,
- target = "Lnet/minecraft/block/Block;STONE:Lnet/minecraft/block/Block;"
- )
- ),
at = @At(
- value = "CONSTANT",
- args = "intValue=256",
- ordinal = 0
+ // inject before the for-loop for checking USES_NEIGHBOR_LIGHT
+ value = "JUMP",
+ opcode = Opcodes.IF_ICMPGE,
+ shift = Shift.BY,
+ // it's extreme but this ensures that the injector is only invoked once
+ by = -5
+ )
+ )
+ private static void osl$blocks$registerBlocks(CallbackInfo ci) {
+ // in Beta 1.2 and above Item class init will happen before this point
+ // but that should not matter as there is a separate event for block
+ // item registration
+ BlockRegistryImpl.registerBlocks();
+ }
+
+ @Inject(
+ method = "",
+ at = @At(
+ value = "TAIL"
+ )
+ )
+ private static void osl$blocks$registerArrayMappers(CallbackInfo ci) {
+ BlockRegistryImpl.registerUnknownBlocks();
+
+ SyncedRegistries.registerMapper(RegistryKeys.BLOCK, NamespacedIdentifiers.from("block/by_id"), ObjectArrayMapper.of(BY_ID));
+ if (MinecraftVersion.resolve().compareTo("b1.5_02") <= 0) {
+ SyncedRegistries.registerMapper(RegistryKeys.BLOCK, NamespacedIdentifiers.from("block/is_solid"), BooleanArrayMapper.of(IS_SOLID_RENDER));
+ } else {
+ SyncedRegistries.registerMapper(RegistryKeys.BLOCK, NamespacedIdentifiers.from("block/is_solid_render"), BooleanArrayMapper.of(IS_SOLID_RENDER));
+ }
+ SyncedRegistries.registerMapper(RegistryKeys.BLOCK, NamespacedIdentifiers.from("block/opacity"), IntArrayMapper.of(OPACITIES));
+ SyncedRegistries.registerMapper(RegistryKeys.BLOCK, NamespacedIdentifiers.from("block/is_translucent"), BooleanArrayMapper.of(IS_TRANSLUCENT));
+ SyncedRegistries.registerMapper(RegistryKeys.BLOCK, NamespacedIdentifiers.from("block/light"), IntArrayMapper.of(LIGHT));
+
+ if (MinecraftVersion.resolve().compareTo("b1.8") >= 0) {
+ SyncedRegistries.registerMapper(RegistryKeys.BLOCK, NamespacedIdentifiers.from("block/enderman_holdable"), BooleanArrayMapper.of(EndermanEntity.HOLDABLE_BLOCKS));
+ }
+
+ for (Block block : BY_ID) {
+ if (block instanceof BlockPostInit) {
+ ((BlockPostInit) block).osl$blocks$postInit();
+ }
+ }
+ }
+
+ @ModifyVariable(
+ method = "",
+ argsOnly = true,
+ ordinal = 0,
+ at = @At(
+ value = "INVOKE",
+ target = "Ljava/lang/Object;()V",
+ shift = Shift.AFTER
)
)
- private static void osl$blocks$initAndLockBlockRegistry(CallbackInfo ci, @Share("osl$blocks$blocksRegistered") LocalBooleanRef blocksRegistered) {
- // in some versions this injector targets a for-loop
- if (!blocksRegistered.get()) {
- BlockRegistryImpl.init();
- BlockRegistryImpl.lock();
+ private int osl$blocks$handleAutoAssignId(int id) {
+ if (id == AUTO_ASSIGN_ID) {
+ // the Block[] array must contain all blocks so this should
+ // give us a valid ID for the Block registry to use.
+ id = DynamicArrays.length(BY_ID);
+
+ // keep 0-255 free for all Vanilla blocks
+ if (id <= VanillaBlocks.MAX_ID) {
+ id = VanillaBlocks.MAX_ID + 1;
+ }
}
- blocksRegistered.set(true);
+ return id;
+ }
+
+ @Inject(
+ method = "",
+ at = @At(
+ value = "FIELD",
+ target = "Lnet/minecraft/block/Block;BY_ID:[Lnet/minecraft/block/Block;",
+ opcode = Opcodes.GETSTATIC,
+ args = "array=set"
+ )
+ )
+ private void osl$blocks$growArrays(int id, Material material, CallbackInfo ci) {
+ int capacity = id + 1;
+
+ BY_ID = DynamicArrays.grow(BY_ID, capacity);
+ IS_SOLID_RENDER = DynamicArrays.grow(IS_SOLID_RENDER, capacity);
+ OPACITIES = DynamicArrays.grow(OPACITIES, capacity);
+ IS_TRANSLUCENT = DynamicArrays.grow(IS_TRANSLUCENT, capacity);
+ LIGHT = DynamicArrays.grow(LIGHT, capacity);
}
@Override
public String toString() {
- return "Block{" + BlockRegistryImpl.getKey((Block) (Object) this) + "}";
+ return "Block{" + BlockRegistryImpl.getIdentifier((Block) (Object) this) + "}";
}
}
diff --git a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin_12w06a.java b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin_12w06a.java
new file mode 100644
index 000000000..b37ab0097
--- /dev/null
+++ b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin_12w06a.java
@@ -0,0 +1,53 @@
+package net.ornithemc.osl.blocks.impl.mixin.common;
+
+import org.objectweb.asm.Opcodes;
+
+import org.spongepowered.asm.mixin.Final;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Mutable;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import net.minecraft.block.Block;
+import net.minecraft.block.material.Material;
+
+import net.ornithemc.osl.blocks.api.block.BlockExtension;
+import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
+import net.ornithemc.osl.registries.api.registry.RegistryKeys;
+import net.ornithemc.osl.registries.api.registry.SyncedRegistries;
+import net.ornithemc.osl.registries.api.registry.sync.BooleanArrayMapper;
+import net.ornithemc.osl.registries.api.registry.sync.DynamicArrays;
+
+@Mixin(Block.class)
+public abstract class BlockMixin_12w06a implements BlockExtension {
+
+ @Shadow @Final @Mutable
+ private static boolean[] f_08006312;
+
+ @Inject(
+ method = "",
+ at = @At(
+ value = "TAIL"
+ )
+ )
+ private static void osl$blocks$registerArrayMappers(CallbackInfo ci) {
+ SyncedRegistries.registerMapper(RegistryKeys.BLOCK, NamespacedIdentifiers.from("block/ticks_randomly"), BooleanArrayMapper.of(f_08006312));
+ }
+
+ @Inject(
+ method = "",
+ at = @At(
+ value = "FIELD",
+ target = "Lnet/minecraft/block/Block;BY_ID:[Lnet/minecraft/block/Block;",
+ opcode = Opcodes.GETSTATIC,
+ args = "array=set"
+ )
+ )
+ private void osl$blocks$growArrays(int id, Material material, CallbackInfo ci) {
+ int capacity = id + 1;
+
+ f_08006312 = DynamicArrays.grow(f_08006312, capacity);
+ }
+}
diff --git a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin_12w40a.java b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin_12w40a.java
new file mode 100644
index 000000000..41c383adf
--- /dev/null
+++ b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin_12w40a.java
@@ -0,0 +1,53 @@
+package net.ornithemc.osl.blocks.impl.mixin.common;
+
+import org.objectweb.asm.Opcodes;
+
+import org.spongepowered.asm.mixin.Final;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Mutable;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import net.minecraft.block.Block;
+import net.minecraft.block.material.Material;
+
+import net.ornithemc.osl.blocks.api.block.BlockExtension;
+import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
+import net.ornithemc.osl.registries.api.registry.RegistryKeys;
+import net.ornithemc.osl.registries.api.registry.SyncedRegistries;
+import net.ornithemc.osl.registries.api.registry.sync.BooleanArrayMapper;
+import net.ornithemc.osl.registries.api.registry.sync.DynamicArrays;
+
+@Mixin(Block.class)
+public abstract class BlockMixin_12w40a implements BlockExtension {
+
+ @Shadow @Final @Mutable
+ private static boolean[] USES_NEIGHBOR_LIGHT;
+
+ @Inject(
+ method = "",
+ at = @At(
+ value = "TAIL"
+ )
+ )
+ private static void osl$blocks$registerArrayMappers(CallbackInfo ci) {
+ SyncedRegistries.registerMapper(RegistryKeys.BLOCK, NamespacedIdentifiers.from("block/uses_neighbor_light"), BooleanArrayMapper.of(USES_NEIGHBOR_LIGHT));
+ }
+
+ @Inject(
+ method = "",
+ at = @At(
+ value = "FIELD",
+ target = "Lnet/minecraft/block/Block;BY_ID:[Lnet/minecraft/block/Block;",
+ opcode = Opcodes.GETSTATIC,
+ args = "array=set"
+ )
+ )
+ private void osl$blocks$growArrays(int id, Material material, CallbackInfo ci) {
+ int capacity = id + 1;
+
+ USES_NEIGHBOR_LIGHT = DynamicArrays.grow(USES_NEIGHBOR_LIGHT, capacity);
+ }
+}
diff --git a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin_13w02a.java b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin_13w02a.java
new file mode 100644
index 000000000..a2ddb5be2
--- /dev/null
+++ b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin_13w02a.java
@@ -0,0 +1,38 @@
+package net.ornithemc.osl.blocks.impl.mixin.common;
+
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
+
+import net.minecraft.block.Block;
+
+import net.ornithemc.osl.blocks.api.BlockRegistry;
+import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.core.impl.util.Util;
+
+@Mixin(Block.class)
+public class BlockMixin_13w02a {
+
+ @Shadow
+ private String key;
+
+ @Inject(
+ method = "getTranslationKey",
+ at = @At(
+ value = "HEAD"
+ )
+ )
+ private void osl$blocks$autoAssignTranslationKey(CallbackInfoReturnable cir) {
+ if (this.key == null) {
+ NamespacedIdentifier identifier = BlockRegistry.getIdentifier((Block) (Object) this);
+
+ if (identifier == null) {
+ this.key = "unknown";
+ } else {
+ this.key = Util.makeTranslationKey(identifier);
+ }
+ }
+ }
+}
diff --git a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin_1_3_1_13w01a.java b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin_1_3_1_13w01a.java
new file mode 100644
index 000000000..4018f3d1e
--- /dev/null
+++ b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin_1_3_1_13w01a.java
@@ -0,0 +1,38 @@
+package net.ornithemc.osl.blocks.impl.mixin.common;
+
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
+
+import net.minecraft.block.Block;
+
+import net.ornithemc.osl.blocks.api.BlockRegistry;
+import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.core.impl.util.Util;
+
+@Mixin(Block.class)
+public class BlockMixin_1_3_1_13w01a {
+
+ @Shadow
+ private String key;
+
+ @Inject(
+ method = "getTranslationKey",
+ at = @At(
+ value = "HEAD"
+ )
+ )
+ private void osl$blocks$autoAssignTranslationKey(CallbackInfoReturnable cir) {
+ if (this.key == null) {
+ NamespacedIdentifier identifier = BlockRegistry.getIdentifier((Block) (Object) this);
+
+ if (identifier == null) {
+ this.key = "tile.unknown";
+ } else {
+ this.key = Util.makeTranslationKey("tile", identifier);
+ }
+ }
+ }
+}
diff --git a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin_a1_1_0_12w06a.java b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin_a1_1_0_12w06a.java
new file mode 100644
index 000000000..fc19a2cba
--- /dev/null
+++ b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin_a1_1_0_12w06a.java
@@ -0,0 +1,53 @@
+package net.ornithemc.osl.blocks.impl.mixin.common;
+
+import org.objectweb.asm.Opcodes;
+
+import org.spongepowered.asm.mixin.Final;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Mutable;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import net.minecraft.block.Block;
+import net.minecraft.block.material.Material;
+
+import net.ornithemc.osl.blocks.api.block.BlockExtension;
+import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
+import net.ornithemc.osl.registries.api.registry.RegistryKeys;
+import net.ornithemc.osl.registries.api.registry.SyncedRegistries;
+import net.ornithemc.osl.registries.api.registry.sync.BooleanArrayMapper;
+import net.ornithemc.osl.registries.api.registry.sync.DynamicArrays;
+
+@Mixin(Block.class)
+public abstract class BlockMixin_a1_1_0_12w06a implements BlockExtension {
+
+ @Shadow @Final @Mutable
+ private static boolean[] f_72646756;
+
+ @Inject(
+ method = "",
+ at = @At(
+ value = "TAIL"
+ )
+ )
+ private static void osl$blocks$registerArrayMappers(CallbackInfo ci) {
+ SyncedRegistries.registerMapper(RegistryKeys.BLOCK, NamespacedIdentifiers.from("block/has_block_entity"), BooleanArrayMapper.of(f_72646756));
+ }
+
+ @Inject(
+ method = "",
+ at = @At(
+ value = "FIELD",
+ target = "Lnet/minecraft/block/Block;BY_ID:[Lnet/minecraft/block/Block;",
+ opcode = Opcodes.GETSTATIC,
+ args = "array=set"
+ )
+ )
+ private void osl$blocks$growArrays(int id, Material material, CallbackInfo ci) {
+ int capacity = id + 1;
+
+ f_72646756 = DynamicArrays.grow(f_72646756, capacity);
+ }
+}
diff --git a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin_b1_0_1_3.java b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin_b1_0_1_3.java
new file mode 100644
index 000000000..59380b977
--- /dev/null
+++ b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin_b1_0_1_3.java
@@ -0,0 +1,38 @@
+package net.ornithemc.osl.blocks.impl.mixin.common;
+
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
+
+import net.minecraft.block.Block;
+
+import net.ornithemc.osl.blocks.api.BlockRegistry;
+import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.core.impl.util.Util;
+
+@Mixin(Block.class)
+public class BlockMixin_b1_0_1_3 {
+
+ @Shadow
+ private String key;
+
+ @Inject(
+ method = "m_27822537",
+ at = @At(
+ value = "HEAD"
+ )
+ )
+ private void osl$blocks$autoAssignTranslationKey(CallbackInfoReturnable cir) {
+ if (this.key == null) {
+ NamespacedIdentifier identifier = BlockRegistry.getIdentifier((Block) (Object) this);
+
+ if (identifier == null) {
+ this.key = "tile.unknown";
+ } else {
+ this.key = Util.makeTranslationKey("tile", identifier);
+ }
+ }
+ }
+}
diff --git a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin_b1_6_tb3_1_4_7.java b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin_b1_6_tb3_1_4_7.java
new file mode 100644
index 000000000..222607a8f
--- /dev/null
+++ b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin_b1_6_tb3_1_4_7.java
@@ -0,0 +1,53 @@
+package net.ornithemc.osl.blocks.impl.mixin.common;
+
+import org.objectweb.asm.Opcodes;
+
+import org.spongepowered.asm.mixin.Final;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Mutable;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import net.minecraft.block.Block;
+import net.minecraft.block.material.Material;
+
+import net.ornithemc.osl.blocks.api.block.BlockExtension;
+import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
+import net.ornithemc.osl.registries.api.registry.RegistryKeys;
+import net.ornithemc.osl.registries.api.registry.SyncedRegistries;
+import net.ornithemc.osl.registries.api.registry.sync.BooleanArrayMapper;
+import net.ornithemc.osl.registries.api.registry.sync.DynamicArrays;
+
+@Mixin(Block.class)
+public abstract class BlockMixin_b1_6_tb3_1_4_7 implements BlockExtension {
+
+ @Shadow @Final @Mutable
+ private static boolean[] f_47406756;
+
+ @Inject(
+ method = "",
+ at = @At(
+ value = "TAIL"
+ )
+ )
+ private static void osl$blocks$registerArrayMappers(CallbackInfo ci) {
+ SyncedRegistries.registerMapper(RegistryKeys.BLOCK, NamespacedIdentifiers.from("block/update_clients"), BooleanArrayMapper.of(f_47406756));
+ }
+
+ @Inject(
+ method = "",
+ at = @At(
+ value = "FIELD",
+ target = "Lnet/minecraft/block/Block;BY_ID:[Lnet/minecraft/block/Block;",
+ opcode = Opcodes.GETSTATIC,
+ args = "array=set"
+ )
+ )
+ private void osl$blocks$growArrays(int id, Material material, CallbackInfo ci) {
+ int capacity = id + 1;
+
+ f_47406756 = DynamicArrays.grow(f_47406756, capacity);
+ }
+}
diff --git a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin_b1_9_pre5_12w38b.java b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin_b1_9_pre5_12w38b.java
new file mode 100644
index 000000000..d9de538d2
--- /dev/null
+++ b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/BlockMixin_b1_9_pre5_12w38b.java
@@ -0,0 +1,53 @@
+package net.ornithemc.osl.blocks.impl.mixin.common;
+
+import org.objectweb.asm.Opcodes;
+
+import org.spongepowered.asm.mixin.Final;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Mutable;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import net.minecraft.block.Block;
+import net.minecraft.block.material.Material;
+
+import net.ornithemc.osl.blocks.api.block.BlockExtension;
+import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
+import net.ornithemc.osl.registries.api.registry.RegistryKeys;
+import net.ornithemc.osl.registries.api.registry.SyncedRegistries;
+import net.ornithemc.osl.registries.api.registry.sync.BooleanArrayMapper;
+import net.ornithemc.osl.registries.api.registry.sync.DynamicArrays;
+
+@Mixin(Block.class)
+public abstract class BlockMixin_b1_9_pre5_12w38b implements BlockExtension {
+
+ @Shadow @Final @Mutable
+ private static boolean[] f_81217054;
+
+ @Inject(
+ method = "",
+ at = @At(
+ value = "TAIL"
+ )
+ )
+ private static void osl$blocks$registerArrayMappers(CallbackInfo ci) {
+ SyncedRegistries.registerMapper(RegistryKeys.BLOCK, NamespacedIdentifiers.from("block/uses_neighbor_light"), BooleanArrayMapper.of(f_81217054));
+ }
+
+ @Inject(
+ method = "",
+ at = @At(
+ value = "FIELD",
+ target = "Lnet/minecraft/block/Block;BY_ID:[Lnet/minecraft/block/Block;",
+ opcode = Opcodes.GETSTATIC,
+ args = "array=set"
+ )
+ )
+ private void osl$blocks$growArrays(int id, Material material, CallbackInfo ci) {
+ int capacity = id + 1;
+
+ f_81217054 = DynamicArrays.grow(f_81217054, capacity);
+ }
+}
diff --git a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/EndermanEntityMixin.java b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/EndermanEntityMixin.java
new file mode 100644
index 000000000..1b8db7f6c
--- /dev/null
+++ b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/EndermanEntityMixin.java
@@ -0,0 +1,37 @@
+package net.ornithemc.osl.blocks.impl.mixin.common;
+
+import org.objectweb.asm.Opcodes;
+
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.At.Shift;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import net.minecraft.block.Block;
+import net.minecraft.entity.living.mob.monster.EndermanEntity;
+
+import net.ornithemc.osl.registries.api.registry.sync.DynamicArrays;
+
+@Mixin(EndermanEntity.class)
+public class EndermanEntityMixin {
+
+ @Shadow
+ private static boolean[] HOLDABLE_BLOCKS;
+
+ @Inject(
+ method = "",
+ at = @At(
+ value = "FIELD",
+ target = "Lnet/minecraft/entity/living/mob/monster/EndermanEntity;HOLDABLE_BLOCKS:[Z",
+ opcode = Opcodes.PUTSTATIC,
+ shift = Shift.AFTER
+ )
+ )
+ private static void osl$blocks$growArray(CallbackInfo ci) {
+ int capacity = Block.BY_ID.length;
+
+ HOLDABLE_BLOCKS = DynamicArrays.grow(HOLDABLE_BLOCKS, capacity);
+ }
+}
diff --git a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/FireBlockMixin.java b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/FireBlockMixin.java
new file mode 100644
index 000000000..5ef90b243
--- /dev/null
+++ b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/FireBlockMixin.java
@@ -0,0 +1,53 @@
+package net.ornithemc.osl.blocks.impl.mixin.common;
+
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import net.minecraft.block.FireBlock;
+
+import net.ornithemc.osl.blocks.api.BlockRegistry;
+import net.ornithemc.osl.blocks.impl.block.BlockPostInit;
+import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.registries.api.registry.RegistryKeys;
+import net.ornithemc.osl.registries.api.registry.SyncedRegistries;
+import net.ornithemc.osl.registries.api.registry.sync.DynamicArrays;
+import net.ornithemc.osl.registries.api.registry.sync.IntArrayMapper;
+import net.ornithemc.osl.registries.impl.registry.RegistriesImpl;
+
+@Mixin(FireBlock.class)
+public class FireBlockMixin implements BlockPostInit {
+
+ @Shadow
+ private int[] flammability;
+ @Shadow
+ private int[] burnChance;
+
+ @Inject(
+ method = "setFlammable",
+ at = @At(
+ value = "HEAD"
+ )
+ )
+ private void osl$blocks$growArrays(int block, int flammability, int burnChance, CallbackInfo ci) {
+ int capacity = block + 1;
+
+ this.flammability = DynamicArrays.grow(this.flammability, capacity);
+ this.burnChance = DynamicArrays.grow(this.burnChance, capacity);
+ }
+
+ @Override
+ public void osl$blocks$postInit() {
+ FireBlock block = (FireBlock) (Object) this;
+ NamespacedIdentifier identifier = BlockRegistry.getIdentifier(block);
+
+ if (identifier == null) {
+ RegistriesImpl.LOGGER.warn("Unable to register FireBlock array mappers for unregistered block {} (ID {})", block, block.id);
+ } else {
+ SyncedRegistries.registerMapper(RegistryKeys.BLOCK, identifier.suffixed("/flammability"), IntArrayMapper.of(this.flammability));
+ SyncedRegistries.registerMapper(RegistryKeys.BLOCK, identifier.suffixed("/burn_chance"), IntArrayMapper.of(this.burnChance));
+ }
+ }
+}
diff --git a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/ItemMixin.java b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/ItemMixin.java
new file mode 100644
index 000000000..503e7eb0a
--- /dev/null
+++ b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/ItemMixin.java
@@ -0,0 +1,31 @@
+package net.ornithemc.osl.blocks.impl.mixin.common;
+
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import net.minecraft.item.Item;
+
+import net.ornithemc.osl.blocks.impl.block.BlockItemsMapper;
+import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
+import net.ornithemc.osl.registries.api.registry.RegistryKeys;
+import net.ornithemc.osl.registries.api.registry.SyncedRegistries;
+
+@Mixin(Item.class)
+public class ItemMixin {
+
+ @Shadow
+ private static Item[] BY_ID;
+
+ @Inject(
+ method = "",
+ at = @At(
+ value = "TAIL"
+ )
+ )
+ private static void osl$items$registerBlockItemMapper(CallbackInfo ci) {
+ SyncedRegistries.registerMapper(RegistryKeys.BLOCK, NamespacedIdentifiers.from("block/item"), BlockItemsMapper.of(BY_ID));
+ }
+}
diff --git a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/StatsMixin.java b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/StatsMixin.java
new file mode 100644
index 000000000..6b714741c
--- /dev/null
+++ b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/java/net/ornithemc/osl/blocks/impl/mixin/common/StatsMixin.java
@@ -0,0 +1,34 @@
+package net.ornithemc.osl.blocks.impl.mixin.common;
+
+import org.spongepowered.asm.mixin.Final;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import net.minecraft.stat.Stat;
+import net.minecraft.stat.Stats;
+
+import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
+import net.ornithemc.osl.registries.api.registry.RegistryKeys;
+import net.ornithemc.osl.registries.api.registry.SyncedRegistries;
+import net.ornithemc.osl.registries.api.registry.sync.ObjectArrayMapper;
+
+@Mixin(Stats.class)
+public class StatsMixin {
+
+ @Shadow @Final
+ private static Stat[] BLOCKS_MINED;
+
+ @Inject(
+ method = "initItemsCraftedStats",
+ at = @At(
+ value = "INVOKE",
+ target = "Lnet/minecraft/stat/Stats;mergeBlockStats([Lnet/minecraft/stat/Stat;)V"
+ )
+ )
+ private static void osl$items$registerStatsMapper(CallbackInfo ci) {
+ SyncedRegistries.registerMapper(RegistryKeys.BLOCK, NamespacedIdentifiers.from("stats/mined"), ObjectArrayMapper.of(BLOCKS_MINED));
+ }
+}
diff --git a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/resources/fabric.mod.json b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/resources/fabric.mod.json
index 044ed4365..89ea1d34e 100644
--- a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/resources/fabric.mod.json
+++ b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/resources/fabric.mod.json
@@ -3,6 +3,11 @@
"id": "osl-blocks",
"version": "0.1.1+mca1.0.1_01-mc1.6.4",
"environment": "*",
+ "entrypoints": {
+ "init": [
+ "net.ornithemc.osl.blocks.impl.BlockRegistryImpl::init"
+ ]
+ },
"mixins": [
"osl.blocks.mixins.json"
],
@@ -10,7 +15,14 @@
"depends": {
"fabricloader": "\u003e\u003d0.18.0",
"minecraft": "\u003e\u003d1.0.0-alpha.0.1 \u003c\u003d1.6.4",
- "osl-core": "\u003e\u003d0.9.0"
+ "osl-core": "\u003e\u003d0.9.0",
+ "osl-entrypoints": "\u003e\u003d0.5.0",
+ "osl-lifecycle-events": "\u003e\u003d0.6.0",
+ "osl-executors": "\u003e\u003d0.1.0",
+ "osl-text-components": "\u003e\u003d0.1.0-",
+ "osl-networking": "\u003e\u003d0.9.0",
+ "osl-networking-impl": "\u003e\u003d0.1.0",
+ "osl-registries": "\u003e\u003d0.1.0-"
},
"name": "OSL Blocks",
"description": "Blocks API and events.",
diff --git a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/resources/osl.blocks.classtweaker b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/resources/osl.blocks.classtweaker
index d4ae7c59e..499656278 100644
--- a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/resources/osl.blocks.classtweaker
+++ b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/resources/osl.blocks.classtweaker
@@ -11,4 +11,7 @@ transitive-accessible method net/minecraft/block/Block setKey (Ljava/lang/String
transitive-accessible method net/minecraft/block/Block setCreativeModeTab (Lnet/minecraft/item/CreativeModeTab;)Lnet/minecraft/block/Block;
transitive-accessible method net/minecraft/block/Block setSpriteName (Ljava/lang/String;)Lnet/minecraft/block/Block;
-transitive-inject-interface net/minecraft/block/Block net/ornithemc/osl/blocks/impl/block/BlockExtensionImpl
\ No newline at end of file
+transitive-inject-interface net/minecraft/block/Block net/ornithemc/osl/blocks/impl/block/BlockExtensionImpl
+
+mutable field net/minecraft/block/Block id I
+accessible field net/minecraft/entity/living/mob/monster/EndermanEntity HOLDABLE_BLOCKS [Z
diff --git a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/resources/osl.blocks.mixins.json b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/resources/osl.blocks.mixins.json
index 3ce092309..3167f0600 100644
--- a/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/resources/osl.blocks.mixins.json
+++ b/libraries/blocks/blocks-mca1.0.1_01-mc1.6.4/src/main/resources/osl.blocks.mixins.json
@@ -5,11 +5,24 @@
"compatibilityLevel": "JAVA_8",
"plugin": "net.ornithemc.osl.blocks.impl.BlocksMixinPlugin",
"mixins": [
+ "common.BlockItemAccess",
+ "common.BlockMixin_1_3_1_13w01a",
+ "common.BlockMixin_12w06a",
+ "common.BlockMixin_12w40a",
+ "common.BlockMixin_13w02a",
+ "common.BlockMixin_a1_1_0_12w06a",
+ "common.BlockMixin_b1_0_1_3",
+ "common.BlockMixin_b1_6_tb3_1_4_7",
+ "common.BlockMixin_b1_9_pre5_12w38b",
"common.BlockMixin",
"common.BlockMixinNew",
"common.BlockMixinOld",
+ "common.EndermanEntityMixin",
+ "common.FireBlockMixin",
+ "common.ItemMixin",
"common.RedstoneTorchBlockMixin",
"common.RepeaterBlockMixin",
+ "common.StatsMixin",
"common.WorldMixin"
],
"client": [
diff --git a/libraries/blocks/gradle.properties b/libraries/blocks/gradle.properties
index 32d5d351a..c4c63d1b7 100644
--- a/libraries/blocks/gradle.properties
+++ b/libraries/blocks/gradle.properties
@@ -3,4 +3,5 @@ library_name = Blocks
library_description = Blocks API and events.
library_version = 0.1.1
-osl_dependencies = core:>=0.9.0
+entrypoint_init = net.ornithemc.osl.blocks.impl.BlockRegistryImpl::init
+osl_dependencies = core:>=0.9.0,entrypoints:>=0.5.0,lifecycle-events:>=0.6.0,executors:>=0.1.0,text-components:>=0.1.0-,networking:>=0.9.0,networking-impl:>=0.1.0,registries:>=0.1.0-
diff --git a/libraries/core/core-mc14w27a-mc1.14.4/src/main/java/net/ornithemc/osl/core/impl/mixin/common/IdentifierMixin.java b/libraries/core/core-mc14w27a-mc1.14.4/src/main/java/net/ornithemc/osl/core/impl/mixin/common/IdentifierMixin.java
index 86722f15c..d06981302 100644
--- a/libraries/core/core-mc14w27a-mc1.14.4/src/main/java/net/ornithemc/osl/core/impl/mixin/common/IdentifierMixin.java
+++ b/libraries/core/core-mc14w27a-mc1.14.4/src/main/java/net/ornithemc/osl/core/impl/mixin/common/IdentifierMixin.java
@@ -42,4 +42,14 @@ public String namespace() {
public String identifier() {
return path;
}
+
+ @Override
+ public NamespacedIdentifier prefixed(String prefix) {
+ return new Identifier(namespace, prefix + path);
+ }
+
+ @Override
+ public NamespacedIdentifier suffixed(String suffix) {
+ return new Identifier(namespace, path + suffix);
+ }
}
diff --git a/libraries/core/core-mca1.0.1_01-mc14w26c/src/main/java/net/ornithemc/osl/core/impl/mixin/client/IdentifierMixin.java b/libraries/core/core-mca1.0.1_01-mc14w26c/src/main/java/net/ornithemc/osl/core/impl/mixin/client/IdentifierMixin.java
index 142dd63d7..eb965addf 100644
--- a/libraries/core/core-mca1.0.1_01-mc14w26c/src/main/java/net/ornithemc/osl/core/impl/mixin/client/IdentifierMixin.java
+++ b/libraries/core/core-mca1.0.1_01-mc14w26c/src/main/java/net/ornithemc/osl/core/impl/mixin/client/IdentifierMixin.java
@@ -42,4 +42,14 @@ public String namespace() {
public String identifier() {
return path;
}
+
+ @Override
+ public NamespacedIdentifier prefixed(String prefix) {
+ return new Identifier(namespace, prefix + path);
+ }
+
+ @Override
+ public NamespacedIdentifier suffixed(String suffix) {
+ return new Identifier(namespace, path + suffix);
+ }
}
diff --git a/libraries/core/src/main/java/net/ornithemc/osl/core/api/registry/DefaultedIdRegistry.java b/libraries/core/src/main/java/net/ornithemc/osl/core/api/registry/DefaultedIdRegistry.java
index 0fb572422..8fb0f1f06 100644
--- a/libraries/core/src/main/java/net/ornithemc/osl/core/api/registry/DefaultedIdRegistry.java
+++ b/libraries/core/src/main/java/net/ornithemc/osl/core/api/registry/DefaultedIdRegistry.java
@@ -3,6 +3,10 @@
import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
+/**
+ * @deprecated use Registries API instead
+ */
+@Deprecated
public class DefaultedIdRegistry extends SimpleIdRegistry {
private final NamespacedIdentifier defaultKey;
diff --git a/libraries/core/src/main/java/net/ornithemc/osl/core/api/registry/IdBiMap.java b/libraries/core/src/main/java/net/ornithemc/osl/core/api/registry/IdBiMap.java
index 12512e89c..2bdfae846 100644
--- a/libraries/core/src/main/java/net/ornithemc/osl/core/api/registry/IdBiMap.java
+++ b/libraries/core/src/main/java/net/ornithemc/osl/core/api/registry/IdBiMap.java
@@ -7,6 +7,10 @@
import it.unimi.dsi.fastutil.objects.Reference2IntMap;
import it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap;
+/**
+ * @deprecated use Registries API instead
+ */
+@Deprecated
public class IdBiMap implements Iterable {
private final Int2ReferenceMap values;
diff --git a/libraries/core/src/main/java/net/ornithemc/osl/core/api/registry/SimpleIdRegistry.java b/libraries/core/src/main/java/net/ornithemc/osl/core/api/registry/SimpleIdRegistry.java
index 4c9d21735..edfee7844 100644
--- a/libraries/core/src/main/java/net/ornithemc/osl/core/api/registry/SimpleIdRegistry.java
+++ b/libraries/core/src/main/java/net/ornithemc/osl/core/api/registry/SimpleIdRegistry.java
@@ -13,6 +13,10 @@
import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+/**
+ * @deprecated use Registries API instead
+ */
+@Deprecated
public class SimpleIdRegistry implements Iterable {
private final Int2ReferenceMap values;
diff --git a/libraries/core/src/main/java/net/ornithemc/osl/core/api/util/NamespacedIdentifier.java b/libraries/core/src/main/java/net/ornithemc/osl/core/api/util/NamespacedIdentifier.java
index 598ac9943..f5435f853 100644
--- a/libraries/core/src/main/java/net/ornithemc/osl/core/api/util/NamespacedIdentifier.java
+++ b/libraries/core/src/main/java/net/ornithemc/osl/core/api/util/NamespacedIdentifier.java
@@ -35,4 +35,14 @@ public interface NamespacedIdentifier {
*/
String identifier();
+ /**
+ * @return a copy of this {@code NamespacedIdentifier} with the given prefix.
+ */
+ NamespacedIdentifier prefixed(String prefix);
+
+ /**
+ * @return a copy of this {@code NamespacedIdentifier} with the given suffix.
+ */
+ NamespacedIdentifier suffixed(String suffix);
+
}
diff --git a/libraries/core/src/main/java/net/ornithemc/osl/core/impl/util/IdentifierImpl.java b/libraries/core/src/main/java/net/ornithemc/osl/core/impl/util/IdentifierImpl.java
index 0358d11b6..ce9caea96 100644
--- a/libraries/core/src/main/java/net/ornithemc/osl/core/impl/util/IdentifierImpl.java
+++ b/libraries/core/src/main/java/net/ornithemc/osl/core/impl/util/IdentifierImpl.java
@@ -15,4 +15,14 @@ default String namespace() {
default String identifier() {
throw new AbstractMethodError("Not implemented!");
}
+
+ @Override
+ default NamespacedIdentifier prefixed(String prefix) {
+ throw new AbstractMethodError("Not implemented!");
+ }
+
+ @Override
+ default NamespacedIdentifier suffixed(String prefix) {
+ throw new AbstractMethodError("Not implemented!");
+ }
}
diff --git a/libraries/core/src/main/java/net/ornithemc/osl/core/impl/util/NamespacedIdentifierImpl.java b/libraries/core/src/main/java/net/ornithemc/osl/core/impl/util/NamespacedIdentifierImpl.java
index f373c4363..9080f4152 100644
--- a/libraries/core/src/main/java/net/ornithemc/osl/core/impl/util/NamespacedIdentifierImpl.java
+++ b/libraries/core/src/main/java/net/ornithemc/osl/core/impl/util/NamespacedIdentifierImpl.java
@@ -54,4 +54,14 @@ public String namespace() {
public String identifier() {
return identifier;
}
+
+ @Override
+ public NamespacedIdentifier prefixed(String prefix) {
+ return new NamespacedIdentifierImpl(namespace, prefix + identifier);
+ }
+
+ @Override
+ public NamespacedIdentifier suffixed(String suffix) {
+ return new NamespacedIdentifierImpl(namespace, identifier + suffix);
+ }
}
diff --git a/libraries/core/src/main/java/net/ornithemc/osl/core/impl/util/Util.java b/libraries/core/src/main/java/net/ornithemc/osl/core/impl/util/Util.java
index 68b106277..deff3908e 100644
--- a/libraries/core/src/main/java/net/ornithemc/osl/core/impl/util/Util.java
+++ b/libraries/core/src/main/java/net/ornithemc/osl/core/impl/util/Util.java
@@ -4,8 +4,22 @@
import java.util.List;
import java.util.concurrent.CompletableFuture;
+import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+
public final class Util {
+ public static String makeTranslationKey(NamespacedIdentifier identifier) {
+ return identifier.namespace() + "." + identifier.identifier().replace('/', '.');
+ }
+
+ public static String makeTranslationKey(String prefix, NamespacedIdentifier identifier) {
+ return prefix + "." + makeTranslationKey(identifier);
+ }
+
+ public static String makeTranslationKey(String prefix, NamespacedIdentifier identifier, String suffix) {
+ return makeTranslationKey(prefix, identifier) + "." + suffix;
+ }
+
public static CompletableFuture
> sequence(List extends CompletableFuture extends V>> futures) {
List results = new ArrayList<>(futures.size());
diff --git a/libraries/items/gradle.properties b/libraries/items/gradle.properties
index b5cf61cbe..994fbee8d 100644
--- a/libraries/items/gradle.properties
+++ b/libraries/items/gradle.properties
@@ -3,4 +3,5 @@ library_name = Items
library_description = Items API and events.
library_version = 0.1.0
-osl_dependencies = core:>=0.9.0,blocks:>=0.1.0
+entrypoint_init = net.ornithemc.osl.items.impl.ItemRegistryImpl::init
+osl_dependencies = core:>=0.9.0,entrypoints:>=0.5.0,lifecycle-events:>=0.6.0,executors:>=0.1.0,text-components:>=0.1.0-,networking:>=0.9.0,networking-impl:>=0.1.0,registries:>=0.1.0-,blocks:>=0.1.0
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
index 4d0923b99..e4b60f8b4 100644
--- 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
@@ -22,7 +22,7 @@ public final class ItemEvents {
*
* {@code
* ItemEvents.REGISTER_ITEMS.register(() -> {
- * ItemRegistry.register(999, NamespacedIdentifiers.from("example", "cookie"), new CookieItem());
+ * ItemRegistry.register(NamespacedIdentifiers.from("example", "cookie"), new CookieItem());
* });
* }
*
diff --git a/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/api/ItemRegistry.java b/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/api/ItemRegistry.java
index 5c9fdcbc3..c7b4f4573 100644
--- a/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/api/ItemRegistry.java
+++ b/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/api/ItemRegistry.java
@@ -8,12 +8,16 @@
import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
import net.ornithemc.osl.items.impl.ItemRegistryImpl;
+import net.ornithemc.osl.registries.api.registry.Registry;
+import net.ornithemc.osl.registries.api.registry.ResourceKey;
/**
* Public access to the Items registry.
*/
public final class ItemRegistry {
+ public static final Registry- REGISTRY = ItemRegistryImpl.REGISTRY;
+
/**
* @return the numerical ID assigned to the given item.
*/
@@ -24,7 +28,14 @@ public static int getId(Item item) {
/**
* @return the namespaced ID assigned to the given item.
*/
- public static NamespacedIdentifier getKey(Item item) {
+ public static NamespacedIdentifier getIdentifier(Item item) {
+ return ItemRegistryImpl.getIdentifier(item);
+ }
+
+ /**
+ * @return the resource key assigned to the given item.
+ */
+ public static ResourceKey
- getKey(Item item) {
return ItemRegistryImpl.getKey(item);
}
@@ -38,14 +49,35 @@ public static Item getItem(int id) {
/**
* @return the item mapped to the given namespaced ID.
*/
- public static Item getItem(NamespacedIdentifier key) {
+ public static Item getItem(NamespacedIdentifier identifier) {
+ return ItemRegistryImpl.getItem(identifier);
+ }
+
+ /**
+ * @return the item mapped to the given resource key.
+ */
+ public static Item getItem(ResourceKey
- key) {
return ItemRegistryImpl.getItem(key);
}
+ /**
+ * @return the item mapped to the given block.
+ */
+ public static Item getItem(Block block) {
+ return ItemRegistryImpl.getItem(block);
+ }
+
/**
* @return a set containing all namespaced IDs in the registry.
*/
- public static Set keySet() {
+ public static Set identifierSet() {
+ return ItemRegistryImpl.identifierSet();
+ }
+
+ /**
+ * @return a set containing all resource keys in the registry.
+ */
+ public static Set> keySet() {
return ItemRegistryImpl.keySet();
}
@@ -76,13 +108,37 @@ public static T register(Block block, T item) {
return ItemRegistryImpl.register(block, item);
}
+ /**
+ * @param the item type.
+ * @param identifier the namespaced ID of the item.
+ * @param item the item to register.
+ * @return the registered item.
+ */
+ public static T register(NamespacedIdentifier identifier, T item) {
+ return ItemRegistryImpl.register(identifier, item);
+ }
+
+ /**
+ * @param the item type.
+ * @param key the resource key of the item.
+ * @param item the item to register.
+ * @return the registered item.
+ */
+ public static T register(ResourceKey
- key, T item) {
+ return ItemRegistryImpl.register(key, item);
+ }
+
/**
* @param the item type.
* @param id the numerical ID of the item.
* @param key the namespaced ID of the item.
* @param item the item to register.
* @return the registered item.
+ *
+ * @deprecated use {@linkplain #register(NamespacedIdentifier, Item)}
+ * or {@linkplain #register(ResourceKey, Item)} instead.
*/
+ @Deprecated
public static T register(int id, NamespacedIdentifier key, T item) {
return ItemRegistryImpl.register(id, key, item);
}
diff --git a/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/impl/ItemRegistryImpl.java b/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/impl/ItemRegistryImpl.java
index 72e7dace4..ba2a299ed 100644
--- a/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/impl/ItemRegistryImpl.java
+++ b/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/impl/ItemRegistryImpl.java
@@ -3,7 +3,6 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
-import java.util.stream.Collectors;
import net.minecraft.block.Block;
import net.minecraft.item.BlockItem;
@@ -11,36 +10,55 @@
import net.ornithemc.osl.blocks.api.BlockRegistry;
import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
-import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
import net.ornithemc.osl.items.api.ItemEvents;
import net.ornithemc.osl.items.impl.mixin.common.BlockItemAccess;
+import net.ornithemc.osl.registries.api.registry.Registry;
+import net.ornithemc.osl.registries.api.registry.RegistryKeys;
+import net.ornithemc.osl.registries.api.registry.ResourceKey;
+import net.ornithemc.osl.registries.api.registry.SyncedRegistries;
+import net.ornithemc.osl.registries.impl.registry.VanillaRegistries;
public final class ItemRegistryImpl {
+ public static final Registry
- REGISTRY = VanillaRegistries.registerSimple(RegistryKeys.ITEM, Item.REGISTRY);
public static final Map BLOCK_ITEMS = new HashMap<>();
private static boolean locked = true;
- private static boolean initialized = false;
public static int getId(Item item) {
- return Item.REGISTRY.getId(item);
+ return REGISTRY.getId(item);
}
- public static NamespacedIdentifier getKey(Item item) {
- String key = Item.REGISTRY.getKey(item);
- return key == null ? null : NamespacedIdentifiers.parse(key);
+ public static NamespacedIdentifier getIdentifier(Item item) {
+ return REGISTRY.getIdentifier(item);
+ }
+
+ public static ResourceKey
- getKey(Item item) {
+ return REGISTRY.getKey(item);
}
public static Item getItem(int id) {
- return Item.REGISTRY.get(id);
+ return REGISTRY.get(id);
+ }
+
+ public static Item getItem(NamespacedIdentifier identifier) {
+ return REGISTRY.get(identifier);
+ }
+
+ public static Item getItem(ResourceKey
- key) {
+ return REGISTRY.get(key);
}
- public static Item getItem(NamespacedIdentifier key) {
- return Item.REGISTRY.get(key.toString());
+ public static Item getItem(Block block) {
+ return Item.byBlock(block);
}
- public static Set keySet() {
- return Item.REGISTRY.keySet().stream().map(NamespacedIdentifiers::parse).collect(Collectors.toSet());
+ public static Set identifierSet() {
+ return REGISTRY.identifierSet();
+ }
+
+ public static Set> keySet() {
+ return REGISTRY.keySet();
}
public static BlockItem register(Block block) {
@@ -56,41 +74,43 @@ public static T register(Block block, T item) {
BLOCK_ITEMS.put(block, item);
}
- return register(BlockRegistry.getId(block), BlockRegistry.getKey(block), item);
+ return register(BlockRegistry.getIdentifier(block), item);
}
- public static T register(int id, NamespacedIdentifier key, T item) {
+ public static T register(NamespacedIdentifier identifier, T item) {
if (locked) {
- throw new IllegalStateException("register called too " + (initialized ? "late" : "early") + ": registry locked!");
+ throw new IllegalStateException("register called too early: registry locked!");
} else {
- Item.REGISTRY.register(id, key.toString(), item);
+ return Registry.register(REGISTRY, identifier, item);
}
+ }
- return item;
+ public static T register(ResourceKey
- key, T item) {
+ if (locked) {
+ throw new IllegalStateException("register called too early: registry locked!");
+ } else {
+ return Registry.register(REGISTRY, key, item);
+ }
}
- public static void lock() {
- if (!initialized) {
- throw new IllegalStateException("cannot lock item registry unless it's been initialized!");
+ @Deprecated
+ public static T register(int id, NamespacedIdentifier key, T item) {
+ if (locked) {
+ throw new IllegalStateException("register called too early: registry locked!");
+ } else {
+ return Registry.register(REGISTRY, id, key, item);
}
+ }
- locked = true;
+ public static void init() {
+ SyncedRegistries.register(RegistryKeys.ITEM);
}
public static void unlock() {
- if (initialized) {
- throw new IllegalStateException("cannot unlock item registry once it's been initialized!");
- }
-
locked = false;
}
- public static void init() {
- if (locked) {
- throw new IllegalStateException("cannot initialize item registry when it's locked!");
- }
-
+ public static void registerItems() {
ItemEvents.REGISTER_ITEMS.invoker().run();
- initialized = true;
}
}
diff --git a/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/impl/ItemsMixinPlugin.java b/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/impl/ItemsMixinPlugin.java
index 03397a6ae..9c1787358 100644
--- a/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/impl/ItemsMixinPlugin.java
+++ b/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/impl/ItemsMixinPlugin.java
@@ -13,6 +13,7 @@
public class ItemsMixinPlugin implements IMixinConfigPlugin {
public static final boolean SPECIAL_BLOCK_ITEM_HANDLING = MinecraftVersion.resolve().compareTo("13w37a") >= 0;
+ public static final boolean BLOCK_ITEMS_MAP_EXISTS = MinecraftVersion.resolve().compareTo("14w25a") >= 0;
@Override
public void onLoad(String mixinPackage) {
@@ -31,6 +32,12 @@ public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
if ("net.ornithemc.osl.items.impl.mixin.common.ItemMixinOld".equals(mixinClassName)) {
return !SPECIAL_BLOCK_ITEM_HANDLING;
}
+ if ("net.ornithemc.osl.items.impl.mixin.common.ItemMixin_14w21b".equals(mixinClassName)) {
+ return !BLOCK_ITEMS_MAP_EXISTS;
+ }
+ if ("net.ornithemc.osl.items.impl.mixin.common.ItemMixin_14w25a".equals(mixinClassName)) {
+ return BLOCK_ITEMS_MAP_EXISTS;
+ }
return true;
}
diff --git a/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/impl/mixin/common/ItemMixin.java b/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/impl/mixin/common/ItemMixin.java
new file mode 100644
index 000000000..356aaff28
--- /dev/null
+++ b/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/impl/mixin/common/ItemMixin.java
@@ -0,0 +1,54 @@
+package net.ornithemc.osl.items.impl.mixin.common;
+
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.Unique;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
+
+import net.minecraft.item.Item;
+
+import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.core.impl.util.Util;
+import net.ornithemc.osl.items.api.ItemRegistry;
+
+@Mixin(Item.class)
+public class ItemMixin {
+
+ @Shadow
+ private String key;
+
+ @Inject(
+ method = "getTranslationKey()Ljava/lang/String;",
+ at = @At(
+ value = "HEAD"
+ )
+ )
+ private void osl$items$autoAssignTranslationKey1(CallbackInfoReturnable cir) {
+ this.ensureTranslationKeyExists();
+ }
+
+ @Inject(
+ method = "getTranslationKey(Lnet/minecraft/item/ItemStack;)Ljava/lang/String;",
+ at = @At(
+ value = "HEAD"
+ )
+ )
+ private void osl$items$autoAssignTranslationKey2(CallbackInfoReturnable cir) {
+ this.ensureTranslationKeyExists();
+ }
+
+ @Unique
+ private void ensureTranslationKeyExists() {
+ if (this.key == null) {
+ NamespacedIdentifier identifier = ItemRegistry.getIdentifier((Item) (Object) this);
+
+ if (identifier == null) {
+ this.key = "unknown";
+ } else {
+ this.key = Util.makeTranslationKey(identifier);
+ }
+ }
+ }
+}
diff --git a/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/impl/mixin/common/ItemMixinNew.java b/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/impl/mixin/common/ItemMixinNew.java
index 017fd6764..7153867b7 100644
--- a/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/impl/mixin/common/ItemMixinNew.java
+++ b/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/impl/mixin/common/ItemMixinNew.java
@@ -34,10 +34,10 @@ public class ItemMixinNew {
target = "Lnet/minecraft/util/registry/IdRegistry;keySet()Ljava/util/Set;"
)
)
- private static void osl$items$initAndLockItemRegistry(CallbackInfo ci, @Local HashSet blocksToSkip) {
- ItemRegistryImpl.init();
- ItemRegistryImpl.lock();
+ private static void osl$items$registerItems(CallbackInfo ci, @Local HashSet blocksToSkip) {
+ ItemRegistryImpl.registerItems();
+ // this set contains all blocks for which not to auto-generate block items
blocksToSkip.addAll(ItemRegistryImpl.BLOCK_ITEMS.keySet());
}
}
diff --git a/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/impl/mixin/common/ItemMixinOld.java b/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/impl/mixin/common/ItemMixinOld.java
index b9cc935ab..a7bc4ac05 100644
--- a/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/impl/mixin/common/ItemMixinOld.java
+++ b/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/impl/mixin/common/ItemMixinOld.java
@@ -37,9 +37,8 @@ public class ItemMixinOld {
target = "Lnet/minecraft/util/registry/IdRegistry;keySet()Ljava/util/Set;"
)
)
- private static void osl$items$initAndLockItemRegistry(CallbackInfo ci) {
- ItemRegistryImpl.init();
- ItemRegistryImpl.lock();
+ private static void osl$items$registerItems(CallbackInfo ci) {
+ ItemRegistryImpl.registerItems();
}
@WrapOperation(
diff --git a/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/impl/mixin/common/ItemMixin_14w21b.java b/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/impl/mixin/common/ItemMixin_14w21b.java
new file mode 100644
index 000000000..eec9d9fa2
--- /dev/null
+++ b/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/impl/mixin/common/ItemMixin_14w21b.java
@@ -0,0 +1,51 @@
+package net.ornithemc.osl.items.impl.mixin.common;
+
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Overwrite;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Slice;
+
+import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
+import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
+import com.llamalad7.mixinextras.sugar.Local;
+
+import net.minecraft.block.Block;
+import net.minecraft.item.Item;
+import net.minecraft.util.registry.IdRegistry;
+
+import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.items.api.ItemRegistry;
+import net.ornithemc.osl.items.impl.ItemRegistryImpl;
+
+@Mixin(Item.class)
+public class ItemMixin_14w21b {
+
+ @Overwrite
+ public static Item byBlock(Block block) {
+ return ItemRegistryImpl.BLOCK_ITEMS.get(block);
+ }
+
+ @WrapOperation(
+ method = "init",
+ slice = @Slice(
+ from = @At(
+ value = "INVOKE",
+ target = "Lnet/minecraft/block/Block;getId(Lnet/minecraft/block/Block;)I"
+ )
+ ),
+ at = @At(
+ value = "INVOKE",
+ target = "Lnet/minecraft/util/registry/IdRegistry;register(ILjava/lang/String;Ljava/lang/Object;)V"
+ )
+ )
+ private static void osl$items$registerVanillaBlockItem(IdRegistry
- registry, int id, String key, Object value, Operation op, @Local Block block) {
+ op.call(registry, id, key, value);
+
+ Item item = (Item) value;
+ NamespacedIdentifier identifier = ItemRegistry.getIdentifier(item);
+
+ if (identifier != null) {
+ ItemRegistryImpl.BLOCK_ITEMS.put(block, item);
+ }
+ }
+}
diff --git a/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/impl/mixin/common/ItemMixin_14w25a.java b/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/impl/mixin/common/ItemMixin_14w25a.java
new file mode 100644
index 000000000..7230ede76
--- /dev/null
+++ b/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/impl/mixin/common/ItemMixin_14w25a.java
@@ -0,0 +1,33 @@
+package net.ornithemc.osl.items.impl.mixin.common;
+
+import java.util.Map;
+
+import org.spongepowered.asm.mixin.Final;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Mutable;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import net.minecraft.block.Block;
+import net.minecraft.item.Item;
+
+import net.ornithemc.osl.items.impl.ItemRegistryImpl;
+
+@Mixin(Item.class)
+public class ItemMixin_14w25a {
+
+ @Shadow @Final @Mutable
+ private static Map f_62044349;
+
+ @Inject(
+ method = "",
+ at = @At(
+ value = "TAIL"
+ )
+ )
+ private static void osl$items$replaceBlockItemsMap(CallbackInfo ci) {
+ f_62044349 = ItemRegistryImpl.BLOCK_ITEMS;
+ }
+}
diff --git a/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/impl/mixin/common/StatsMixin.java b/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/impl/mixin/common/StatsMixin.java
new file mode 100644
index 000000000..13c0a2a18
--- /dev/null
+++ b/libraries/items/items-mc13w36a-mc14w25b/src/main/java/net/ornithemc/osl/items/impl/mixin/common/StatsMixin.java
@@ -0,0 +1,52 @@
+package net.ornithemc.osl.items.impl.mixin.common;
+
+import java.util.Map;
+
+import org.spongepowered.asm.mixin.Final;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import net.minecraft.stat.Stat;
+import net.minecraft.stat.Stats;
+
+import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
+import net.ornithemc.osl.core.impl.util.MinecraftVersion;
+import net.ornithemc.osl.registries.api.registry.RegistryKeys;
+import net.ornithemc.osl.registries.api.registry.SyncedRegistries;
+import net.ornithemc.osl.registries.api.registry.sync.ObjectArrayMapper;
+import net.ornithemc.osl.registries.impl.registry.sync.StatsMapper;
+
+@Mixin(Stats.class)
+public class StatsMixin {
+
+ @Shadow @Final
+ private static Map BY_KEY;
+ @Shadow @Final
+ private static Stat[] ITEMS_CRAFTED;
+ @Shadow @Final
+ private static Stat[] ITEMS_USED;
+ @Shadow @Final
+ private static Stat[] ITEMS_BROKEN;
+
+ @Inject(
+ // inject at init instead of in case the arrays are resized...
+ method = "init",
+ at = @At(
+ value = "TAIL"
+ )
+ )
+ private static void osl$items$registerStatsMapper(CallbackInfo ci) {
+ if (MinecraftVersion.resolve().compareTo("14w06a") < 0) {
+ SyncedRegistries.registerMapper(RegistryKeys.ITEM, NamespacedIdentifiers.from("stats/crafted"), StatsMapper.of(BY_KEY, ITEMS_CRAFTED));
+ SyncedRegistries.registerMapper(RegistryKeys.ITEM, NamespacedIdentifiers.from("stats/used"), StatsMapper.of(BY_KEY, ITEMS_USED));
+ SyncedRegistries.registerMapper(RegistryKeys.ITEM, NamespacedIdentifiers.from("stats/broken"), StatsMapper.of(BY_KEY, ITEMS_BROKEN));
+ } else {
+ SyncedRegistries.registerMapper(RegistryKeys.ITEM, NamespacedIdentifiers.from("stats/crafted"), ObjectArrayMapper.of(ITEMS_CRAFTED));
+ SyncedRegistries.registerMapper(RegistryKeys.ITEM, NamespacedIdentifiers.from("stats/used"), ObjectArrayMapper.of(ITEMS_USED));
+ SyncedRegistries.registerMapper(RegistryKeys.ITEM, NamespacedIdentifiers.from("stats/broken"), ObjectArrayMapper.of(ITEMS_BROKEN));
+ }
+ }
+}
diff --git a/libraries/items/items-mc13w36a-mc14w25b/src/main/resources/fabric.mod.json b/libraries/items/items-mc13w36a-mc14w25b/src/main/resources/fabric.mod.json
index d1b645c9c..091245c13 100644
--- a/libraries/items/items-mc13w36a-mc14w25b/src/main/resources/fabric.mod.json
+++ b/libraries/items/items-mc13w36a-mc14w25b/src/main/resources/fabric.mod.json
@@ -3,6 +3,11 @@
"id": "osl-items",
"version": "0.1.0+mc13w36a-mc14w25b",
"environment": "*",
+ "entrypoints": {
+ "init": [
+ "net.ornithemc.osl.items.impl.ItemRegistryImpl::init"
+ ]
+ },
"mixins": [
"osl.items.mixins.json"
],
@@ -11,6 +16,13 @@
"fabricloader": "\u003e\u003d0.18.0",
"minecraft": "\u003e\u003d1.7-alpha.13.36.a \u003c\u003d1.8-alpha.14.25.b",
"osl-core": "\u003e\u003d0.9.0",
+ "osl-entrypoints": "\u003e\u003d0.5.0",
+ "osl-lifecycle-events": "\u003e\u003d0.6.0",
+ "osl-executors": "\u003e\u003d0.1.0",
+ "osl-text-components": "\u003e\u003d0.1.0-",
+ "osl-networking": "\u003e\u003d0.9.0",
+ "osl-networking-impl": "\u003e\u003d0.1.0",
+ "osl-registries": "\u003e\u003d0.1.0-",
"osl-blocks": "\u003e\u003d0.1.0"
},
"name": "OSL Items",
diff --git a/libraries/items/items-mc13w36a-mc14w25b/src/main/resources/osl.items.mixins.json b/libraries/items/items-mc13w36a-mc14w25b/src/main/resources/osl.items.mixins.json
index 23794a0f8..3eacdfb05 100644
--- a/libraries/items/items-mc13w36a-mc14w25b/src/main/resources/osl.items.mixins.json
+++ b/libraries/items/items-mc13w36a-mc14w25b/src/main/resources/osl.items.mixins.json
@@ -6,8 +6,12 @@
"plugin": "net.ornithemc.osl.items.impl.ItemsMixinPlugin",
"mixins": [
"common.BlockItemAccess",
+ "common.ItemMixin_14w21b",
+ "common.ItemMixin_14w25a",
+ "common.ItemMixin",
"common.ItemMixinNew",
- "common.ItemMixinOld"
+ "common.ItemMixinOld",
+ "common.StatsMixin"
],
"client": [
],
diff --git a/libraries/items/items-mc14w26a-mc17w46a/src/main/java/net/ornithemc/osl/items/api/ItemEvents.java b/libraries/items/items-mc14w26a-mc17w46a/src/main/java/net/ornithemc/osl/items/api/ItemEvents.java
index 4d0923b99..e4b60f8b4 100644
--- a/libraries/items/items-mc14w26a-mc17w46a/src/main/java/net/ornithemc/osl/items/api/ItemEvents.java
+++ b/libraries/items/items-mc14w26a-mc17w46a/src/main/java/net/ornithemc/osl/items/api/ItemEvents.java
@@ -22,7 +22,7 @@ public final class ItemEvents {
*