123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- 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.util.registry.DynamicRegistries;
- import net.minecraft.world.World;
- import net.minecraft.world.server.ServerWorld;
- import net.minecraft.world.storage.PlayerData;
- 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) -> {
- };
- 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 List<ItemStack> getDropsA(BlockState state, ServerWorld w, BlockPos pos, @Nullable TileEntity tileEnt) {
- return blockHarvest.onBlockHarvest(state, w, pos, tileEnt, null, null);
- }
- public static List<ItemStack> 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);
- }
- }
|