ItemAdder link

This commit is contained in:
Vatuu 2022-05-13 23:25:27 +02:00
parent b8b9d7bf8c
commit 192538a741
No known key found for this signature in database
GPG Key ID: C6F07B79B2ED9150
6 changed files with 63 additions and 49 deletions

View File

@ -76,6 +76,7 @@ repositories {
maven { url "https://dl.cloudsmith.io/public/arcane/archive/maven/" }
mavenCentral()
mavenLocal()
maven { url "https://jitpack.io"}
}
/**
@ -126,6 +127,7 @@ dependencies {
implementation 'me.clip:placeholderapi:2.11.1'
implementation 'io.th0rgal:oraxen:1.94.0'
implementation 'org.bukkit:craftbukkit:1.18.2-R0.1-SNAPSHOT:remapped-mojang'
implementation 'com.github.LoneDev6:api-itemsadder:3.1.0b'
// Shaded
implementation 'com.dfsek:Paralithic:0.4.0'

View File

@ -1,9 +1,9 @@
package com.volmit.iris.core.link;
import com.volmit.iris.util.collection.KList;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.block.data.BlockData;
import org.bukkit.plugin.Plugin;
@ -13,7 +13,7 @@ import java.util.MissingResourceException;
public abstract class BlockDataProvider {
@Getter
private final String pluginId, identifierPrefix;
private final String pluginId;
public Plugin getPlugin() {
return Bukkit.getPluginManager().getPlugin(pluginId);
@ -23,13 +23,9 @@ public abstract class BlockDataProvider {
return getPlugin() != null;
}
public abstract BlockData getBlockData(String blockId) throws MissingResourceException;
public abstract BlockData getBlockData(NamespacedKey blockId) throws MissingResourceException;
public String[] getBlockIdentifiers() {
KList<String> names = new KList<>(getBlockTypes());
names.rewrite(s -> identifierPrefix + ":" + s);
return names.toArray(new String[0]);
}
public abstract NamespacedKey[] getBlockTypes();
public abstract String[] getBlockTypes();
public abstract boolean isProviderBlock(NamespacedKey namespace);
}

View File

@ -1,5 +1,9 @@
package com.volmit.iris.core.link;
import com.volmit.iris.util.collection.KList;
import dev.lone.itemsadder.api.CustomBlock;
import dev.lone.itemsadder.api.ItemsAdder;
import org.bukkit.NamespacedKey;
import org.bukkit.block.data.BlockData;
import java.util.MissingResourceException;
@ -7,16 +11,28 @@ import java.util.MissingResourceException;
public class ItemAdderLink extends BlockDataProvider {
public ItemAdderLink() {
super("ItemAdder", "itemadder");
super("ItemsAdder");
}
@Override
public BlockData getBlockData(String blockId) throws MissingResourceException {
throw new MissingResourceException("Fuck you, not implemented yet.", getPluginId(), blockId);
public BlockData getBlockData(NamespacedKey blockId) throws MissingResourceException {
return CustomBlock.getBaseBlockData(blockId.toString());
}
@Override
public String[] getBlockTypes() {
return new String[0];
public NamespacedKey[] getBlockTypes() {
KList<NamespacedKey> keys = new KList<>();
for(String s : ItemsAdder.getNamespacedBlocksNamesInConfig())
keys.add(NamespacedKey.fromString(s));
return keys.toArray(new NamespacedKey[0]);
}
@Override
public boolean isProviderBlock(NamespacedKey blockId) {
for(NamespacedKey k : getBlockTypes())
if(k.equals(blockId)) {
return true;
}
return false;
}
}

View File

@ -29,6 +29,7 @@ import io.th0rgal.oraxen.mechanics.provided.gameplay.noteblock.NoteBlockMechanic
import io.th0rgal.oraxen.utils.Utils;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.MultipleFacing;
@ -43,7 +44,7 @@ public class OraxenDataProvider extends BlockDataProvider {
private Map<String, MechanicFactory> factories;
public OraxenDataProvider() {
super("Oraxen", "oraxen");
super("Oraxen");
try {
Field f = MechanicsManager.class.getDeclaredField(FIELD_FACTORIES_MAP);
@ -56,29 +57,30 @@ public class OraxenDataProvider extends BlockDataProvider {
}
@Override
public BlockData getBlockData(String blockId) throws MissingResourceException {
public BlockData getBlockData(NamespacedKey blockId) throws MissingResourceException {
MechanicFactory f = getFactory(blockId);
if(f instanceof NoteBlockMechanicFactory)
return ((NoteBlockMechanicFactory)f).createNoteBlockData(blockId);
return ((NoteBlockMechanicFactory)f).createNoteBlockData(blockId.getKey());
else if(f instanceof BlockMechanicFactory) {
MultipleFacing newBlockData = (MultipleFacing) Bukkit.createBlockData(Material.MUSHROOM_STEM);
Utils.setBlockFacing(newBlockData, ((BlockMechanic)f.getMechanic(blockId)).getCustomVariation());
Utils.setBlockFacing(newBlockData, ((BlockMechanic)f.getMechanic(blockId.getKey())).getCustomVariation());
return newBlockData;
} else
throw new MissingResourceException("Failed to find BlockData!", getIdentifierPrefix(), blockId);
throw new MissingResourceException("Failed to find BlockData!", blockId.getNamespace(), blockId.getKey());
}
@Override
public String[] getBlockTypes() {
KList<String> names = new KList<>();
public NamespacedKey[] getBlockTypes() {
KList<NamespacedKey> names = new KList<>();
for(String name : OraxenItems.getItemNames()) {
try {
if(getBlockData(name) != null)
names.add(name);
NamespacedKey key = new NamespacedKey("oraxen", name);
if(getBlockData(key) != null)
names.add(key);
} catch(MissingResourceException ignored) { }
}
return names.toArray(new String[0]);
return names.toArray(new NamespacedKey[0]);
}
@Override
@ -86,10 +88,15 @@ public class OraxenDataProvider extends BlockDataProvider {
return super.isPresent() && factories != null;
}
private MechanicFactory getFactory(String blockId) throws MissingResourceException {
@Override
public boolean isProviderBlock(NamespacedKey key) {
return key.getNamespace().equalsIgnoreCase("oraxen");
}
private MechanicFactory getFactory(NamespacedKey key) throws MissingResourceException {
return factories.values().stream()
.filter(i -> i.getItems().contains(blockId))
.filter(i -> i.getItems().contains(key.getKey()))
.findFirst()
.orElseThrow(() -> new MissingResourceException("Failed to find BlockData!", getPluginId(), blockId));
.orElseThrow(() -> new MissingResourceException("Failed to find BlockData!", key.getNamespace(), key.getKey()));
}
}

View File

@ -25,6 +25,7 @@ import com.volmit.iris.core.link.OraxenDataProvider;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.plugin.IrisService;
import lombok.Data;
import org.bukkit.NamespacedKey;
import org.bukkit.block.data.BlockData;
import java.util.MissingResourceException;
@ -47,8 +48,8 @@ public class CustomBlockDataSVC implements IrisService {
providers.add(provider);
}
public Optional<BlockData> getBlockData(String namespace, String key) {
Optional<BlockDataProvider> provider = providers.stream().filter(p -> p.isPresent() && p.getIdentifierPrefix().equalsIgnoreCase(namespace)).findFirst();
public Optional<BlockData> getBlockData(NamespacedKey key) {
Optional<BlockDataProvider> provider = providers.stream().filter(p -> p.isPresent() && p.isProviderBlock(key)).findFirst();
if(provider.isEmpty())
return Optional.empty();
try {
@ -59,9 +60,9 @@ public class CustomBlockDataSVC implements IrisService {
}
}
public String[] getAllIdentifiers() {
KList<String> names = new KList<>();
providers.forEach(p -> names.add(p.getBlockIdentifiers()));
return names.toArray(new String[0]);
public NamespacedKey[] getAllIdentifiers() {
KList<NamespacedKey> names = new KList<>();
providers.forEach(p -> names.add(p.getBlockTypes()));
return names.toArray(new NamespacedKey[0]);
}
}

View File

@ -31,6 +31,7 @@ import it.unimi.dsi.fastutil.ints.IntSet;
import it.unimi.dsi.fastutil.ints.IntSets;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Waterlogged;
import org.bukkit.block.data.type.Leaves;
@ -469,21 +470,11 @@ public class B {
try {
BlockData bx = null;
if(!ix.startsWith("minecraft:")) {
try {
if(ix.contains(":")) {
String[] id = ix.toLowerCase().split("\\Q:\\E");
Optional<BlockData> bd = Iris.service(CustomBlockDataSVC.class).getBlockData(id[0], id[1]);
if(bd.isPresent()) {
bx = bd.get();
} else {
/*Supplier<BlockData> sup = Iris.service(RegistrySVC.class).getCustomBlockRegistry().resolve(id[0], id[1]);
bx = sup == null ? null : sup.get();*/
}
}
} catch(Throwable e) {
e.printStackTrace();// TODO: REMOVE
}
if(!ix.startsWith("minecraft:") && ix.contains(":")) {
NamespacedKey key = NamespacedKey.fromString(ix);
Optional<BlockData> bd = Iris.service(CustomBlockDataSVC.class).getBlockData(key);
if(bd.isPresent())
bx = bd.get();
}
if(bx == null) {
@ -656,7 +647,8 @@ public class B {
}
}
bt.add(Iris.service(CustomBlockDataSVC.class).getAllIdentifiers());
for(NamespacedKey id : Iris.service(CustomBlockDataSVC.class).getAllIdentifiers())
bt.add(id.toString());
bt.addAll(custom.k());
return bt.toArray(new String[0]);