Update to 1.18

Rewrite command builders
Usercontent api v2
This commit is contained in:
Marcel Konrad
2021-12-02 12:45:25 +01:00
parent 915ce2cad2
commit 7951c13bc5
153 changed files with 1821 additions and 8360 deletions

View File

@@ -2,13 +2,11 @@ package exopandora.worldhandler.util;
import exopandora.worldhandler.Main;
import exopandora.worldhandler.WorldHandler;
import exopandora.worldhandler.builder.impl.BuilderDifficulty;
import exopandora.worldhandler.builder.impl.BuilderGamemode;
import exopandora.worldhandler.builder.impl.BuilderGamemode.EnumGamemode;
import exopandora.worldhandler.builder.impl.BuilderTime;
import exopandora.worldhandler.builder.impl.BuilderTime.EnumMode;
import exopandora.worldhandler.builder.impl.BuilderWeather;
import exopandora.worldhandler.builder.impl.BuilderWeather.EnumWeather;
import exopandora.worldhandler.builder.argument.Gamemode;
import exopandora.worldhandler.builder.impl.DifficultyCommandBuilder;
import exopandora.worldhandler.builder.impl.GamemodeCommandBuilder;
import exopandora.worldhandler.builder.impl.TimeCommandBuilder;
import exopandora.worldhandler.builder.impl.WeatherCommandBuilder;
import exopandora.worldhandler.config.Config;
import exopandora.worldhandler.gui.container.impl.GuiWorldHandler;
import exopandora.worldhandler.gui.content.Content;
@@ -67,77 +65,98 @@ public class ActionHelper
public static void timeDawn()
{
CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new BuilderTime(EnumMode.SET, Config.getSettings().getDawn()));
ActionHelper.setDayTime(Config.getSettings().getDawn());
}
public static void timeNoon()
{
CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new BuilderTime(EnumMode.SET, Config.getSettings().getNoon()));
ActionHelper.setDayTime(Config.getSettings().getNoon());
}
public static void timeSunset()
{
CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new BuilderTime(EnumMode.SET, Config.getSettings().getSunset()));
ActionHelper.setDayTime(Config.getSettings().getSunset());
}
public static void timeMidnight()
{
CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new BuilderTime(EnumMode.SET, Config.getSettings().getMidnight()));
ActionHelper.setDayTime(Config.getSettings().getMidnight());
}
public static void setDayTime(int time)
{
TimeCommandBuilder builder = new TimeCommandBuilder();
builder.time().set((float) time);
CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), builder, TimeCommandBuilder.Label.SET);
}
public static void weatherClear()
{
CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new BuilderWeather(EnumWeather.CLEAR));
CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new WeatherCommandBuilder(), WeatherCommandBuilder.Label.CLEAR);
}
public static void weatherRain()
{
CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new BuilderWeather(EnumWeather.RAIN));
CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new WeatherCommandBuilder(), WeatherCommandBuilder.Label.RAIN);
}
public static void weatherThunder()
{
CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new BuilderWeather(EnumWeather.THUNDER));
CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new WeatherCommandBuilder(), WeatherCommandBuilder.Label.THUNDER);
}
public static void difficultyPeaceful()
{
CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new BuilderDifficulty(Difficulty.PEACEFUL));
ActionHelper.setDifficulty(Difficulty.PEACEFUL);
}
public static void difficultyEasy()
{
CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new BuilderDifficulty(Difficulty.EASY));
ActionHelper.setDifficulty(Difficulty.EASY);
}
public static void difficultyNormal()
{
CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new BuilderDifficulty(Difficulty.NORMAL));
ActionHelper.setDifficulty(Difficulty.NORMAL);
}
public static void difficultyHard()
{
CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new BuilderDifficulty(Difficulty.HARD));
ActionHelper.setDifficulty(Difficulty.HARD);
}
private static void setDifficulty(Difficulty difficulty)
{
DifficultyCommandBuilder builder = new DifficultyCommandBuilder();
builder.difficulty().set(difficulty);
CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), builder, DifficultyCommandBuilder.Label.DIFFICULTY);
}
public static void gamemodeSurvival()
{
CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new BuilderGamemode(EnumGamemode.SURVIVAL));
ActionHelper.setGamemode(Gamemode.SURVIVAL);
}
public static void gamemodeCreative()
{
CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new BuilderGamemode(EnumGamemode.CREATIVE));
ActionHelper.setGamemode(Gamemode.CREATIVE);
}
public static void gamemodeAdventure()
{
CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new BuilderGamemode(EnumGamemode.ADVENTURE));
ActionHelper.setGamemode(Gamemode.ADVENTURE);
}
public static void gamemodeSpectator()
{
CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new BuilderGamemode(EnumGamemode.SPECTATOR));
ActionHelper.setGamemode(Gamemode.SPECTATOR);
}
private static void setGamemode(Gamemode gamemode)
{
GamemodeCommandBuilder builder = new GamemodeCommandBuilder();
builder.gamemode().set(gamemode);
CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), builder, GamemodeCommandBuilder.Label.GAMEMODE);
}
public static void tryRun(ActionHandler action)

