Fix deprecated code

This commit is contained in:
Marcel Konrad
2020-07-05 13:49:42 +02:00
parent 563ef68c95
commit 7832c0a902
3 changed files with 101 additions and 47 deletions

View File

@@ -20,6 +20,7 @@ import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.DistExecutor.SafeRunnable;
import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.client.registry.ClientRegistry; import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
@@ -35,24 +36,29 @@ public class WorldHandler
public static final Logger LOGGER = LogManager.getLogger(); public static final Logger LOGGER = LogManager.getLogger();
public static final Path USERCONTENT_PATH = FMLPaths.CONFIGDIR.get().resolve(Main.MODID).resolve("usercontent"); public static final Path USERCONTENT_PATH = FMLPaths.CONFIGDIR.get().resolve(Main.MODID).resolve("usercontent");
@SuppressWarnings("deprecation")
public WorldHandler() public WorldHandler()
{ {
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
modEventBus.addListener(this::clientSetup); modEventBus.addListener(this::clientSetup);
MinecraftForge.EVENT_BUS.addListener(this::serverStarting); MinecraftForge.EVENT_BUS.addListener(this::serverStarting);
DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> new SafeRunnable()
{ {
SimpleReloadableResourceManager manager = (SimpleReloadableResourceManager) Minecraft.getInstance().getResourceManager(); private static final long serialVersionUID = 1457410143759855413L;
manager.addReloadListener(AdvancementHelper.getInstance());
Config.setupDirectories(WorldHandler.USERCONTENT_PATH); @Override
ModLoadingContext.get().registerConfig(Type.CLIENT, Config.CLIENT_SPEC, Main.MODID + "/" + Main.MODID + ".toml"); public void run()
UsercontentLoader.load(WorldHandler.USERCONTENT_PATH); {
modEventBus.register(Config.class); SimpleReloadableResourceManager manager = (SimpleReloadableResourceManager) Minecraft.getInstance().getResourceManager();
modEventBus.addListener(Content::createRegistry); manager.addReloadListener(AdvancementHelper.getInstance());
modEventBus.addListener(Category::createRegistry); Config.setupDirectories(WorldHandler.USERCONTENT_PATH);
modEventBus.addGenericListener(Content.class, Content::register); ModLoadingContext.get().registerConfig(Type.CLIENT, Config.CLIENT_SPEC, Main.MODID + "/" + Main.MODID + ".toml");
modEventBus.addGenericListener(Category.class, Category::register); UsercontentLoader.load(WorldHandler.USERCONTENT_PATH);
modEventBus.register(Config.class);
modEventBus.addListener(Content::createRegistry);
modEventBus.addListener(Category::createRegistry);
modEventBus.addGenericListener(Content.class, Content::register);
modEventBus.addGenericListener(Category.class, Category::register);
}
}); });
// ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.CONFIGGUIFACTORY, () -> // ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.CONFIGGUIFACTORY, () ->
// { // {

View File

