use holders
This commit is contained in:
@@ -84,6 +84,10 @@ tasks.withType(JavaCompile).configureEach {
|
|||||||
|
|
||||||
if (lljij.toBoolean()) jarJar.enable()
|
if (lljij.toBoolean()) jarJar.enable()
|
||||||
|
|
||||||
|
java {
|
||||||
|
withSourcesJar()
|
||||||
|
}
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
manifest {
|
manifest {
|
||||||
attributes([
|
attributes([
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ neogradle.subsystems.parchment.mappingsVersion=2024.06.02
|
|||||||
|
|
||||||
minecraft_version=1.21
|
minecraft_version=1.21
|
||||||
minecraft_version_range=[1.21,1.22)
|
minecraft_version_range=[1.21,1.22)
|
||||||
neo_version=21.0.19-beta
|
neo_version=21.0.30-beta
|
||||||
neo_version_range=[21.0,)
|
neo_version_range=[21.0,)
|
||||||
loader_version_range=[2,)
|
loader_version_range=[2,)
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ loader_version_range=[2,)
|
|||||||
mod_id=l2core
|
mod_id=l2core
|
||||||
mod_name=L2Core
|
mod_name=L2Core
|
||||||
mod_license=LGPL-2.1
|
mod_license=LGPL-2.1
|
||||||
mod_version=3.0.0
|
mod_version=3.0.1
|
||||||
mod_group_id=dev.xkmc
|
mod_group_id=dev.xkmc
|
||||||
mod_authors=lcy0x1
|
mod_authors=lcy0x1
|
||||||
mod_description=Core Library mod for all L2 mods
|
mod_description=Core Library mod for all L2 mods
|
||||||
|
|||||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
|
||||||
|
networkTimeout=10000
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
zipStorePath=wrapper/dists
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package dev.xkmc.l2core.base.menu.base;
|
package dev.xkmc.l2core.base.menu.base;
|
||||||
|
|
||||||
import dev.xkmc.l2serial.util.Wrappers;
|
import dev.xkmc.l2serial.util.Wrappers;
|
||||||
|
import net.minecraft.core.RegistryAccess;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.Container;
|
import net.minecraft.world.Container;
|
||||||
import net.minecraft.world.SimpleContainer;
|
import net.minecraft.world.SimpleContainer;
|
||||||
@@ -87,11 +88,14 @@ public class BaseContainerMenu<T extends BaseContainerMenu<T>> extends AbstractC
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final Inventory inventory;
|
public final Inventory inventory;
|
||||||
|
public final Player player;
|
||||||
public final Container container;
|
public final Container container;
|
||||||
public final SpriteManager sprite;
|
public final RegistryAccess access;
|
||||||
protected int added = 0;
|
protected int added = 0;
|
||||||
protected final boolean isVirtual;
|
protected final boolean isVirtual;
|
||||||
|
|
||||||
|
private final SpriteManager sprite;
|
||||||
|
|
||||||
private boolean updating = false;
|
private boolean updating = false;
|
||||||
|
|
||||||
private final Map<SlotKey, Slot> slotMap = new TreeMap<>(SlotKey.COMPARATOR);
|
private final Map<SlotKey, Slot> slotMap = new TreeMap<>(SlotKey.COMPARATOR);
|
||||||
@@ -109,14 +113,20 @@ public class BaseContainerMenu<T extends BaseContainerMenu<T>> extends AbstractC
|
|||||||
protected BaseContainerMenu(MenuType<?> type, int wid, Inventory plInv, SpriteManager manager, Function<T, SimpleContainer> factory, boolean isVirtual) {
|
protected BaseContainerMenu(MenuType<?> type, int wid, Inventory plInv, SpriteManager manager, Function<T, SimpleContainer> factory, boolean isVirtual) {
|
||||||
super(type, wid);
|
super(type, wid);
|
||||||
this.inventory = plInv;
|
this.inventory = plInv;
|
||||||
|
this.player = plInv.player;
|
||||||
container = factory.apply(Wrappers.cast(this));
|
container = factory.apply(Wrappers.cast(this));
|
||||||
sprite = manager;
|
sprite = manager;
|
||||||
int x = manager.get().getPlInvX();
|
access = plInv.player.level().registryAccess();
|
||||||
int y = manager.get().getPlInvY();
|
int x = getLayout().getPlInvX();
|
||||||
|
int y = getLayout().getPlInvY();
|
||||||
this.bindPlayerInventory(plInv, x, y);
|
this.bindPlayerInventory(plInv, x, y);
|
||||||
this.isVirtual = isVirtual;
|
this.isVirtual = isVirtual;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MenuLayoutConfig getLayout() {
|
||||||
|
return sprite.get(access);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Binds player inventory. Should not be called by others, but permits override.
|
* Binds player inventory. Should not be called by others, but permits override.
|
||||||
*/
|
*/
|
||||||
@@ -146,7 +156,7 @@ public class BaseContainerMenu<T extends BaseContainerMenu<T>> extends AbstractC
|
|||||||
* Add new slots, with item input predicate
|
* Add new slots, with item input predicate
|
||||||
*/
|
*/
|
||||||
protected void addSlot(String name, Predicate<ItemStack> pred) {
|
protected void addSlot(String name, Predicate<ItemStack> pred) {
|
||||||
sprite.get().getSlot(name, (x, y) -> new PredSlot(container, added++, x, y, pred), this::addSlot);
|
getLayout().getSlot(name, (x, y) -> new PredSlot(container, added++, x, y, pred), this::addSlot);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -155,7 +165,7 @@ public class BaseContainerMenu<T extends BaseContainerMenu<T>> extends AbstractC
|
|||||||
*/
|
*/
|
||||||
protected void addSlot(String name, BiPredicate<Integer, ItemStack> pred) {
|
protected void addSlot(String name, BiPredicate<Integer, ItemStack> pred) {
|
||||||
int current = added;
|
int current = added;
|
||||||
sprite.get().getSlot(name, (x, y) -> {
|
getLayout().getSlot(name, (x, y) -> {
|
||||||
int i = added - current;
|
int i = added - current;
|
||||||
var ans = new PredSlot(container, added, x, y, e -> pred.test(i, e));
|
var ans = new PredSlot(container, added, x, y, e -> pred.test(i, e));
|
||||||
added++;
|
added++;
|
||||||
@@ -167,7 +177,7 @@ public class BaseContainerMenu<T extends BaseContainerMenu<T>> extends AbstractC
|
|||||||
* Add new slots, with other modifications to the slot.
|
* Add new slots, with other modifications to the slot.
|
||||||
*/
|
*/
|
||||||
protected void addSlot(String name, Predicate<ItemStack> pred, Consumer<PredSlot> modifier) {
|
protected void addSlot(String name, Predicate<ItemStack> pred, Consumer<PredSlot> modifier) {
|
||||||
sprite.get().getSlot(name, (x, y) -> {
|
getLayout().getSlot(name, (x, y) -> {
|
||||||
PredSlot s = new PredSlot(container, added++, x, y, pred);
|
PredSlot s = new PredSlot(container, added++, x, y, pred);
|
||||||
modifier.accept(s);
|
modifier.accept(s);
|
||||||
return s;
|
return s;
|
||||||
@@ -180,7 +190,7 @@ public class BaseContainerMenu<T extends BaseContainerMenu<T>> extends AbstractC
|
|||||||
*/
|
*/
|
||||||
protected void addSlot(String name, BiPredicate<Integer, ItemStack> pred, BiConsumer<Integer, PredSlot> modifier) {
|
protected void addSlot(String name, BiPredicate<Integer, ItemStack> pred, BiConsumer<Integer, PredSlot> modifier) {
|
||||||
int current = added;
|
int current = added;
|
||||||
sprite.get().getSlot(name, (x, y) -> {
|
getLayout().getSlot(name, (x, y) -> {
|
||||||
int i = added - current;
|
int i = added - current;
|
||||||
var ans = new PredSlot(container, added, x, y, e -> pred.test(i, e));
|
var ans = new PredSlot(container, added, x, y, e -> pred.test(i, e));
|
||||||
modifier.accept(i, ans);
|
modifier.accept(i, ans);
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package dev.xkmc.l2core.base.menu.base;
|
package dev.xkmc.l2core.base.menu.base;
|
||||||
|
|
||||||
import dev.xkmc.l2core.util.Proxy;
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||||
@@ -11,8 +10,8 @@ public abstract class BaseContainerScreen<T extends BaseContainerMenu<T>> extend
|
|||||||
|
|
||||||
public BaseContainerScreen(T cont, Inventory plInv, Component title) {
|
public BaseContainerScreen(T cont, Inventory plInv, Component title) {
|
||||||
super(cont, plInv, title);
|
super(cont, plInv, title);
|
||||||
this.imageHeight = menu.sprite.get().getHeight();
|
this.imageHeight = menu.getLayout().getHeight();
|
||||||
this.inventoryLabelY = menu.sprite.get().getPlInvY() - 11;
|
this.inventoryLabelY = menu.getLayout().getPlInvY() - 11;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -22,7 +21,7 @@ public abstract class BaseContainerScreen<T extends BaseContainerMenu<T>> extend
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected boolean click(int btn) {
|
protected boolean click(int btn) {
|
||||||
if (menu.clickMenuButton(Proxy.getClientPlayer(), btn) && Minecraft.getInstance().gameMode != null) {
|
if (menu.clickMenuButton(menu.player, btn) && Minecraft.getInstance().gameMode != null) {
|
||||||
Minecraft.getInstance().gameMode.handleInventoryButtonClick(this.menu.containerId, btn);
|
Minecraft.getInstance().gameMode.handleInventoryButtonClick(this.menu.containerId, btn);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package dev.xkmc.l2core.base.menu.base;
|
package dev.xkmc.l2core.base.menu.base;
|
||||||
|
|
||||||
import dev.xkmc.l2core.init.L2LibReg;
|
import dev.xkmc.l2core.init.L2LibReg;
|
||||||
|
import net.minecraft.core.RegistryAccess;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
public record SpriteManager(ResourceLocation id) {
|
public record SpriteManager(ResourceLocation id) {
|
||||||
@@ -9,8 +10,8 @@ public record SpriteManager(ResourceLocation id) {
|
|||||||
this(ResourceLocation.fromNamespaceAndPath(modid, path));
|
this(ResourceLocation.fromNamespaceAndPath(modid, path));
|
||||||
}
|
}
|
||||||
|
|
||||||
public MenuLayoutConfig get() {
|
public MenuLayoutConfig get(RegistryAccess access) {
|
||||||
return L2LibReg.MENU_LAYOUT.get(id);
|
return L2LibReg.MENU_LAYOUT.get(access, id).value();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +1,34 @@
|
|||||||
package dev.xkmc.l2core.init.reg.datapack;
|
package dev.xkmc.l2core.init.reg.datapack;
|
||||||
|
|
||||||
import com.mojang.datafixers.util.Pair;
|
import com.mojang.datafixers.util.Pair;
|
||||||
import dev.xkmc.l2core.util.Proxy;
|
import net.minecraft.core.Holder;
|
||||||
|
import net.minecraft.core.RegistryAccess;
|
||||||
import net.neoforged.neoforge.registries.datamaps.DataMapType;
|
import net.neoforged.neoforge.registries.datamaps.DataMapType;
|
||||||
import net.neoforged.neoforge.registries.datamaps.RegisterDataMapTypesEvent;
|
import net.neoforged.neoforge.registries.datamaps.RegisterDataMapTypesEvent;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public record DataMapReg<K, V>(DataMapType<K, V> reg) implements ValSet<K, V> {
|
public record DataMapReg<K, V>(DataMapType<K, V> reg) {
|
||||||
|
|
||||||
public void register(final RegisterDataMapTypesEvent event) {
|
public void register(final RegisterDataMapTypesEvent event) {
|
||||||
event.register(reg);
|
event.register(reg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public V get(K key) {
|
public V get(RegistryAccess access, Holder<K> key) {
|
||||||
var registry = Proxy.getRegistryAccess().registry(reg.registryKey()).get();
|
var registry = access.registry(reg.registryKey());
|
||||||
return registry.getData(reg, registry.getResourceKey(key).get());
|
if (registry.isEmpty()) return null;
|
||||||
|
var id = key.unwrapKey();
|
||||||
|
if (id.isEmpty()) return null;
|
||||||
|
return registry.get().getData(reg, id.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stream<Pair<K, V>> getAll() {
|
public Stream<Pair<Holder<K>, V>> getAll(RegistryAccess access) {
|
||||||
var registry = Proxy.getRegistryAccess().registry(reg.registryKey()).get();
|
var registry = access.registry(reg.registryKey());
|
||||||
return registry.getDataMap(reg).entrySet().stream()
|
if (registry.isEmpty()) return Stream.empty();
|
||||||
.map(e -> Pair.of(registry.get(e.getKey()), e.getValue()));
|
return registry.get().getDataMap(reg).entrySet().stream()
|
||||||
|
.map(e -> Pair.of(registry.get().getHolderOrThrow(e.getKey()), e.getValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +1,33 @@
|
|||||||
package dev.xkmc.l2core.init.reg.datapack;
|
package dev.xkmc.l2core.init.reg.datapack;
|
||||||
|
|
||||||
import com.mojang.datafixers.util.Pair;
|
|
||||||
import com.mojang.serialization.Codec;
|
import com.mojang.serialization.Codec;
|
||||||
import dev.xkmc.l2core.util.Proxy;
|
import net.minecraft.core.Holder;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
|
import net.minecraft.core.RegistryAccess;
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.neoforged.neoforge.registries.DataPackRegistryEvent;
|
import net.neoforged.neoforge.registries.DataPackRegistryEvent;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public record DatapackReg<T>(ResourceKey<Registry<T>> key, Codec<T> codec) implements ValSet<ResourceLocation, T> {
|
public record DatapackReg<T>(ResourceKey<Registry<T>> key, Codec<T> codec) {
|
||||||
|
|
||||||
public void onRegister(DataPackRegistryEvent.NewRegistry event) {
|
public void onRegister(DataPackRegistryEvent.NewRegistry event) {
|
||||||
event.dataPackRegistry(key, codec, codec);
|
event.dataPackRegistry(key, codec, codec);
|
||||||
}
|
}
|
||||||
|
|
||||||
public T get(ResourceLocation id) {
|
@Nullable
|
||||||
return Proxy.getRegistryAccess().registry(key).get().get(id);
|
public Holder<T> get(RegistryAccess access, ResourceLocation id) {
|
||||||
|
var reg = access.registry(key);
|
||||||
|
if (reg.isEmpty()) return null;
|
||||||
|
return reg.get().getHolder(id).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stream<Pair<ResourceLocation, T>> getAll() {
|
public Stream<Holder<T>> getAll(RegistryAccess access) {
|
||||||
return Proxy.getRegistryAccess().registry(key).get().entrySet()
|
var reg = access.registry(key);
|
||||||
.stream().map(e -> Pair.of(e.getKey().location(), e.getValue()));
|
if (reg.isEmpty()) return Stream.empty();
|
||||||
|
return reg.get().holders().map(e -> e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
package dev.xkmc.l2core.init.reg.datapack;
|
|
||||||
|
|
||||||
import com.mojang.datafixers.util.Pair;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
public interface ValSet<K, V> {
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
V get(K k);
|
|
||||||
|
|
||||||
Stream<Pair<K, V>> getAll();
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -13,6 +13,7 @@ import java.util.Optional;
|
|||||||
|
|
||||||
public class Proxy {
|
public class Proxy {
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public static RegistryAccess getRegistryAccess() {
|
public static RegistryAccess getRegistryAccess() {
|
||||||
if (FMLEnvironment.dist == Dist.CLIENT) {
|
if (FMLEnvironment.dist == Dist.CLIENT) {
|
||||||
return Minecraft.getInstance().level.registryAccess();
|
return Minecraft.getInstance().level.registryAccess();
|
||||||
|
|||||||
Reference in New Issue
Block a user