1
1
package com .samsthenerd .hexgloop .blockentities ;
2
2
3
+ import javax .annotation .Nullable ;
4
+
3
5
import com .samsthenerd .hexgloop .HexGloop ;
4
6
import com .samsthenerd .hexgloop .blocks .BlockIoticDial ;
5
7
import com .samsthenerd .hexgloop .blocks .iotic .IIoticProvider ;
8
+ import com .samsthenerd .hexgloop .items .ItemMultiFocus ;
6
9
7
10
import at .petrak .hexcasting .api .addldata .ADIotaHolder ;
8
11
import at .petrak .hexcasting .common .items .ItemSpellbook ;
11
14
import net .minecraft .block .entity .BlockEntity ;
12
15
import net .minecraft .item .ItemStack ;
13
16
import net .minecraft .nbt .NbtCompound ;
17
+ import net .minecraft .network .Packet ;
18
+ import net .minecraft .network .listener .ClientPlayPacketListener ;
19
+ import net .minecraft .network .packet .s2c .play .BlockEntityUpdateS2CPacket ;
20
+ import net .minecraft .server .world .ServerWorld ;
14
21
import net .minecraft .util .math .BlockPos ;
22
+ import net .minecraft .util .math .MathHelper ;
15
23
import net .minecraft .world .World ;
16
24
17
25
public class BlockEntityDial extends BlockEntity implements IIoticProvider {
@@ -40,12 +48,19 @@ public void setInnerMultiFocus(ItemStack innerMultiFocus) {
40
48
}
41
49
42
50
public void setSelection (int selection ){
51
+ selection = MathHelper .clamp (selection , 0 , 6 );
43
52
BlockState old = world .getBlockState (pos );
44
53
world .setBlockState (pos , old .with (BlockIoticDial .SELECTED , selection ));
45
- // TODO: update the inner multi focus too
54
+ if (selection != 0 ){
55
+ ItemMultiFocus .setPageIdx (innerMultiFocus , selection );
56
+ }
46
57
markDirty ();
47
58
}
48
59
60
+ public int getSelection (){
61
+ return world .getBlockState (pos ).get (BlockIoticDial .SELECTED );
62
+ }
63
+
49
64
// TODO: wrap this so we can get a hook when the iota is changed
50
65
public ADIotaHolder getIotaHolder (World world , BlockPos pos ){
51
66
return IXplatAbstractions .INSTANCE .findDataHolder (innerMultiFocus );
@@ -60,4 +75,25 @@ protected void writeNbt(NbtCompound nbt) {
60
75
super .writeNbt (nbt );
61
76
nbt .put ("innerMultiFocus" , innerMultiFocus .writeNbt (new NbtCompound ()));
62
77
}
78
+
79
+ @ Override
80
+ public void markDirty () {
81
+ if (world instanceof ServerWorld sWorld ) {
82
+ sWorld .getChunkManager ().markForUpdate (pos );
83
+ }
84
+ super .markDirty ();
85
+ }
86
+
87
+ @ Override
88
+ public NbtCompound toInitialChunkDataNbt () {
89
+ NbtCompound tag = new NbtCompound ();
90
+ this .writeNbt (tag );
91
+ return tag ;
92
+ }
93
+
94
+ @ Override
95
+ @ Nullable
96
+ public Packet <ClientPlayPacketListener > toUpdatePacket () {
97
+ return BlockEntityUpdateS2CPacket .create (this );
98
+ }
63
99
}
0 commit comments