-
Notifications
You must be signed in to change notification settings - Fork 207
Expand file tree
/
Copy pathItemFlutterPot.java
More file actions
67 lines (58 loc) · 2.69 KB
/
ItemFlutterPot.java
File metadata and controls
67 lines (58 loc) · 2.69 KB
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
package com.github.alexthe666.alexsmobs.item;
import com.github.alexthe666.alexsmobs.entity.AMEntityRegistry;
import com.github.alexthe666.alexsmobs.entity.EntityFlutter;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.DispensibleContainerItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.phys.BlockHitResult;
import javax.annotation.Nullable;
public class ItemFlutterPot extends Item implements DispensibleContainerItem {
public ItemFlutterPot(Properties builder) {
super(builder.stacksTo(1));
}
@Override
public InteractionResult useOn(UseOnContext context) {
Level world = context.getLevel();
BlockPos blockpos = context.getClickedPos();
if(!world.isClientSide){
if(this.placePot((ServerLevel)world, context.getItemInHand(), blockpos,context.getPlayer()) && (context.getPlayer() == null || !context.getPlayer().isCreative())){
context.getItemInHand().shrink(1);
}
return InteractionResult.sidedSuccess(world.isClientSide);
}else{
return InteractionResult.PASS;
}
}
protected void playEmptySound(@Nullable Player player, LevelAccessor worldIn, BlockPos pos) {
worldIn.playSound(player, pos, SoundEvents.BUCKET_EMPTY_FISH, SoundSource.NEUTRAL, 1.0F, 1.0F);
}
private boolean placePot(ServerLevel worldIn, ItemStack stack, BlockPos pos, Player player) {
EntityFlutter entity = AMEntityRegistry.FLUTTER.get().spawn(worldIn, stack, (Player)null, pos, MobSpawnType.BUCKET, true, false);
if (entity instanceof EntityFlutter) {
CompoundTag compoundnbt = stack.getOrCreateTag();
if(compoundnbt.contains("FlutterData")){
entity.readAdditionalSaveData(compoundnbt.getCompound("FlutterData"));
} else {
entity.setPotted(true);
}
return true;
}
return false;
}
@Override
public boolean emptyContents(@org.jetbrains.annotations.Nullable Player p_150821_, Level p_150822_, BlockPos p_150823_, @org.jetbrains.annotations.Nullable BlockHitResult p_150824_) {
return false;
}
}