View File

@@ -1,30 +1,26 @@
package exopandora.worldhandler.util;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import javax.annotation.Nonnull;
import org.apache.commons.lang3.ArrayUtils;
import exopandora.worldhandler.builder.impl.BuilderExecute;
import exopandora.worldhandler.builder.impl.BuilderExecute.EnumMode;
import exopandora.worldhandler.builder.impl.BuilderFill;
import exopandora.worldhandler.builder.impl.BuilderSetBlock;
import exopandora.worldhandler.builder.types.BlockResourceLocation;
import exopandora.worldhandler.builder.types.Coordinate.EnumType;
import exopandora.worldhandler.builder.types.CoordinateInt;
import exopandora.worldhandler.builder.ICommandBuilder;
import exopandora.worldhandler.builder.argument.Coordinate;
import exopandora.worldhandler.builder.impl.ExecuteCommandBuilder;
import exopandora.worldhandler.builder.impl.FillCommandBuilder;
import exopandora.worldhandler.builder.impl.SetBlockCommandBuilder;
import exopandora.worldhandler.builder.impl.ExecuteCommandBuilder.AtOptionalArgument;
import exopandora.worldhandler.config.Config;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.network.protocol.game.ServerboundSetCommandBlockPacket;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.CommandBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
@@ -32,10 +28,8 @@ import net.minecraft.world.phys.HitResult.Type;
public class BlockHelper
{
private static BlockPos pos1 = BlockPos.ZERO;
private static BlockPos pos2 = BlockPos.ZERO;
private static final List<Consumer<BlockPos>> POS_1_OBSERVERS = new ArrayList<Consumer<BlockPos>>();
private static final List<Consumer<BlockPos>> POS_2_OBSERVERS = new ArrayList<Consumer<BlockPos>>();
private static MutableBlockPos pos1 = new MutableBlockPos(0, -64, 0);
private static MutableBlockPos pos2 = new MutableBlockPos(0, -64, 0);
private static final Block[] BLACKLIST = new Block[] {Blocks.AIR, Blocks.WATER, Blocks.LAVA};
@Nonnull
@@ -83,116 +77,36 @@ public class BlockHelper
return Blocks.AIR;
}
public static BlockPos setX(BlockPos pos, double x)
{
return new BlockPos(x, pos.getY(), pos.getZ());
}
public static BlockPos setY(BlockPos pos, double y)
{
return new BlockPos(pos.getX(), y, pos.getZ());
}
public static BlockPos setZ(BlockPos pos, double z)
{
return new BlockPos(pos.getX(), pos.getY(), z);
}
@Nonnull
public static BlockPos getPos1()
{
return BlockHelper.pos1;
}
public static void setPos1(BlockPos pos)
{
if(pos != null && !BlockHelper.pos1.equals(pos))
{
BlockHelper.pos1 = pos;
for(Consumer<BlockPos> observer : POS_1_OBSERVERS)
{
observer.accept(BlockHelper.pos1);
}
}
}
@Nonnull
public static BlockPos getPos2()
{
return BlockHelper.pos2;
}
public static void setPos2(BlockPos pos)
{
if(pos != null && !BlockHelper.pos2.equals(pos))
{
BlockHelper.pos2 = pos;
for(Consumer<BlockPos> observer : POS_2_OBSERVERS)
{
observer.accept(BlockHelper.pos2);
}
}
}
public static <T> T addPositionObservers(T observer, Function<T, Consumer<BlockPos>> pos1generator, Function<T, Consumer<BlockPos>> pos2generator)
{
BlockHelper.addPos1Observer(pos1generator.apply(observer));
BlockHelper.addPos2Observer(pos2generator.apply(observer));
return observer;
}
public static void addPos1Observer(Consumer<BlockPos> observer)
{
POS_1_OBSERVERS.add(observer);
}
public static void removePos1Observer(Consumer<BlockPos> observer)
{
POS_1_OBSERVERS.remove(observer);
}
public static void addPos2Observer(Consumer<BlockPos> observer)
{
POS_2_OBSERVERS.add(observer);
}
public static void removePos2Observer(Consumer<BlockPos> observer)
{
POS_2_OBSERVERS.add(observer);
}
public static boolean setCommandBlockNearPlayer(String player, String command)
public static boolean setCommandBlockNearPlayer(String player, ICommandBuilder command, Object label)
{
if(CommandHelper.canPlayerIssueCommand() && Minecraft.getInstance().getConnection() != null)
{
BlockPos pos = Minecraft.getInstance().player.blockPosition().offset(0, 3, 0);
BuilderFill placeFill = new BuilderFill();
placeFill.setPosition1(pos);
placeFill.setPosition2(pos.above());
placeFill.setBlock1(new BlockResourceLocation(Blocks.COMMAND_BLOCK.getRegistryName()));
FillCommandBuilder place = new FillCommandBuilder();
place.from().set(pos);
place.to().set(pos.above());
place.block().set(Blocks.COMMAND_BLOCK);
BuilderFill removeFill = new BuilderFill();
removeFill.setX1(new CoordinateInt(0, EnumType.GLOBAL));
removeFill.setY1(new CoordinateInt(-1, EnumType.GLOBAL));
removeFill.setZ1(new CoordinateInt(0, EnumType.GLOBAL));
removeFill.setX2(new CoordinateInt(0, EnumType.GLOBAL));
removeFill.setY2(new CoordinateInt(0, EnumType.GLOBAL));
removeFill.setZ2(new CoordinateInt(0, EnumType.GLOBAL));
removeFill.setBlock1(new BlockResourceLocation(Blocks.AIR.getRegistryName()));
FillCommandBuilder remove = new FillCommandBuilder();
remove.from().setX(new Coordinate.Ints(0, Coordinate.Type.RELATIVE));
remove.from().setY(new Coordinate.Ints(-1, Coordinate.Type.RELATIVE));
remove.from().setZ(new Coordinate.Ints(0, Coordinate.Type.RELATIVE));
remove.to().setX(new Coordinate.Ints(0, Coordinate.Type.RELATIVE));
remove.to().setY(new Coordinate.Ints(0, Coordinate.Type.RELATIVE));
remove.to().setZ(new Coordinate.Ints(0, Coordinate.Type.RELATIVE));
remove.block().set(Blocks.AIR);
Minecraft.getInstance().player.chat(placeFill.toActualCommand());
Minecraft.getInstance().player.chat(place.toCommand(FillCommandBuilder.Label.FILL, false));
BuilderExecute wrapped = new BuilderExecute();
wrapped.setMode1(EnumMode.AT);
wrapped.setTarget(player);
wrapped.setMode2(EnumMode.RUN);
wrapped.setCommand(command);
ExecuteCommandBuilder execute = new ExecuteCommandBuilder();
AtOptionalArgument at = new AtOptionalArgument(AtOptionalArgument.Label.AT);
at.targets().setTarget(player);
execute.modifiers().add(at);
execute.command().set(command, label);
Minecraft.getInstance().getConnection().send(new ServerboundSetCommandBlockPacket(pos, wrapped.toActualCommand(), CommandBlockEntity.Mode.REDSTONE, true, false, true));
Minecraft.getInstance().getConnection().send(new ServerboundSetCommandBlockPacket(pos.above(), removeFill.toActualCommand(), CommandBlockEntity.Mode.REDSTONE, true, false, true));
Minecraft.getInstance().getConnection().send(new ServerboundSetCommandBlockPacket(pos, execute.toCommand(ExecuteCommandBuilder.Label.RUN, false), CommandBlockEntity.Mode.REDSTONE, true, false, true));
Minecraft.getInstance().getConnection().send(new ServerboundSetCommandBlockPacket(pos.above(), remove.toCommand(FillCommandBuilder.Label.FILL, false), CommandBlockEntity.Mode.REDSTONE, true, false, true));
return true;
}
@@ -202,13 +116,41 @@ public class BlockHelper
public static void setBlockNearPlayer(String player, Block block)
{
BuilderSetBlock builder = new BuilderSetBlock(new CoordinateInt(EnumType.LOCAL), new CoordinateInt(EnumType.LOCAL), new CoordinateInt(2, EnumType.LOCAL), block.getRegistryName(), Config.getSettings().getBlockPlacingMode());
SetBlockCommandBuilder builder = new SetBlockCommandBuilder();
builder.pos().setX(new Coordinate.Ints(Coordinate.Type.LOCAL));
builder.pos().setY(new Coordinate.Ints(Coordinate.Type.LOCAL));
builder.pos().setZ(new Coordinate.Ints(2, Coordinate.Type.LOCAL));
if(Minecraft.getInstance().player != null)
BlockState state = block.defaultBlockState();
if(Minecraft.getInstance().player != null && state.hasProperty(BlockStateProperties.HORIZONTAL_FACING))
{
builder.setState(BlockStateProperties.HORIZONTAL_FACING, Minecraft.getInstance().player.getDirection().getOpposite());
state = state.setValue(BlockStateProperties.HORIZONTAL_FACING, Minecraft.getInstance().player.getDirection().getOpposite());
}
CommandHelper.sendCommand(player, builder);
builder.block().set(state);
switch(Config.getSettings().getBlockPlacingMode())
{
case KEEP:
CommandHelper.sendCommand(player, builder, SetBlockCommandBuilder.Label.KEEP);
break;
case REPLACE:
CommandHelper.sendCommand(player, builder, SetBlockCommandBuilder.Label.REPLACE);
break;
case DESTROY:
CommandHelper.sendCommand(player, builder, SetBlockCommandBuilder.Label.DESTROY);
break;
}
}
public static MutableBlockPos pos1()
{
return pos1;
}
public static MutableBlockPos pos2()
{
return pos2;
}
}

