CauldronInteractions.java
net.minecraft.core.cauldron.CauldronInteractions
信息
- 全限定名:net.minecraft.core.cauldron.CauldronInteractions
- 类型:public class
- 包:net.minecraft.core.cauldron
- 源码路径:src/main/java/net/minecraft/core/cauldron/CauldronInteractions.java
- 起始行号:L33
- 职责:
TODO
字段/常量
-
ID_MAPPER- 类型:
ExtraCodecs.LateBoundIdMapper<String,CauldronInteraction.Dispatcher> - 修饰符:
private static final - 源码定位:
L34 - 说明:
TODO
- 类型:
-
CODEC- 类型:
Codec<CauldronInteraction.Dispatcher> - 修饰符:
public static final - 源码定位:
L35 - 说明:
TODO
- 类型:
-
EMPTY- 类型:
CauldronInteraction.Dispatcher - 修饰符:
public static final - 源码定位:
L36 - 说明:
TODO
- 类型:
-
WATER- 类型:
CauldronInteraction.Dispatcher - 修饰符:
public static final - 源码定位:
L37 - 说明:
TODO
- 类型:
-
LAVA- 类型:
CauldronInteraction.Dispatcher - 修饰符:
public static final - 源码定位:
L38 - 说明:
TODO
- 类型:
-
POWDER_SNOW- 类型:
CauldronInteraction.Dispatcher - 修饰符:
public static final - 源码定位:
L39 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
- 无
方法
下面的方法块按源码顺序生成。
private static CauldronInteraction.Dispatcher newDispatcher(String name) @ L41
- 方法名:newDispatcher
- 源码定位:L41
- 返回类型:CauldronInteraction.Dispatcher
- 修饰符:private static
参数:
- name: String
说明:
TODO
public static void bootStrap() @ L47
- 方法名:bootStrap
- 源码定位:L47
- 返回类型:void
- 修饰符:public static
参数:
- 无
说明:
TODO
static void addDefaultInteractions(CauldronInteraction.Dispatcher interactionMap) @ L173
- 方法名:addDefaultInteractions
- 源码定位:L173
- 返回类型:void
- 修饰符:static
参数:
- interactionMap: CauldronInteraction.Dispatcher
说明:
TODO
static InteractionResult fillBucket(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, ItemStack itemInHand, ItemStack newItem, Predicate<BlockState> canFill, SoundEvent soundEvent) @ L179
- 方法名:fillBucket
- 源码定位:L179
- 返回类型:InteractionResult
- 修饰符:static
参数:
- state: BlockState
- level: Level
- pos: BlockPos
- player: Player
- hand: InteractionHand
- itemInHand: ItemStack
- newItem: ItemStack
- canFill: Predicate
- soundEvent: SoundEvent
说明:
TODO
static InteractionResult emptyBucket(Level level, BlockPos pos, Player player, InteractionHand hand, ItemStack itemInHand, BlockState newState, SoundEvent soundEvent) @ L207
- 方法名:emptyBucket
- 源码定位:L207
- 返回类型:InteractionResult
- 修饰符:static
参数:
- level: Level
- pos: BlockPos
- player: Player
- hand: InteractionHand
- itemInHand: ItemStack
- newState: BlockState
- soundEvent: SoundEvent
说明:
TODO
private static InteractionResult fillWaterInteraction(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, ItemStack itemInHand) @ L223
- 方法名:fillWaterInteraction
- 源码定位:L223
- 返回类型:InteractionResult
- 修饰符:private static
参数:
- state: BlockState
- level: Level
- pos: BlockPos
- player: Player
- hand: InteractionHand
- itemInHand: ItemStack
说明:
TODO
private static InteractionResult fillLavaInteraction(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, ItemStack itemInHand) @ L231
- 方法名:fillLavaInteraction
- 源码定位:L231
- 返回类型:InteractionResult
- 修饰符:private static
参数:
- state: BlockState
- level: Level
- pos: BlockPos
- player: Player
- hand: InteractionHand
- itemInHand: ItemStack
说明:
TODO
private static InteractionResult fillPowderSnowInteraction(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, ItemStack itemInHand) @ L237
- 方法名:fillPowderSnowInteraction
- 源码定位:L237
- 返回类型:InteractionResult
- 修饰符:private static
参数:
- state: BlockState
- level: Level
- pos: BlockPos
- player: Player
- hand: InteractionHand
- itemInHand: ItemStack
说明:
TODO
private static InteractionResult shulkerBoxInteraction(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, ItemStack itemInHand) @ L253
- 方法名:shulkerBoxInteraction
- 源码定位:L253
- 返回类型:InteractionResult
- 修饰符:private static
参数:
- state: BlockState
- level: Level
- pos: BlockPos
- player: Player
- hand: InteractionHand
- itemInHand: ItemStack
说明:
TODO
private static InteractionResult bannerInteraction(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, ItemStack itemInHand) @ L271
- 方法名:bannerInteraction
- 源码定位:L271
- 返回类型:InteractionResult
- 修饰符:private static
参数:
- state: BlockState
- level: Level
- pos: BlockPos
- player: Player
- hand: InteractionHand
- itemInHand: ItemStack
说明:
TODO
private static InteractionResult dyedItemIteration(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, ItemStack itemInHand) @ L288
- 方法名:dyedItemIteration
- 源码定位:L288
- 返回类型:InteractionResult
- 修饰符:private static
参数:
- state: BlockState
- level: Level
- pos: BlockPos
- player: Player
- hand: InteractionHand
- itemInHand: ItemStack
说明:
TODO
private static boolean isUnderWater(Level level, BlockPos pos) @ L302
- 方法名:isUnderWater
- 源码定位:L302
- 返回类型:boolean
- 修饰符:private static
参数:
- level: Level
- pos: BlockPos
说明:
TODO
代码
public class CauldronInteractions {
private static final ExtraCodecs.LateBoundIdMapper<String, CauldronInteraction.Dispatcher> ID_MAPPER = new ExtraCodecs.LateBoundIdMapper<>();
public static final Codec<CauldronInteraction.Dispatcher> CODEC = ID_MAPPER.codec(Codec.STRING);
public static final CauldronInteraction.Dispatcher EMPTY = newDispatcher("empty");
public static final CauldronInteraction.Dispatcher WATER = newDispatcher("water");
public static final CauldronInteraction.Dispatcher LAVA = newDispatcher("lava");
public static final CauldronInteraction.Dispatcher POWDER_SNOW = newDispatcher("powder_snow");
private static CauldronInteraction.Dispatcher newDispatcher(String name) {
CauldronInteraction.Dispatcher result = new CauldronInteraction.Dispatcher();
ID_MAPPER.put(name, result);
return result;
}
public static void bootStrap() {
addDefaultInteractions(EMPTY);
EMPTY.put(Items.POTION, (var0, level, pos, player, hand, itemInHand) -> {
PotionContents potion = itemInHand.get(DataComponents.POTION_CONTENTS);
if (potion != null && potion.is(Potions.WATER)) {
if (!level.isClientSide()) {
Item usedItem = itemInHand.getItem();
player.setItemInHand(hand, ItemUtils.createFilledResult(itemInHand, player, new ItemStack(Items.GLASS_BOTTLE)));
player.awardStat(Stats.USE_CAULDRON);
player.awardStat(Stats.ITEM_USED.get(usedItem));
level.setBlockAndUpdate(pos, Blocks.WATER_CAULDRON.defaultBlockState());
level.playSound(null, pos, SoundEvents.BOTTLE_EMPTY, SoundSource.BLOCKS, 1.0F, 1.0F);
level.gameEvent(null, GameEvent.FLUID_PLACE, pos);
}
return InteractionResult.SUCCESS;
} else {
return InteractionResult.TRY_WITH_EMPTY_HAND;
}
});
addDefaultInteractions(WATER);
WATER.put(
Items.BUCKET,
(state, level, pos, player, hand, itemInHand) -> fillBucket(
state,
level,
pos,
player,
hand,
itemInHand,
new ItemStack(Items.WATER_BUCKET),
s -> s.getValue(LayeredCauldronBlock.LEVEL) == 3,
SoundEvents.BUCKET_FILL
)
);
WATER.put(Items.GLASS_BOTTLE, (state, level, pos, player, hand, itemInHand) -> {
if (!level.isClientSide()) {
Item usedItem = itemInHand.getItem();
player.setItemInHand(hand, ItemUtils.createFilledResult(itemInHand, player, PotionContents.createItemStack(Items.POTION, Potions.WATER)));
player.awardStat(Stats.USE_CAULDRON);
player.awardStat(Stats.ITEM_USED.get(usedItem));
LayeredCauldronBlock.lowerFillLevel(state, level, pos);
level.playSound(null, pos, SoundEvents.BOTTLE_FILL, SoundSource.BLOCKS, 1.0F, 1.0F);
level.gameEvent(null, GameEvent.FLUID_PICKUP, pos);
}
return InteractionResult.SUCCESS;
});
WATER.put(Items.POTION, (state, level, pos, player, hand, itemInHand) -> {
if (state.getValue(LayeredCauldronBlock.LEVEL) == 3) {
return InteractionResult.TRY_WITH_EMPTY_HAND;
} else {
PotionContents potion = itemInHand.get(DataComponents.POTION_CONTENTS);
if (potion != null && potion.is(Potions.WATER)) {
if (!level.isClientSide()) {
player.setItemInHand(hand, ItemUtils.createFilledResult(itemInHand, player, new ItemStack(Items.GLASS_BOTTLE)));
player.awardStat(Stats.USE_CAULDRON);
player.awardStat(Stats.ITEM_USED.get(itemInHand.getItem()));
level.setBlockAndUpdate(pos, state.cycle(LayeredCauldronBlock.LEVEL));
level.playSound(null, pos, SoundEvents.BOTTLE_EMPTY, SoundSource.BLOCKS, 1.0F, 1.0F);
level.gameEvent(null, GameEvent.FLUID_PLACE, pos);
}
return InteractionResult.SUCCESS;
} else {
return InteractionResult.TRY_WITH_EMPTY_HAND;
}
}
});
WATER.put(ItemTags.CAULDRON_CAN_REMOVE_DYE, CauldronInteractions::dyedItemIteration);
WATER.put(Items.WHITE_BANNER, CauldronInteractions::bannerInteraction);
WATER.put(Items.GRAY_BANNER, CauldronInteractions::bannerInteraction);
WATER.put(Items.BLACK_BANNER, CauldronInteractions::bannerInteraction);
WATER.put(Items.BLUE_BANNER, CauldronInteractions::bannerInteraction);
WATER.put(Items.BROWN_BANNER, CauldronInteractions::bannerInteraction);
WATER.put(Items.CYAN_BANNER, CauldronInteractions::bannerInteraction);
WATER.put(Items.GREEN_BANNER, CauldronInteractions::bannerInteraction);
WATER.put(Items.LIGHT_BLUE_BANNER, CauldronInteractions::bannerInteraction);
WATER.put(Items.LIGHT_GRAY_BANNER, CauldronInteractions::bannerInteraction);
WATER.put(Items.LIME_BANNER, CauldronInteractions::bannerInteraction);
WATER.put(Items.MAGENTA_BANNER, CauldronInteractions::bannerInteraction);
WATER.put(Items.ORANGE_BANNER, CauldronInteractions::bannerInteraction);
WATER.put(Items.PINK_BANNER, CauldronInteractions::bannerInteraction);
WATER.put(Items.PURPLE_BANNER, CauldronInteractions::bannerInteraction);
WATER.put(Items.RED_BANNER, CauldronInteractions::bannerInteraction);
WATER.put(Items.YELLOW_BANNER, CauldronInteractions::bannerInteraction);
WATER.put(Items.WHITE_SHULKER_BOX, CauldronInteractions::shulkerBoxInteraction);
WATER.put(Items.GRAY_SHULKER_BOX, CauldronInteractions::shulkerBoxInteraction);
WATER.put(Items.BLACK_SHULKER_BOX, CauldronInteractions::shulkerBoxInteraction);
WATER.put(Items.BLUE_SHULKER_BOX, CauldronInteractions::shulkerBoxInteraction);
WATER.put(Items.BROWN_SHULKER_BOX, CauldronInteractions::shulkerBoxInteraction);
WATER.put(Items.CYAN_SHULKER_BOX, CauldronInteractions::shulkerBoxInteraction);
WATER.put(Items.GREEN_SHULKER_BOX, CauldronInteractions::shulkerBoxInteraction);
WATER.put(Items.LIGHT_BLUE_SHULKER_BOX, CauldronInteractions::shulkerBoxInteraction);
WATER.put(Items.LIGHT_GRAY_SHULKER_BOX, CauldronInteractions::shulkerBoxInteraction);
WATER.put(Items.LIME_SHULKER_BOX, CauldronInteractions::shulkerBoxInteraction);
WATER.put(Items.MAGENTA_SHULKER_BOX, CauldronInteractions::shulkerBoxInteraction);
WATER.put(Items.ORANGE_SHULKER_BOX, CauldronInteractions::shulkerBoxInteraction);
WATER.put(Items.PINK_SHULKER_BOX, CauldronInteractions::shulkerBoxInteraction);
WATER.put(Items.PURPLE_SHULKER_BOX, CauldronInteractions::shulkerBoxInteraction);
WATER.put(Items.RED_SHULKER_BOX, CauldronInteractions::shulkerBoxInteraction);
WATER.put(Items.YELLOW_SHULKER_BOX, CauldronInteractions::shulkerBoxInteraction);
LAVA.put(
Items.BUCKET,
(state, level, pos, player, hand, itemInHand) -> fillBucket(
state, level, pos, player, hand, itemInHand, new ItemStack(Items.LAVA_BUCKET), var0x -> true, SoundEvents.BUCKET_FILL_LAVA
)
);
addDefaultInteractions(LAVA);
POWDER_SNOW.put(
Items.BUCKET,
(state, level, pos, player, hand, itemInHand) -> fillBucket(
state,
level,
pos,
player,
hand,
itemInHand,
new ItemStack(Items.POWDER_SNOW_BUCKET),
s -> s.getValue(LayeredCauldronBlock.LEVEL) == 3,
SoundEvents.BUCKET_FILL_POWDER_SNOW
)
);
addDefaultInteractions(POWDER_SNOW);
}
static void addDefaultInteractions(CauldronInteraction.Dispatcher interactionMap) {
interactionMap.put(Items.LAVA_BUCKET, CauldronInteractions::fillLavaInteraction);
interactionMap.put(Items.WATER_BUCKET, CauldronInteractions::fillWaterInteraction);
interactionMap.put(Items.POWDER_SNOW_BUCKET, CauldronInteractions::fillPowderSnowInteraction);
}
static InteractionResult fillBucket(
BlockState state,
Level level,
BlockPos pos,
Player player,
InteractionHand hand,
ItemStack itemInHand,
ItemStack newItem,
Predicate<BlockState> canFill,
SoundEvent soundEvent
) {
if (!canFill.test(state)) {
return InteractionResult.TRY_WITH_EMPTY_HAND;
} else {
if (!level.isClientSide()) {
Item itemUsed = itemInHand.getItem();
player.setItemInHand(hand, ItemUtils.createFilledResult(itemInHand, player, newItem));
player.awardStat(Stats.USE_CAULDRON);
player.awardStat(Stats.ITEM_USED.get(itemUsed));
level.setBlockAndUpdate(pos, Blocks.CAULDRON.defaultBlockState());
level.playSound(null, pos, soundEvent, SoundSource.BLOCKS, 1.0F, 1.0F);
level.gameEvent(null, GameEvent.FLUID_PICKUP, pos);
}
return InteractionResult.SUCCESS;
}
}
static InteractionResult emptyBucket(
Level level, BlockPos pos, Player player, InteractionHand hand, ItemStack itemInHand, BlockState newState, SoundEvent soundEvent
) {
if (!level.isClientSide()) {
Item itemUsed = itemInHand.getItem();
player.setItemInHand(hand, ItemUtils.createFilledResult(itemInHand, player, new ItemStack(Items.BUCKET)));
player.awardStat(Stats.FILL_CAULDRON);
player.awardStat(Stats.ITEM_USED.get(itemUsed));
level.setBlockAndUpdate(pos, newState);
level.playSound(null, pos, soundEvent, SoundSource.BLOCKS, 1.0F, 1.0F);
level.gameEvent(null, GameEvent.FLUID_PLACE, pos);
}
return InteractionResult.SUCCESS;
}
private static InteractionResult fillWaterInteraction(
BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, ItemStack itemInHand
) {
return emptyBucket(
level, pos, player, hand, itemInHand, Blocks.WATER_CAULDRON.defaultBlockState().setValue(LayeredCauldronBlock.LEVEL, 3), SoundEvents.BUCKET_EMPTY
);
}
private static InteractionResult fillLavaInteraction(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, ItemStack itemInHand) {
return (InteractionResult)(isUnderWater(level, pos)
? InteractionResult.CONSUME
: emptyBucket(level, pos, player, hand, itemInHand, Blocks.LAVA_CAULDRON.defaultBlockState(), SoundEvents.BUCKET_EMPTY_LAVA));
}
private static InteractionResult fillPowderSnowInteraction(
BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, ItemStack itemInHand
) {
return (InteractionResult)(isUnderWater(level, pos)
? InteractionResult.CONSUME
: emptyBucket(
level,
pos,
player,
hand,
itemInHand,
Blocks.POWDER_SNOW_CAULDRON.defaultBlockState().setValue(LayeredCauldronBlock.LEVEL, 3),
SoundEvents.BUCKET_EMPTY_POWDER_SNOW
));
}
private static InteractionResult shulkerBoxInteraction(
BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, ItemStack itemInHand
) {
Block block = Block.byItem(itemInHand.getItem());
if (!(block instanceof ShulkerBoxBlock)) {
return InteractionResult.TRY_WITH_EMPTY_HAND;
} else {
if (!level.isClientSide()) {
ItemStack cleanedShulkerBox = itemInHand.transmuteCopy(Blocks.SHULKER_BOX, 1);
player.setItemInHand(hand, ItemUtils.createFilledResult(itemInHand, player, cleanedShulkerBox, false));
player.awardStat(Stats.CLEAN_SHULKER_BOX);
LayeredCauldronBlock.lowerFillLevel(state, level, pos);
}
return InteractionResult.SUCCESS;
}
}
private static InteractionResult bannerInteraction(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, ItemStack itemInHand) {
BannerPatternLayers patterns = itemInHand.getOrDefault(DataComponents.BANNER_PATTERNS, BannerPatternLayers.EMPTY);
if (patterns.layers().isEmpty()) {
return InteractionResult.TRY_WITH_EMPTY_HAND;
} else {
if (!level.isClientSide()) {
ItemStack cleanedBanner = itemInHand.copyWithCount(1);
cleanedBanner.set(DataComponents.BANNER_PATTERNS, patterns.removeLast());
player.setItemInHand(hand, ItemUtils.createFilledResult(itemInHand, player, cleanedBanner, false));
player.awardStat(Stats.CLEAN_BANNER);
LayeredCauldronBlock.lowerFillLevel(state, level, pos);
}
return InteractionResult.SUCCESS;
}
}
private static InteractionResult dyedItemIteration(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, ItemStack itemInHand) {
if (!itemInHand.has(DataComponents.DYED_COLOR)) {
return InteractionResult.TRY_WITH_EMPTY_HAND;
} else {
if (!level.isClientSide()) {
itemInHand.remove(DataComponents.DYED_COLOR);
player.awardStat(Stats.CLEAN_ARMOR);
LayeredCauldronBlock.lowerFillLevel(state, level, pos);
}
return InteractionResult.SUCCESS;
}
}
private static boolean isUnderWater(Level level, BlockPos pos) {
FluidState fluidState = level.getFluidState(pos.above());
return fluidState.is(FluidTags.WATER);
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/字段/方法调用/构造调用/返回值 - 关联成员:
CauldronInteraction.Dispatcher(), Dispatcher()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
字段
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/构造调用 - 关联成员:
ItemStack()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ItemUtils.createFilledResult()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
PotionContents.createItemStack()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Block.byItem()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
LayeredCauldronBlock.lowerFillLevel()
- 引用位置:
-
- 引用位置:
参数
- 引用位置: