package me.kcm; import java.util.Collections; import java.util.List; import java.util.function.Consumer; import javax.annotation.Nullable; import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.inventory.CraftResultInventory; import net.minecraft.inventory.CraftingInventory; import net.minecraft.item.ItemStack; import net.minecraft.server.dedicated.DedicatedPlayerList; import net.minecraft.server.dedicated.DedicatedServer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.server.ServerWorld; public class Hooks { private static Consumer playerListFunction = null; private static BlockHarvest blockHarvest = (state, w, pos, tileEnt, ent, stack) -> Collections.EMPTY_LIST; private static Craft craft = (id, w, p, cInv, slot) -> {}; public static void setPlayerListFunction(Consumer c) { playerListFunction = c; } public static void setPlayerList(DedicatedServer server) { if(playerListFunction != null) { playerListFunction.accept(server); } else { try { server.setPlayerList(new DedicatedPlayerList(server)); } catch(Exception ex) { // this is stupid and should not be needed ex.printStackTrace(); } } } public static void setBlockHarvest(BlockHarvest c) { blockHarvest = c; } public static void setCraft(Craft c) { craft = c; } public static List getDropsA(BlockState state, ServerWorld w, BlockPos pos, @Nullable TileEntity tileEnt) { return blockHarvest.onBlockHarvest(state, w, pos, tileEnt, null, null); } public static List getDropsB(BlockState state, ServerWorld w, BlockPos pos, @Nullable TileEntity tileEnt, @Nullable Entity ent, ItemStack stack) { return blockHarvest.onBlockHarvest(state, w, pos, tileEnt, ent, stack); } public static void onCraft(int id, World w, PlayerEntity p, CraftingInventory cInv, CraftResultInventory slot) { craft.onCraft(id, w, p, cInv, slot); } }