View File

@@ -4,7 +4,6 @@ import com.mojang.brigadier.CommandDispatcher;
import exopandora.worldhandler.WorldHandler;
import exopandora.worldhandler.builder.ICommandBuilder;
import exopandora.worldhandler.builder.ICommandBuilderSyntax;
import exopandora.worldhandler.command.CommandWH;
import exopandora.worldhandler.command.CommandWorldHandler;
import net.minecraft.client.Minecraft;
@@ -13,6 +12,8 @@ import net.minecraft.network.chat.TextComponent;
public class CommandHelper
{
public static final int MAX_COMMAND_LENGTH = 256;
public static void sendFeedback(CommandSourceStack source, String message)
{
source.sendSuccess(new TextComponent(message), false);
@@ -34,36 +35,24 @@ public class CommandHelper
CommandWH.register(dispatcher);
}
public static void sendCommand(String player, ICommandBuilder builder)
public static void sendCommand(String player, ICommandBuilder builder, Object label)
{
CommandHelper.sendCommand(player, builder, false);
CommandHelper.sendCommand(player, builder, label, false);
}
public static void sendCommand(String player, ICommandBuilder builder, boolean special)
public static void sendCommand(String player, ICommandBuilder builder, Object label, boolean special)
{
if(builder != null)
String command = builder.toCommand(label, false);
if(builder.needsCommandBlock(label, false) || special)
{
String command;
if(builder instanceof ICommandBuilderSyntax)
{
command = ((ICommandBuilderSyntax) builder).toActualCommand();
}
else
{
command = builder.toCommand();
}
WorldHandler.LOGGER.info("Command: " + command);
if(builder.needsCommandBlock() || special)
{
BlockHelper.setCommandBlockNearPlayer(player, command);
}
else if(Minecraft.getInstance().player != null)
{
Minecraft.getInstance().player.chat(command);
}
BlockHelper.setCommandBlockNearPlayer(player, builder, label);
}
else if(Minecraft.getInstance().player != null)
{
Minecraft.getInstance().player.chat(command);
}
WorldHandler.LOGGER.info("Command: " + command);
}
}