@@ -27,6 +27,7 @@ import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.DistExecutor.SafeRunnable;
import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistries;
public class CommandWH public class CommandWH
@@ -61,12 +62,18 @@ public class CommandWH
private static int pos1(CommandSource source) throws CommandSyntaxException private static int pos1(CommandSource source) throws CommandSyntaxException
{ {
DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> () -> DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> new SafeRunnable()
{ {
BlockHelper.setPos1(BlockHelper.getFocusedBlockPos()); private static final long serialVersionUID = 818420798194963795L;
BlockPos pos = BlockHelper.getPos1();
ResourceLocation block = ForgeRegistries.BLOCKS.getKey(BlockHelper.getBlock(pos)); @Override
CommandHelper.sendFeedback(source, "Set first position to " + pos.getX() + ", " + pos.getY() + ", " + pos.getZ() + " (" + block + ")"); public void run()
{
BlockHelper.setPos1(BlockHelper.getFocusedBlockPos());
BlockPos pos = BlockHelper.getPos1();
ResourceLocation block = ForgeRegistries.BLOCKS.getKey(BlockHelper.getBlock(pos));
CommandHelper.sendFeedback(source, "Set first position to " + pos.getX() + ", " + pos.getY() + ", " + pos.getZ() + " (" + block + ")");
}
}); });
return 1; return 1;
@@ -74,12 +81,18 @@ public class CommandWH
private static int pos2(CommandSource source) throws CommandSyntaxException private static int pos2(CommandSource source) throws CommandSyntaxException
{ {
DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> () -> DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> new SafeRunnable()
{ {
BlockHelper.setPos2(BlockHelper.getFocusedBlockPos()); private static final long serialVersionUID = 5436684018502529063L;
BlockPos pos = BlockHelper.getPos2();
ResourceLocation block = ForgeRegistries.BLOCKS.getKey(BlockHelper.getBlock(pos)); @Override
CommandHelper.sendFeedback(source, "Set second position to " + pos.getX() + ", " + pos.getY() + ", " + pos.getZ() + " (" + block + ")"); public void run()
{
BlockHelper.setPos2(BlockHelper.getFocusedBlockPos());
BlockPos pos = BlockHelper.getPos2();
ResourceLocation block = ForgeRegistries.BLOCKS.getKey(BlockHelper.getBlock(pos));
CommandHelper.sendFeedback(source, "Set second position to " + pos.getX() + ", " + pos.getY() + ", " + pos.getZ() + " (" + block + ")");
}
}); });
return 1; return 1;
@@ -87,11 +100,17 @@ public class CommandWH
private static int fill(CommandSource source, BlockStateInput block) private static int fill(CommandSource source, BlockStateInput block)
{ {
DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> () -> DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> new SafeRunnable()
{ {
BuilderFill builder = new BuilderFill(); private static final long serialVersionUID = 7622739284160142817L;
builder.setBlock1(new BlockResourceLocation(block.getState().getBlock().getRegistryName(), block.getState(), block.tag));
CommandHelper.sendCommand(builder); @Override
public void run()
{
BuilderFill builder = new BuilderFill();
builder.setBlock1(new BlockResourceLocation(block.getState().getBlock().getRegistryName(), block.getState(), block.tag));
CommandHelper.sendCommand(builder);
}
}); });
return 1; return 1;
@@ -99,14 +118,20 @@ public class CommandWH
private static int replace(CommandSource source, BlockStateInput block, BlockStateInput replace) private static int replace(CommandSource source, BlockStateInput block, BlockStateInput replace)
{ {
DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> () -> DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> new SafeRunnable()
{ {
BuilderFill builder = new BuilderFill(); private static final long serialVersionUID = -5007303344454187200L;
builder.setPosition1(BlockHelper.getPos1());
builder.setPosition2(BlockHelper.getPos2()); @Override
builder.setBlock1(new BlockResourceLocation(block.getState().getBlock().getRegistryName(), block.getState(), block.tag)); public void run()
builder.setBlock2(new BlockResourceLocation(replace.getState().getBlock().getRegistryName(), replace.getState(), replace.tag)); {
CommandHelper.sendCommand(builder); BuilderFill builder = new BuilderFill();
builder.setPosition1(BlockHelper.getPos1());
builder.setPosition2(BlockHelper.getPos2());
builder.setBlock1(new BlockResourceLocation(block.getState().getBlock().getRegistryName(), block.getState(), block.tag));
builder.setBlock2(new BlockResourceLocation(replace.getState().getBlock().getRegistryName(), replace.getState(), replace.tag));
CommandHelper.sendCommand(builder);
}
}); });
return 1; return 1;
@@ -114,14 +139,20 @@ public class CommandWH
private static int clone(CommandSource source, String mask, String filter) private static int clone(CommandSource source, String mask, String filter)
{ {
DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> () -> DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> new SafeRunnable()
{ {
BuilderClone builder = new BuilderClone(); private static final long serialVersionUID = -2849956095821394079L;
builder.setPosition1(BlockHelper.getPos1());
builder.setPosition2(BlockHelper.getPos2()); @Override
builder.setMask(EnumHelper.valueOf(mask, EnumMask.class)); public void run()
builder.setFilter(filter); {
CommandHelper.sendCommand(builder); BuilderClone builder = new BuilderClone();
builder.setPosition1(BlockHelper.getPos1());
builder.setPosition2(BlockHelper.getPos2());
builder.setMask(EnumHelper.valueOf(mask, EnumMask.class));
builder.setFilter(filter);
CommandHelper.sendCommand(builder);
}
}); });
return 1; return 1;
@@ -129,13 +160,19 @@ public class CommandWH
private static int clone(CommandSource source, String mask) private static int clone(CommandSource source, String mask)
{ {
DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> () -> DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> new SafeRunnable()
{ {
BuilderClone builder = new BuilderClone(); private static final long serialVersionUID = -7349335271543407747L;
builder.setPosition1(BlockHelper.getPos1());
builder.setPosition2(BlockHelper.getPos2()); @Override
builder.setMask(EnumHelper.valueOf(mask, EnumMask.class)); public void run()
CommandHelper.sendCommand(builder); {
BuilderClone builder = new BuilderClone();
builder.setPosition1(BlockHelper.getPos1());
builder.setPosition2(BlockHelper.getPos2());
builder.setMask(EnumHelper.valueOf(mask, EnumMask.class));
CommandHelper.sendCommand(builder);
}
}); });
return 1; return 1;

View File

@@ -13,6 +13,7 @@ import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands; import net.minecraft.command.Commands;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.DistExecutor.SafeRunnable;
import net.minecraftforge.fml.ModList; import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.VersionChecker; import net.minecraftforge.fml.VersionChecker;
@@ -39,7 +40,17 @@ public class CommandWorldHandler
private static int display(CommandSource source) throws CommandSyntaxException private static int display(CommandSource source) throws CommandSyntaxException
{ {
DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> () -> Minecraft.getInstance().execute(ActionHelper::displayGui)); DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> new SafeRunnable()
{
private static final long serialVersionUID = 210782927512442500L;
@Override
public void run()
{
Minecraft.getInstance().execute(ActionHelper::displayGui);
}
});
return 1; return 1;
} }