remove direct registry calls from common module
This commit is contained in:
parent
5c95c9aed2
commit
4cf3d7f7be
@ -1,7 +1,9 @@
|
||||
package io.github.flemmli97.flan;
|
||||
|
||||
import me.shedaniel.architectury.annotations.ExpectPlatform;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.effect.StatusEffect;
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
@ -13,12 +15,17 @@ public class CrossPlatformStuff {
|
||||
}
|
||||
|
||||
@ExpectPlatform
|
||||
public static StatusEffect effectFromString(String s) {
|
||||
public static SimpleRegistryWrapper<StatusEffect> registryStatusEffects() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@ExpectPlatform
|
||||
public static String stringFromEffect(StatusEffect s) {
|
||||
public static SimpleRegistryWrapper<Block> registryBlocks() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@ExpectPlatform
|
||||
public static SimpleRegistryWrapper<Item> registryItems() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,15 @@
|
||||
package io.github.flemmli97.flan;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
/**
|
||||
* Simple structure to get stuff from registries
|
||||
*/
|
||||
public interface SimpleRegistryWrapper<T> {
|
||||
|
||||
T getFromId(Identifier id);
|
||||
|
||||
Identifier getIDFrom(T entry);
|
||||
|
||||
Iterable<T> getIterator();
|
||||
}
|
@ -22,6 +22,7 @@ import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.world.Heightmap;
|
||||
@ -528,7 +529,7 @@ public class Claim implements IPermissionContainer {
|
||||
this.homePos = new BlockPos(home.get(0).getAsInt(), home.get(1).getAsInt(), home.get(2).getAsInt());
|
||||
}
|
||||
JsonObject potion = ConfigHandler.fromJson(obj, "Potions");
|
||||
potion.entrySet().forEach(e -> this.potions.put(CrossPlatformStuff.effectFromString(e.getKey()), e.getValue().getAsInt()));
|
||||
potion.entrySet().forEach(e -> this.potions.put(CrossPlatformStuff.registryStatusEffects().getFromId(new Identifier(e.getKey())), e.getValue().getAsInt()));
|
||||
if (ConfigHandler.fromJson(obj, "AdminClaim", false))
|
||||
this.owner = null;
|
||||
else
|
||||
@ -594,7 +595,7 @@ public class Claim implements IPermissionContainer {
|
||||
home.add(this.homePos.getZ());
|
||||
obj.add("Home", home);
|
||||
JsonObject potions = new JsonObject();
|
||||
this.potions.forEach((effect, amp) -> potions.addProperty(CrossPlatformStuff.stringFromEffect(effect), amp));
|
||||
this.potions.forEach((effect, amp) -> potions.addProperty(CrossPlatformStuff.registryStatusEffects().getIDFrom(effect).toString(), amp));
|
||||
obj.add("Potions", potions);
|
||||
if (this.parent != null)
|
||||
obj.addProperty("Parent", this.parent.toString());
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.github.flemmli97.flan.claim;
|
||||
|
||||
import io.github.flemmli97.flan.CrossPlatformStuff;
|
||||
import io.github.flemmli97.flan.api.ClaimPermission;
|
||||
import io.github.flemmli97.flan.api.PermissionRegistry;
|
||||
import net.minecraft.block.AbstractButtonBlock;
|
||||
@ -32,7 +33,6 @@ import net.minecraft.item.EnderPearlItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -50,10 +50,10 @@ public class ObjectToPermissionMap {
|
||||
public static void reload(MinecraftServer server) {
|
||||
blockToPermission.clear();
|
||||
itemToPermission.clear();
|
||||
for (Block block : Registry.BLOCK) {
|
||||
for (Block block : CrossPlatformStuff.registryBlocks().getIterator()) {
|
||||
blockPermissionBuilder.entrySet().stream().filter(e -> e.getKey().test(block)).map(Map.Entry::getValue).findFirst().ifPresent(sub -> blockToPermission.put(block, sub.get()));
|
||||
}
|
||||
for (Item item : Registry.ITEM) {
|
||||
for (Item item : CrossPlatformStuff.registryItems().getIterator()) {
|
||||
itemPermissionBuilder.entrySet().stream().filter(e -> e.getKey().test(item)).map(Map.Entry::getValue).findFirst().ifPresent(sub -> itemToPermission.put(item, sub.get()));
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import net.minecraft.item.Items;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
@ -131,9 +130,9 @@ public class Config {
|
||||
this.blacklistedWorlds[i] = arr.get(i).getAsString();
|
||||
this.worldWhitelist = ConfigHandler.fromJson(obj, "worldWhitelist", this.worldWhitelist);
|
||||
if (obj.has("claimingItem"))
|
||||
this.claimingItem = Registry.ITEM.get(new Identifier((obj.get("claimingItem").getAsString())));
|
||||
this.claimingItem = CrossPlatformStuff.registryItems().getFromId(new Identifier((obj.get("claimingItem").getAsString())));
|
||||
if (obj.has("inspectionItem"))
|
||||
this.inspectionItem = Registry.ITEM.get(new Identifier((obj.get("inspectionItem").getAsString())));
|
||||
this.inspectionItem = CrossPlatformStuff.registryItems().getFromId(new Identifier((obj.get("inspectionItem").getAsString())));
|
||||
this.claimDisplayTime = ConfigHandler.fromJson(obj, "claimDisplayTime", this.claimDisplayTime);
|
||||
this.defaultGroups.clear();
|
||||
JsonObject defP = ConfigHandler.fromJson(obj, "defaultGroups");
|
||||
@ -208,8 +207,8 @@ public class Config {
|
||||
arr.add(blacklistedWorld);
|
||||
obj.add("blacklistedWorlds", arr);
|
||||
obj.addProperty("worldWhitelist", this.worldWhitelist);
|
||||
obj.addProperty("claimingItem", Registry.ITEM.getId(this.claimingItem).toString());
|
||||
obj.addProperty("inspectionItem", Registry.ITEM.getId(this.inspectionItem).toString());
|
||||
obj.addProperty("claimingItem", CrossPlatformStuff.registryItems().getIDFrom(this.claimingItem).toString());
|
||||
obj.addProperty("inspectionItem", CrossPlatformStuff.registryItems().getIDFrom(this.inspectionItem).toString());
|
||||
obj.addProperty("claimDisplayTime", this.claimDisplayTime);
|
||||
obj.addProperty("permissionLevel", this.permissionLevel);
|
||||
JsonObject defPerm = new JsonObject();
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.github.flemmli97.flan.event;
|
||||
|
||||
import io.github.flemmli97.flan.CrossPlatformStuff;
|
||||
import io.github.flemmli97.flan.api.ClaimPermission;
|
||||
import io.github.flemmli97.flan.api.PermissionRegistry;
|
||||
import io.github.flemmli97.flan.claim.ClaimStorage;
|
||||
@ -32,7 +33,6 @@ import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BlockInteractEvents {
|
||||
@ -48,7 +48,7 @@ public class BlockInteractEvents {
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
||||
if (claim != null) {
|
||||
Identifier id = Registry.BLOCK.getId(state.getBlock());
|
||||
Identifier id = CrossPlatformStuff.registryBlocks().getIDFrom(state.getBlock());
|
||||
if (alwaysAllowBlock(id, world.getBlockEntity(pos)))
|
||||
return true;
|
||||
if (!claim.canInteract(player, PermissionRegistry.BREAK, pos, true)) {
|
||||
@ -80,7 +80,7 @@ public class BlockInteractEvents {
|
||||
boolean cancelBlockInteract = player.shouldCancelInteraction() && emptyHand;
|
||||
if (!cancelBlockInteract) {
|
||||
BlockState state = world.getBlockState(hitResult.getBlockPos());
|
||||
Identifier id = Registry.BLOCK.getId(state.getBlock());
|
||||
Identifier id = CrossPlatformStuff.registryBlocks().getIDFrom(state.getBlock());
|
||||
BlockEntity blockEntity = world.getBlockEntity(hitResult.getBlockPos());
|
||||
if (alwaysAllowBlock(id, blockEntity))
|
||||
return ActionResult.PASS;
|
||||
|
@ -21,6 +21,7 @@ import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@ -58,7 +59,7 @@ public class PotionEditScreenHandler extends ServerOnlyScreenHandler<Claim> {
|
||||
protected void fillInventoryWith(PlayerEntity player, Inventory inv, Claim claim) {
|
||||
Map<StatusEffect, Integer> potions = claim.getPotions();
|
||||
List<StatusEffect> key = Lists.newArrayList(potions.keySet());
|
||||
key.sort(Comparator.comparing(CrossPlatformStuff::stringFromEffect));
|
||||
key.sort(Comparator.comparing(eff -> CrossPlatformStuff.registryStatusEffects().getIDFrom(eff).toString()));
|
||||
for (int i = 0; i < 54; i++) {
|
||||
if (i == 0) {
|
||||
ItemStack close = new ItemStack(Items.TNT);
|
||||
@ -82,7 +83,7 @@ public class PotionEditScreenHandler extends ServerOnlyScreenHandler<Claim> {
|
||||
ItemStack effectStack = new ItemStack(Items.POTION);
|
||||
TranslatableText txt = new TranslatableText(effect.getTranslationKey());
|
||||
Collection<StatusEffectInstance> inst = Collections.singleton(new StatusEffectInstance(effect, 0, potions.get(effect)));
|
||||
effectStack.getOrCreateTag().putString("FlanEffect", CrossPlatformStuff.stringFromEffect(effect));
|
||||
effectStack.getOrCreateTag().putString("FlanEffect", CrossPlatformStuff.registryStatusEffects().getIDFrom(effect).toString());
|
||||
effectStack.getTag().putInt("CustomPotionColor", PotionUtil.getColor(inst));
|
||||
effectStack.setCustomName(txt.setStyle(txt.getStyle().withItalic(false).withFormatting(Formatting.DARK_BLUE)).append(ServerScreenHelper.coloredGuiText("-" + potions.get(effect), Formatting.DARK_BLUE)));
|
||||
inv.setStack(i, effectStack);
|
||||
@ -109,7 +110,7 @@ public class PotionEditScreenHandler extends ServerOnlyScreenHandler<Claim> {
|
||||
player.getServer().execute(() -> StringResultScreenHandler.createNewStringResult(player, (s) -> {
|
||||
String[] potion = s.split(";");
|
||||
int amp = 1;
|
||||
StatusEffect effect = CrossPlatformStuff.effectFromString(potion[0]);
|
||||
StatusEffect effect = CrossPlatformStuff.registryStatusEffects().getFromId(new Identifier(potion[0]));
|
||||
if (effect == null || (effect == StatusEffects.LUCK && !potion[0].equals("minecraft:luck"))) {
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.ENTITY_VILLAGER_NO, 1, 1f);
|
||||
return;
|
||||
@ -143,7 +144,7 @@ public class PotionEditScreenHandler extends ServerOnlyScreenHandler<Claim> {
|
||||
ItemStack stack = slot.getStack();
|
||||
if (!stack.isEmpty() && this.removeMode) {
|
||||
String effect = stack.getOrCreateTag().getString("FlanEffect");
|
||||
this.claim.removePotion(CrossPlatformStuff.effectFromString(effect));
|
||||
this.claim.removePotion(CrossPlatformStuff.registryStatusEffects().getFromId(new Identifier(effect)));
|
||||
slot.setStack(ItemStack.EMPTY);
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.ENTITY_BAT_DEATH, 1, 1f);
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
package io.github.flemmli97.flan;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
public class FabricRegistryWrapper<T> implements SimpleRegistryWrapper<T> {
|
||||
|
||||
private final Registry<T> delegate;
|
||||
|
||||
public FabricRegistryWrapper(Registry<T> delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getFromId(Identifier id) {
|
||||
return this.delegate.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Identifier getIDFrom(T entry) {
|
||||
return this.delegate.getId(entry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<T> getIterator() {
|
||||
return this.delegate;
|
||||
}
|
||||
}
|
@ -1,7 +1,11 @@
|
||||
package io.github.flemmli97.flan.fabric;
|
||||
|
||||
import io.github.flemmli97.flan.FabricRegistryWrapper;
|
||||
import io.github.flemmli97.flan.SimpleRegistryWrapper;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.effect.StatusEffect;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
@ -20,4 +24,16 @@ public class CrossPlatformStuffImpl {
|
||||
public static String stringFromEffect(StatusEffect s) {
|
||||
return Registry.STATUS_EFFECT.getId(s).toString();
|
||||
}
|
||||
|
||||
public static SimpleRegistryWrapper<StatusEffect> registryStatusEffects() {
|
||||
return new FabricRegistryWrapper<>(Registry.STATUS_EFFECT);
|
||||
}
|
||||
|
||||
public static SimpleRegistryWrapper<Block> registryBlocks() {
|
||||
return new FabricRegistryWrapper<>(Registry.BLOCK);
|
||||
}
|
||||
|
||||
public static SimpleRegistryWrapper<Item> registryItems() {
|
||||
return new FabricRegistryWrapper<>(Registry.ITEM);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
package io.github.flemmli97.flan;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
|
||||
public class ForgeRegistryWrapper<T extends IForgeRegistryEntry<T>> implements SimpleRegistryWrapper<T> {
|
||||
|
||||
private final IForgeRegistry<T> registry;
|
||||
|
||||
public ForgeRegistryWrapper(IForgeRegistry<T> registry) {
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getFromId(Identifier id) {
|
||||
return this.registry.getValue(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Identifier getIDFrom(T entry) {
|
||||
return entry.getRegistryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<T> getIterator() {
|
||||
return this.registry;
|
||||
}
|
||||
}
|
@ -1,7 +1,10 @@
|
||||
package io.github.flemmli97.flan.forge;
|
||||
|
||||
import io.github.flemmli97.flan.ForgeRegistryWrapper;
|
||||
import io.github.flemmli97.flan.SimpleRegistryWrapper;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.effect.StatusEffect;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.fml.loading.FMLPaths;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
@ -13,11 +16,15 @@ public class CrossPlatformStuffImpl {
|
||||
return FMLPaths.CONFIGDIR.get();
|
||||
}
|
||||
|
||||
public static StatusEffect effectFromString(String s) {
|
||||
return ForgeRegistries.POTIONS.getValue(new Identifier(s));
|
||||
public static SimpleRegistryWrapper<StatusEffect> registryStatusEffects() {
|
||||
return new ForgeRegistryWrapper<>(ForgeRegistries.POTIONS);
|
||||
}
|
||||
|
||||
public static String stringFromEffect(StatusEffect s) {
|
||||
return s.getRegistryName().toString();
|
||||
public static SimpleRegistryWrapper<Block> registryBlocks() {
|
||||
return new ForgeRegistryWrapper<>(ForgeRegistries.BLOCKS);
|
||||
}
|
||||
|
||||
public static SimpleRegistryWrapper<Item> registryItems() {
|
||||
return new ForgeRegistryWrapper<>(ForgeRegistries.ITEMS);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user