View File

@@ -1,5 +1,7 @@
package exopandora.worldhandler.util;
import java.util.function.Function;
import javax.annotation.Nullable;
public class EnumHelper
@@ -16,4 +18,18 @@ public class EnumHelper
return null;
}
}
@Nullable
public static <T extends Enum<T>> T find(String key, T[] values, Function<T, String> mapper)
{
for(T value : values)
{
if(mapper.apply(value).equals(key))
{
return value;
}
}
return null;
}
}

View File

@@ -1,6 +1,5 @@
package exopandora.worldhandler.util;
import exopandora.worldhandler.builder.INBTWritable;
import net.minecraft.ChatFormatting;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
@@ -8,7 +7,7 @@ import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.util.FormattedCharSequence;
public class MutableTextComponent extends TextComponent implements INBTWritable
public class MutableTextComponent extends TextComponent
{
public MutableTextComponent()
{
@@ -70,7 +69,6 @@ public class MutableTextComponent extends TextComponent implements INBTWritable
return FormattedCharSequence.forward(string, this.getStyle());
}
@Override
public Tag serialize()
{
if(this.getContents() != null && !this.getContents().isEmpty())

View File

@@ -3,9 +3,8 @@ package exopandora.worldhandler.util;
import java.util.Arrays;
import java.util.List;
import exopandora.worldhandler.builder.INBTWritable;
import exopandora.worldhandler.builder.component.IBuilderComponent;
import exopandora.worldhandler.builder.component.impl.EntityNBT;
import exopandora.worldhandler.builder.argument.tag.EntityTag;
import exopandora.worldhandler.builder.argument.tag.ITagProvider;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.DoubleTag;
import net.minecraft.nbt.ListTag;
@@ -13,6 +12,7 @@ import net.minecraft.nbt.NbtUtils;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.state.BlockState;
@@ -49,19 +49,19 @@ public class NBTHelper
return null;
}
public static Tag serialize(ResourceLocation[] itemArray)
public static Tag serialize(Item[] itemArray)
{
if(Arrays.stream(itemArray).allMatch(resource -> resource != null && resource.equals(Items.AIR.getRegistryName())))
if(Arrays.stream(itemArray).allMatch(Items.AIR::equals))
{
return null;
}
ListTag list = new ListTag();
for(ResourceLocation item : itemArray)
for(Item item : itemArray)
{
CompoundTag compound = new CompoundTag();
compound.putString("id", item.toString());
compound.putString("id", item.getRegistryName().toString());
compound.putInt("Count", 1);
list.add(compound);
}
@@ -69,13 +69,13 @@ public class NBTHelper
return list;
}
public static Tag serialize(List<EntityNBT> entities)
public static Tag serialize(List<EntityTag> entities)
{
ListTag list = new ListTag();
for(EntityNBT entity : entities)
for(EntityTag entity : entities)
{
Tag nbt = entity.serialize();
Tag nbt = entity.value();
if(nbt != null)
{
@@ -91,24 +91,16 @@ public class NBTHelper
return list;
}
public static void append(CompoundTag compound, String tag, INBTWritable writable)
public static void append(CompoundTag compound, ITagProvider component)
{
NBTHelper.append(compound, tag, writable.serialize());
}
public static void append(CompoundTag compound, IBuilderComponent component)
{
NBTHelper.append(compound, component.getTag(), component.serialize());
NBTHelper.append(compound, component.key(), component.value());
}
public static void append(CompoundTag compound, String tag, Tag nbt)
{
if(nbt != null)
if(nbt != null && !compound.contains(tag))
{
if(!compound.contains(tag))
{
compound.put(tag, nbt);
}
compound.put(tag, nbt);
}
}
}

View File

@@ -52,7 +52,6 @@ public class Node
{
this.validateEntries();
this.entries.add(node);
return node;
}
@@ -145,8 +144,7 @@ public class Node
}
}
root.addNode(node);
return this.insertNode(index + 1, path, node);
return this.insertNode(index + 1, path, root.addNode(node));
}
public void mergeItems()

