1
1
package ace .actually .pirates .blocks .entity ;
2
2
3
- import ace .actually .pirates .blocks .MotionInvokingBlock ;
4
3
import ace .actually .pirates .util .ConfigUtils ;
4
+ import ace .actually .pirates .util .EurekaCompat ;
5
5
import ace .actually .pirates .util .PatternProcessor ;
6
6
import ace .actually .pirates .Pirates ;
7
- import net .minecraft .block .Block ;
8
7
import net .minecraft .block .BlockState ;
9
- import net .minecraft .block .Blocks ;
10
8
import net .minecraft .block .entity .BlockEntity ;
11
9
import net .minecraft .nbt .NbtCompound ;
12
10
import net .minecraft .nbt .NbtList ;
13
- import net .minecraft .registry .tag .BlockTags ;
14
11
import net .minecraft .server .world .ServerWorld ;
15
- import net .minecraft .util .BlockRotation ;
16
12
import net .minecraft .util .math .BlockPos ;
17
13
import net .minecraft .util .math .ChunkPos ;
18
- import net .minecraft .util .math .Vec3d ;
19
14
import net .minecraft .world .World ;
20
- import org .joml .Quaterniondc ;
21
15
import org .joml .Vector3d ;
22
16
import org .joml .Vector3dc ;
23
- import org .joml .Vector3i ;
24
17
import org .valkyrienskies .core .api .ships .LoadedServerShip ;
25
- import org .valkyrienskies .core .api .ships .ServerShip ;
26
18
import org .valkyrienskies .core .api .ships .Ship ;
27
- import org .valkyrienskies .core .util .datastructures .DenseBlockPosSet ;
28
19
import org .valkyrienskies .eureka .block .ShipHelmBlock ;
29
- import org .valkyrienskies .eureka .ship .EurekaShipControl ;
30
- import org .valkyrienskies .eureka .util .ShipAssembler ;
31
20
import org .valkyrienskies .mod .api .SeatedControllingPlayer ;
32
21
import org .valkyrienskies .mod .common .VSGameUtilsKt ;
33
- import org .valkyrienskies .mod .common .ValkyrienSkiesMod ;
34
- import org .valkyrienskies .mod .common .assembly .ShipAssemblyKt ;
35
- import org .valkyrienskies .mod .common .util .DimensionIdProvider ;
36
22
import org .valkyrienskies .mod .common .util .GameTickForceApplier ;
37
- import org .valkyrienskies .mod .common .util .VectorConversionsMCKt ;
38
- import org .valkyrienskies .mod .util .RelocationUtilKt ;
39
23
40
24
import java .util .List ;
41
25
44
28
public class MotionInvokingBlockEntity extends BlockEntity {
45
29
NbtList instructions = new NbtList ();
46
30
long nextInstruction = 0 ;
31
+ String compat = "Eureka" ;
32
+
33
+ //variables below this line aren't serialised because they don't need to be.
34
+ int [] target = new int [3 ]; //x,y,z of a point in space that the ship is "trying" to get to.
35
+ double ldx = -1 ; //last distance tracked along the x axis, from the target
36
+ double ldz = -1 ; //last distance tracked along the z axis, from the target
47
37
48
38
public NbtList getInstructions () {return instructions ;}
49
39
public void setNextInstruction (long nextInstruction ) {this .nextInstruction = nextInstruction ;}
@@ -55,7 +45,10 @@ public MotionInvokingBlockEntity(BlockPos pos, BlockState state) {
55
45
super (Pirates .MOTION_INVOKING_BLOCK_ENTITY , pos , state );
56
46
}
57
47
58
-
48
+ public void setCompat (String compat ) {
49
+ this .compat = compat ;
50
+ markDirty ();
51
+ }
59
52
60
53
public static void tick (World world , BlockPos pos , BlockState state , MotionInvokingBlockEntity be ) {
61
54
@@ -87,8 +80,6 @@ public static void tick(World world, BlockPos pos, BlockState state, MotionInvok
87
80
ChunkPos chunkPos = world .getChunk (pos ).getPos ();
88
81
LoadedServerShip ship = VSGameUtilsKt .getShipObjectManagingPos ((ServerWorld ) world , chunkPos );
89
82
90
- //Pirates.LOGGER.info("scaling of ship: "+s.x()+" "+s.y()+" "+s.z());
91
-
92
83
if (ship != null ) {
93
84
SeatedControllingPlayer seatedControllingPlayer = ship .getAttachment (SeatedControllingPlayer .class );
94
85
if (seatedControllingPlayer == null ) {
@@ -100,10 +91,6 @@ public static void tick(World world, BlockPos pos, BlockState state, MotionInvok
100
91
ship .setAttachment (SeatedControllingPlayer .class , seatedControllingPlayer );
101
92
}
102
93
103
-
104
- //Pirates.LOGGER.info(be.instructions.getString(0));
105
- //be.utiliseInternalPattern(seatedControllingPlayer, be);
106
- //be.moveShipForward(ship);
107
94
if (world .getTimeOfDay ()%updateTicks ==0 )
108
95
{
109
96
List <Ship > ships = VSGameUtilsKt .getAllShips (world ).stream ().filter (a ->
@@ -120,7 +107,12 @@ public static void tick(World world, BlockPos pos, BlockState state, MotionInvok
120
107
}
121
108
}
122
109
123
- be .moveTowards (seatedControllingPlayer ,ship );
110
+ switch (be .compat )
111
+ {
112
+ case "Eureka" -> EurekaCompat .moveTowards (be ,seatedControllingPlayer ,ship );
113
+ default -> be .moveShipForward (ship );
114
+ }
115
+
124
116
125
117
}
126
118
}
@@ -133,6 +125,7 @@ protected void writeNbt(NbtCompound nbt) {
133
125
nbt .putLong ("nextInstruction" , nextInstruction );
134
126
nbt .put ("instructions" , instructions );
135
127
nbt .putIntArray ("target" ,target );
128
+ nbt .putString ("compat" ,compat );
136
129
super .writeNbt (nbt );
137
130
}
138
131
@@ -141,6 +134,10 @@ public void readNbt(NbtCompound nbt) {
141
134
super .readNbt (nbt );
142
135
instructions = (NbtList ) nbt .get ("instructions" );
143
136
nextInstruction = nbt .getLong ("nextInstruction" );
137
+ if (nbt .contains ("compat" ))
138
+ {
139
+ compat = nbt .getString ("compat" );
140
+ }
144
141
if (nbt .contains ("target" ))
145
142
{
146
143
target = nbt .getIntArray ("target" );
@@ -160,61 +157,44 @@ public void setTarget(int[] target) {
160
157
markDirty ();
161
158
}
162
159
163
- int [] target = new int [3 ];
164
- double ldx = -1 ;
165
- double ldz = -1 ;
166
- int flipflop = 1 ;
167
160
168
- private void moveTowards (SeatedControllingPlayer power , LoadedServerShip ship )
169
- {
170
- if (target .length !=3 ) return ;
171
161
172
- power .setForwardImpulse (1 );
173
- Vector3dc v3d = ship .getTransform ().getPositionInWorld ();
174
- if (ldx ==-1 )
175
- {
176
- //lastDistance = v3d.distanceSquared(target[0],target[1],target[2]);
177
- ldx = vdis (target [0 ],v3d .x ());
178
- ldz = vdis (target [2 ],v3d .z ());
179
- }
180
- else
181
- {
182
- //double currentDistance = v3d.distanceSquared(target[0],target[1],target[2]);
183
- double cdx = vdis (target [0 ],v3d .x ());
184
- double cdz = vdis (target [2 ],v3d .z ());
185
- //System.out.println(lastDistance+" -> "+currentDistance);
186
- if (cdx >=ldx || cdz >=ldz )
187
- {
188
- power .setLeftImpulse (flipflop );
162
+ public int [] getTarget () {
163
+ return target ;
164
+ }
189
165
190
- }
191
- else
192
- {
193
- power .setLeftImpulse (0 );
194
- flipflop = -flipflop ;
195
- }
196
- ldx =cdx ;
197
- ldz =cdz ;
198
- }
166
+ public double getLdx () {
167
+ return ldx ;
168
+ }
199
169
170
+ public double getLdz () {
171
+ return ldz ;
200
172
}
201
173
202
- private double vdis (double x , double xto ) {
203
- return Math . abs ( x - xto ) ;
174
+ public void setLdx (double ldx ) {
175
+ this . ldx = ldx ;
204
176
}
205
177
178
+ public void setLdz (double ldz ) {
179
+ this .ldz = ldz ;
180
+ }
181
+
182
+
183
+ /**
184
+ * This method uses bases VS things to effectively create circles.
185
+ * the circles arent very good. TODO: Make the circles good
186
+ * @param ship
187
+ */
206
188
private void moveShipForward (LoadedServerShip ship )
207
189
{
208
190
double mass = ship .getInertiaData ().getMass ();
209
- Vector3d qdc = ship .getTransform ().getShipToWorldRotation ().getEulerAnglesZXY (new Vector3d ()).mul (mass *100 );
191
+ Vector3d qdc = ship .getTransform ().getShipToWorldRotation ().getEulerAnglesZXY (new Vector3d ()).normalize (). mul (mass *500 );
210
192
qdc = new Vector3d (qdc .x ,0 ,qdc .z );
211
- //qdc = qdc.rotateY(-Math.PI);
212
193
GameTickForceApplier gtfa = ship .getAttachment (GameTickForceApplier .class );
213
194
if (gtfa !=null )
214
195
{
215
- Vector3d loc = new Vector3d (pos .getX ()- 1 ,pos .getY ()+ 0.3 ,pos .getZ ()- 1 ).sub (ship .getTransform ().getPositionInShip ());
196
+ Vector3d loc = new Vector3d (pos .getX (),pos .getY (),pos .getZ ()).sub (ship .getTransform ().getPositionInShip ());
216
197
gtfa .applyInvariantForceToPos (qdc ,loc );
217
- //gtfa.applyInvariantForce(qdc);
218
198
}
219
199
}
220
200
}
0 commit comments