LootParams类 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 public class LootParams { ServerLevel ; Map<LootContextParam<?>, Object> ; Map<ResourceLocation, LootParams.DynamicDrop> dynamicDrops; luck; getParameter(LootContextParam<T> ) { } getOptionalParameter(LootContextParam<T> ) { } getParamOrNull( ) { } addDynamicDrops() { } float getLuck () { } public static class Builder { ServerLevel level; Map<LootContextParam<?>, Object> params Map<ResourceLocation, LootParams.DynamicDrop> dynamicDrops private float luck; public Builder (ServerLevel ) { } public ServerLevel getLevel () { } <T> LootParams.Builder withParameter (LootContextParam<T> ,) { } <T> LootParams.Builder withOptionalParameter (LootContextParam<T>, @Nullable T ) { } <T> T getParameter (LootContextParam<T> ) { } @Nullable <T> T getOptionalParameter (LootContextParam<T> ) { } LootParams.Builder withDynamicDrop (ResourceLocation , LootParams.DynamicDrop ) { } public LootParams.Builder withLuck (float ) { } public LootParams create (LootContextParamSet ) { } } @FunctionalInterface public interface DynamicDrop { void add (Consumer<ItemStack>) ; } }
LootContextParam 类 主要目的是定义一个可以存储资源位置的参数类,这个类可以被用于表示游戏中的各种上下文参数,例如掉落物的位置,玩家的位置等等
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 LootContextParam<T> { name; LootContextParam( ) { } ResourceLocation getName () { } String toString () { } }
LootContextParams类 定义了一个名为LootContextParams
的类,这个类用于创建各种类型的掉落物上下文参数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 public class LootContextParams {"last_damage_player" "damage_source" "killer_entity" "direct_killer_entity" "origin" "block_state" "block_entity" "tool" "explosion_radius" }
block类部分代码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 dropResources() { } } void dropResources () { } void dropResources ( ) { } playerDestroy() { } List<ItemStack> getDrops () { } List<ItemStack> getDrops BlockState , ServerLevel , BlockPos , BlockEntity , Entity , ItemStack ) { }
blockstate部分代码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 getDrops() { } getDrops( ) { if () { } else { } }
ServerPlayerGameMode类部分代码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 destroyBlock(BlockPos) { if () { } else { if () { } else if () { return false ; } else if () { } else { if () { } else { if () if ()) { } if () } } } }