Hooks.java 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package me.kcm;
  2. import java.util.Collections;
  3. import java.util.List;
  4. import java.util.function.Consumer;
  5. import javax.annotation.Nullable;
  6. import net.minecraft.block.BlockState;
  7. import net.minecraft.entity.Entity;
  8. import net.minecraft.item.ItemStack;
  9. import net.minecraft.server.dedicated.DedicatedPlayerList;
  10. import net.minecraft.server.dedicated.DedicatedServer;
  11. import net.minecraft.tileentity.TileEntity;
  12. import net.minecraft.util.math.BlockPos;
  13. import net.minecraft.world.server.ServerWorld;
  14. public class Hooks {
  15. private static Consumer<DedicatedServer> playerListFunction = null;
  16. private static BlockHarvest blockHarvest = (state, w, pos, tileEnt, ent, stack) -> Collections.EMPTY_LIST;
  17. public static void setPlayerListFunction(Consumer<DedicatedServer> c) {
  18. playerListFunction = c;
  19. }
  20. public static void setPlayerList(DedicatedServer server) {
  21. if(playerListFunction != null) {
  22. playerListFunction.accept(server);
  23. } else {
  24. try {
  25. server.setPlayerList(new DedicatedPlayerList(server));
  26. } catch(Exception ex) {
  27. // this is stupid and should not be needed
  28. ex.printStackTrace();
  29. }
  30. }
  31. }
  32. public static void setBlockHarvest(BlockHarvest c) {
  33. blockHarvest = c;
  34. }
  35. public static List<ItemStack> getDropsA(BlockState state, ServerWorld w, BlockPos pos, @Nullable TileEntity tileEnt) {
  36. return blockHarvest.onBlockHarvest(state, w, pos, tileEnt, null, null);
  37. }
  38. public static List<ItemStack> getDropsB(BlockState state, ServerWorld w, BlockPos pos, @Nullable TileEntity tileEnt, @Nullable Entity ent, ItemStack stack) {
  39. return blockHarvest.onBlockHarvest(state, w, pos, tileEnt, ent, stack);
  40. }
  41. }