ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/util/compat/CompatUtil.java

57 lines
2 KiB
Java
Raw Normal View History

2015-08-29 14:33:25 +02:00
/*
2016-05-16 22:52:27 +02:00
* This file ("CompatUtil.java") is part of the Actually Additions mod for Minecraft.
2015-08-29 14:33:25 +02:00
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-05-16 22:52:27 +02:00
* http://ellpeck.de/actaddlicense
2015-08-29 14:33:25 +02:00
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2017-01-01 16:23:26 +01:00
* © 2015-2017 Ellpeck
2015-08-29 14:33:25 +02:00
*/
2016-06-17 14:00:52 +02:00
package de.ellpeck.actuallyadditions.mod.util.compat;
2015-06-28 03:12:32 +02:00
2018-03-07 03:08:25 +01:00
import net.minecraft.client.gui.inventory.GuiCrafting;
2021-02-26 22:15:48 +01:00
import net.minecraft.entity.player.PlayerEntity;
2018-03-07 03:08:25 +01:00
import net.minecraft.inventory.ContainerWorkbench;
2021-02-26 22:15:48 +01:00
import net.minecraft.nbt.CompoundNBT;
2018-03-07 03:08:25 +01:00
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.Loader;
2018-03-23 03:53:13 +01:00
import net.minecraftforge.fml.common.event.FMLInterModComms;
2015-06-28 03:12:32 +02:00
2018-03-07 03:08:25 +01:00
public final class CompatUtil {
2015-06-28 03:12:32 +02:00
2018-03-23 03:53:13 +01:00
static boolean fb = Loader.isModLoaded("fastbench");
2018-03-07 03:08:25 +01:00
2021-02-26 22:15:48 +01:00
@OnlyIn(Dist.CLIENT)
public static Object getCrafterGuiElement(PlayerEntity player, World world, int x, int y, int z) {
if (fb) {
return CompatFastBench.getFastBenchGui(player, world);
}
2018-03-23 03:53:13 +01:00
return new GuiCrafting(player.inventory, world, new BlockPos(x, y, z));
}
2018-03-07 03:08:25 +01:00
2021-02-26 22:15:48 +01:00
public static Object getCrafterContainerElement(PlayerEntity player, World world, int x, int y, int z) {
if (fb) {
return CompatFastBench.getFastBenchContainer(player, world);
}
2018-03-23 03:53:13 +01:00
return new ContainerWorkbench(player.inventory, world, new BlockPos(x, y, z)) {
2019-02-27 19:53:05 +01:00
@Override
2021-02-26 22:15:48 +01:00
public boolean canInteractWith(PlayerEntity playerIn) {
2018-03-23 03:53:13 +01:00
return true;
}
};
}
public static void registerCraftingTweaks() {
2021-02-26 22:15:48 +01:00
CompoundNBT t = new CompoundNBT();
if (fb) {
t.setString("ContainerClass", "de.ellpeck.actuallyadditions.mod.util.compat.CompatFastBench$1");
} else {
t.setString("ContainerClass", "de.ellpeck.actuallyadditions.mod.util.compat.CompatUtil$1");
}
2018-03-23 03:53:13 +01:00
FMLInterModComms.sendMessage("craftingtweaks", "RegisterProvider", t);
}
2015-06-28 03:12:32 +02:00
}