Hooks.java 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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.entity.player.PlayerEntity;
  9. import net.minecraft.inventory.CraftResultInventory;
  10. import net.minecraft.inventory.CraftingInventory;
  11. import net.minecraft.item.ItemStack;
  12. import net.minecraft.server.dedicated.DedicatedPlayerList;
  13. import net.minecraft.server.dedicated.DedicatedServer;
  14. import net.minecraft.tileentity.TileEntity;
  15. import net.minecraft.util.math.BlockPos;
  16. import net.minecraft.world.World;
  17. import net.minecraft.world.server.ServerWorld;
  18. public class Hooks {
  19. private static Consumer<DedicatedServer> playerListFunction = null;
  20. private static BlockHarvest blockHarvest = (state, w, pos, tileEnt, ent, stack) -> Collections.EMPTY_LIST;
  21. private static Craft craft = (id, w, p, cInv, slot) -> {};
  22. public static void setPlayerListFunction(Consumer<DedicatedServer> c) {
  23. playerListFunction = c;
  24. }
  25. public static void setPlayerList(DedicatedServer server) {
  26. if(playerListFunction != null) {
  27. playerListFunction.accept(server);
  28. } else {
  29. try {
  30. server.setPlayerList(new DedicatedPlayerList(server));
  31. } catch(Exception ex) {
  32. // this is stupid and should not be needed
  33. ex.printStackTrace();
  34. }
  35. }
  36. }
  37. public static void setBlockHarvest(BlockHarvest c) {
  38. blockHarvest = c;
  39. }
  40. public static void setCraft(Craft c) {
  41. craft = c;
  42. }
  43. public static List<ItemStack> getDropsA(BlockState state, ServerWorld w, BlockPos pos, @Nullable TileEntity tileEnt) {
  44. return blockHarvest.onBlockHarvest(state, w, pos, tileEnt, null, null);
  45. }
  46. public static List<ItemStack> getDropsB(BlockState state, ServerWorld w, BlockPos pos, @Nullable TileEntity tileEnt, @Nullable Entity ent, ItemStack stack) {
  47. return blockHarvest.onBlockHarvest(state, w, pos, tileEnt, ent, stack);
  48. }
  49. public static void onCraft(int id, World w, PlayerEntity p, CraftingInventory cInv, CraftResultInventory slot) {
  50. craft.onCraft(id, w, p, cInv, slot);
  51. }
  52. }