|
1
|
|
|
package de.pewpewproject.lasertag.block.entity; |
|
2
|
|
|
|
|
3
|
|
|
import de.pewpewproject.lasertag.block.LasertagFlagBlock; |
|
4
|
|
|
import de.pewpewproject.lasertag.entity.Entities; |
|
5
|
|
|
import net.minecraft.block.BlockState; |
|
6
|
|
|
import net.minecraft.block.entity.BlockEntity; |
|
7
|
|
|
import net.minecraft.block.enums.DoubleBlockHalf; |
|
8
|
|
|
import net.minecraft.nbt.NbtCompound; |
|
9
|
|
|
import net.minecraft.network.Packet; |
|
10
|
|
|
import net.minecraft.network.listener.ClientPlayPacketListener; |
|
11
|
|
|
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket; |
|
12
|
|
|
import net.minecraft.util.math.BlockPos; |
|
13
|
|
|
import org.jetbrains.annotations.Nullable; |
|
14
|
|
|
import software.bernie.geckolib3.core.IAnimatable; |
|
15
|
|
|
import software.bernie.geckolib3.core.PlayState; |
|
16
|
|
|
import software.bernie.geckolib3.core.controller.AnimationController; |
|
17
|
|
|
import software.bernie.geckolib3.core.event.predicate.AnimationEvent; |
|
18
|
|
|
import software.bernie.geckolib3.core.manager.AnimationData; |
|
19
|
|
|
import software.bernie.geckolib3.core.manager.AnimationFactory; |
|
20
|
|
|
import software.bernie.geckolib3.util.GeckoLibUtil; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Block entity for the lasertag flag |
|
24
|
|
|
* |
|
25
|
|
|
* @author Étienne Muser |
|
26
|
|
|
*/ |
|
27
|
|
|
public class LasertagFlagBlockEntity extends BlockEntity implements IAnimatable { |
|
28
|
|
|
|
|
29
|
|
|
private final AnimationFactory animationFactory = GeckoLibUtil.createFactory(this); |
|
30
|
|
|
|
|
31
|
|
|
public static final String TEAM_NAME_NBT_KEY = "teamName"; |
|
32
|
|
|
|
|
33
|
|
|
private String teamName = ""; |
|
34
|
|
|
private final DoubleBlockHalf half; |
|
35
|
|
|
|
|
36
|
|
|
public LasertagFlagBlockEntity(BlockPos pos, BlockState state) { |
|
37
|
|
|
super(Entities.LASERTAG_FLAG_BLOCK_ENTITY, pos, state); |
|
38
|
|
|
|
|
39
|
|
|
this.half = state.get(LasertagFlagBlock.HALF); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
@Override |
|
43
|
|
|
protected void writeNbt(NbtCompound nbt) { |
|
44
|
|
|
|
|
45
|
|
|
nbt.putString(TEAM_NAME_NBT_KEY, this.teamName); |
|
46
|
|
|
|
|
47
|
|
|
super.writeNbt(nbt); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
@Override |
|
51
|
|
|
public void readNbt(NbtCompound nbt) { |
|
52
|
|
|
super.readNbt(nbt); |
|
53
|
|
|
|
|
54
|
|
|
this.teamName = nbt.getString(TEAM_NAME_NBT_KEY); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
@Nullable |
|
58
|
|
|
@Override |
|
59
|
|
|
public Packet<ClientPlayPacketListener> toUpdatePacket() { |
|
60
|
|
|
return BlockEntityUpdateS2CPacket.create(this); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
@Override |
|
64
|
|
|
public NbtCompound toInitialChunkDataNbt() { |
|
65
|
|
|
return createNbt(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public String getTeamName() { |
|
69
|
|
|
return this.teamName; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public void setTeamName(String newTeamName) { |
|
73
|
|
|
this.teamName = newTeamName; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public DoubleBlockHalf getHalf() { |
|
77
|
|
|
return this.half; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
private <P extends IAnimatable> PlayState predicate(AnimationEvent<P> event) { |
|
81
|
|
|
return PlayState.CONTINUE; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
@Override |
|
85
|
|
|
public void registerControllers(AnimationData animationData) { |
|
86
|
|
|
animationData.addAnimationController(new AnimationController(this, "controller", 16, this::predicate)); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
@Override |
|
90
|
|
|
public AnimationFactory getFactory() { |
|
91
|
|
|
return this.animationFactory; |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|