View File

@@ -36,7 +36,6 @@ public class RegistryHelper
Registry<Biome> registry = RegistryAccess.builtin().registryOrThrow(Registry.BIOME_REGISTRY);
ResourceLocation resource = registry.getKey(biome);
String key = "biome." + biome.getRegistryName().getNamespace() + "." + resource.getPath();
return Language.getInstance().has(key) ? key : resource.toString();
});
registerRegistry(ForgeRegistries.ENCHANTMENTS, Enchantment::getDescriptionId);

View File

@@ -9,6 +9,8 @@ import net.minecraft.client.gui.GuiComponent;
public class RenderUtils
{
public static final double EPS = 0.0020000000949949026D;
public static void drawWatchIntoGui(PoseStack matrix, GuiComponent gui, int width, int height, long worldTicks, boolean smooth)
{
float hour = TextUtils.toHour(worldTicks);

View File

@@ -3,8 +3,6 @@ package exopandora.worldhandler.util;
import javax.annotation.Nullable;
import exopandora.worldhandler.Main;
import exopandora.worldhandler.builder.types.BlockResourceLocation;
import exopandora.worldhandler.builder.types.ItemResourceLocation;
import exopandora.worldhandler.config.Config;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.registries.IForgeRegistry;
@@ -15,59 +13,26 @@ public class ResourceHelper
private static final ResourceLocation BACKGROUND_VANILLA = new ResourceLocation(Main.MODID, "textures/skins/vanilla/vanilla.png");
private static final ResourceLocation BUTTON = new ResourceLocation("textures/gui/widgets.png");
public static ResourceLocation stringToResourceLocation(String resource)
@Nullable
public static ResourceLocation stringToResourceLocation(@Nullable String resource)
{
if(resource != null)
if(resource != null && !resource.isEmpty())
{
return new ResourceLocation(stripToResourceLocation(resource));
return ResourceLocation.tryParse(resource.toLowerCase().replaceAll("[^a-z0-9/._\\-:]", "_"));
}
return null;
}
@Nullable
public static String stripToResourceLocation(String resource)
{
if(resource != null)
{
return resource.toLowerCase().replaceAll("[^a-z0-9/._\\-:]", "_");
}
return null;
}
@Nullable
public static boolean isRegistered(ResourceLocation resource, IForgeRegistry<?> registry)
{
return resource != null && registry != null && registry.containsKey(resource);
}
@Nullable
public static boolean isRegistered(BlockResourceLocation resource, IForgeRegistry<?> registry)
{
if(resource != null)
{
return isRegistered(resource.getResourceLocation(), registry);
}
return false;
}
@Nullable
public static boolean isRegistered(ItemResourceLocation resource, IForgeRegistry<?> registry)
{
if(resource != null)
{
return isRegistered(resource.getResourceLocation(), registry);
}
return false;
}
@Nullable
public static ResourceLocation assertRegistered(ResourceLocation resource, IForgeRegistry<?> registry)
{
if(ResourceHelper.isRegistered(resource, registry))
if(resource != null && ResourceHelper.isRegistered(resource, registry))
{
return resource;
}