package me.kcm; import java.util.Collections; import java.util.List; 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.util.registry.DynamicRegistries; import net.minecraft.world.World; import net.minecraft.world.server.ServerWorld; import net.minecraft.world.storage.PlayerData; import net.minecraft.inventory.container.ClickType; import net.minecraft.inventory.container.Container; public class Hooks { @FunctionalInterface public interface PlayerListFunction { public void accept(DedicatedServer server, DynamicRegistries.Impl impl, PlayerData pd); } private static PlayerListFunction playerListFunction = null; private static BlockHarvest blockHarvest = (state, w, pos, tileEnt, ent, stack) -> Collections.EMPTY_LIST; private static Craft craft = (id, w, p, cInv, slot) -> { }; private static ContainerClick click = (c, slot, dragType, ct, p) -> { return false; }; public static void setPlayerListFunction(PlayerListFunction c) { playerListFunction = c; } public static void setPlayerList(DedicatedServer server, DynamicRegistries.Impl impl, PlayerData pd) { System.out.println("trying to update player list ..."); if(playerListFunction != null) { playerListFunction.accept(server, impl, pd); System.out.println("succeeded with custom function"); } else { try { server.setPlayerList(new DedicatedPlayerList(server, impl, pd)); System.out.println("succeeded with vanilla function"); } 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 void setContainerClick(ContainerClick c) { click = 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); } public static boolean onSlotClick(Container c, int slot, int dragType, ClickType ct, PlayerEntity p) { return click.onClick(c, slot, dragType, ct, p); } }