Multiloader VII

cleanup registration api
This commit is contained in:
techno-sam
2026-04-17 00:03:13 +02:00
parent 212fcbfad3
commit 808a80d9f4
4 changed files with 6 additions and 20 deletions
@@ -8,7 +8,7 @@ public class RegistrationListeners<T> {
private @Nullable T obj;
private @Nullable Consumer<T> cons;
public void registered(T obj) {
public synchronized void registered(T obj) {
this.obj = obj;
if (cons != null) {
cons.accept(obj);
@@ -16,7 +16,7 @@ public class RegistrationListeners<T> {
}
}
public void addListener(Consumer<? super T> consumer) {
public synchronized void addListener(Consumer<? super T> consumer) {
if (obj != null) {
consumer.accept(obj);
} else if (cons == null) {
@@ -5,7 +5,7 @@ import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
public class BlockHolder<T extends Block> extends ItemLikeHolder.NonItem<T> {
public class BlockHolder<T extends Block> extends ItemLikeHolder<T> {
public BlockHolder(HolderOwner<T> owner, ResourceKey<T> key) {
super(owner, key);
}
@@ -8,9 +8,4 @@ public class ItemHolder<T extends Item> extends ItemLikeHolder<T> {
public ItemHolder(HolderOwner<T> owner, ResourceKey<T> key) {
super(owner, key);
}
@Override
public boolean is(Item item) {
return asItem() == item;
}
}
@@ -23,21 +23,12 @@ abstract class ItemLikeHolder<T extends ItemLike> extends BaseHolder<T> implemen
return is(stack.getItem());
}
public abstract boolean is(Item item);
public boolean is(Item item) {
return asItem() == item;
}
@Override
public Item asItem() {
return value().asItem();
}
static class NonItem<T extends ItemLike> extends ItemLikeHolder<T> {
protected NonItem(HolderOwner<T> owner, ResourceKey<T> key) {
super(owner, key);
}
@Override
public boolean is(Item item) {
return asItem() == item;
}
}
}