Skip to content

Commit c3a6289

Browse files
committed
making motion possible to be independent of eureka, although right now you still need eureka for the new ai. also made the shot entity use its stored data properly
1 parent e5a417b commit c3a6289

File tree

5 files changed

+114
-68
lines changed

5 files changed

+114
-68
lines changed

src/main/java/ace/actually/pirates/blocks/DispenserCannonBlock.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected DispenserBehavior getBehaviorForItem(ItemStack stack) {
3232
return new CannonDispenserBehavior() {
3333
@Override
3434
protected ProjectileEntity createProjectile(World world, Position position, ItemStack stack) {
35-
ShotEntity qentity = Util.make(new ShotEntity(Pirates.SHOT_ENTITY_TYPE,world,null,Pirates.CANNONBALL_ENT,2,""), (entity) -> {});
35+
ShotEntity qentity = Util.make(new ShotEntity(Pirates.SHOT_ENTITY_TYPE,world,null,Pirates.CANNONBALL_ENT,6,""), (entity) -> {});
3636
qentity.setPosition(new Vec3d(position.getX(),position.getY(),position.getZ()));
3737
return qentity;
3838
}

src/main/java/ace/actually/pirates/blocks/MotionInvokingBlock.java

+15
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@
66
import net.minecraft.block.entity.BlockEntity;
77
import net.minecraft.block.entity.BlockEntityTicker;
88
import net.minecraft.block.entity.BlockEntityType;
9+
import net.minecraft.entity.player.PlayerEntity;
10+
import net.minecraft.item.Item;
911
import net.minecraft.item.ItemStack;
12+
import net.minecraft.item.Items;
1013
import net.minecraft.server.world.ServerWorld;
1114
import net.minecraft.sound.SoundCategory;
1215
import net.minecraft.sound.SoundEvents;
16+
import net.minecraft.util.ActionResult;
17+
import net.minecraft.util.Hand;
18+
import net.minecraft.util.hit.BlockHitResult;
1319
import net.minecraft.util.math.BlockPos;
1420
import net.minecraft.util.math.ChunkPos;
1521
import net.minecraft.world.World;
@@ -27,6 +33,15 @@ public MotionInvokingBlock(Settings settings) {
2733

2834
}
2935

36+
@Override
37+
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
38+
if(world instanceof ServerWorld serverWorld && player.getStackInHand(hand).isOf(Items.DEBUG_STICK))
39+
{
40+
MotionInvokingBlockEntity be = (MotionInvokingBlockEntity) serverWorld.getBlockEntity(pos);
41+
be.setCompat("None");
42+
}
43+
return super.onUse(state, world, pos, player, hand, hit);
44+
}
3045

3146
@Nullable
3247
@Override
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,25 @@
11
package ace.actually.pirates.blocks.entity;
22

3-
import ace.actually.pirates.blocks.MotionInvokingBlock;
43
import ace.actually.pirates.util.ConfigUtils;
4+
import ace.actually.pirates.util.EurekaCompat;
55
import ace.actually.pirates.util.PatternProcessor;
66
import ace.actually.pirates.Pirates;
7-
import net.minecraft.block.Block;
87
import net.minecraft.block.BlockState;
9-
import net.minecraft.block.Blocks;
108
import net.minecraft.block.entity.BlockEntity;
119
import net.minecraft.nbt.NbtCompound;
1210
import net.minecraft.nbt.NbtList;
13-
import net.minecraft.registry.tag.BlockTags;
1411
import net.minecraft.server.world.ServerWorld;
15-
import net.minecraft.util.BlockRotation;
1612
import net.minecraft.util.math.BlockPos;
1713
import net.minecraft.util.math.ChunkPos;
18-
import net.minecraft.util.math.Vec3d;
1914
import net.minecraft.world.World;
20-
import org.joml.Quaterniondc;
2115
import org.joml.Vector3d;
2216
import org.joml.Vector3dc;
23-
import org.joml.Vector3i;
2417
import org.valkyrienskies.core.api.ships.LoadedServerShip;
25-
import org.valkyrienskies.core.api.ships.ServerShip;
2618
import org.valkyrienskies.core.api.ships.Ship;
27-
import org.valkyrienskies.core.util.datastructures.DenseBlockPosSet;
2819
import org.valkyrienskies.eureka.block.ShipHelmBlock;
29-
import org.valkyrienskies.eureka.ship.EurekaShipControl;
30-
import org.valkyrienskies.eureka.util.ShipAssembler;
3120
import org.valkyrienskies.mod.api.SeatedControllingPlayer;
3221
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;
3622
import org.valkyrienskies.mod.common.util.GameTickForceApplier;
37-
import org.valkyrienskies.mod.common.util.VectorConversionsMCKt;
38-
import org.valkyrienskies.mod.util.RelocationUtilKt;
3923

4024
import java.util.List;
4125

@@ -44,6 +28,12 @@
4428
public class MotionInvokingBlockEntity extends BlockEntity {
4529
NbtList instructions = new NbtList();
4630
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
4737

4838
public NbtList getInstructions() {return instructions;}
4939
public void setNextInstruction(long nextInstruction) {this.nextInstruction = nextInstruction;}
@@ -55,7 +45,10 @@ public MotionInvokingBlockEntity(BlockPos pos, BlockState state) {
5545
super(Pirates.MOTION_INVOKING_BLOCK_ENTITY, pos, state);
5646
}
5747

58-
48+
public void setCompat(String compat) {
49+
this.compat = compat;
50+
markDirty();
51+
}
5952

6053
public static void tick(World world, BlockPos pos, BlockState state, MotionInvokingBlockEntity be) {
6154

@@ -87,8 +80,6 @@ public static void tick(World world, BlockPos pos, BlockState state, MotionInvok
8780
ChunkPos chunkPos = world.getChunk(pos).getPos();
8881
LoadedServerShip ship = VSGameUtilsKt.getShipObjectManagingPos((ServerWorld) world, chunkPos);
8982

90-
//Pirates.LOGGER.info("scaling of ship: "+s.x()+" "+s.y()+" "+s.z());
91-
9283
if (ship != null) {
9384
SeatedControllingPlayer seatedControllingPlayer = ship.getAttachment(SeatedControllingPlayer.class);
9485
if (seatedControllingPlayer == null) {
@@ -100,10 +91,6 @@ public static void tick(World world, BlockPos pos, BlockState state, MotionInvok
10091
ship.setAttachment(SeatedControllingPlayer.class, seatedControllingPlayer);
10192
}
10293

103-
104-
//Pirates.LOGGER.info(be.instructions.getString(0));
105-
//be.utiliseInternalPattern(seatedControllingPlayer, be);
106-
//be.moveShipForward(ship);
10794
if(world.getTimeOfDay()%updateTicks==0)
10895
{
10996
List<Ship> ships = VSGameUtilsKt.getAllShips(world).stream().filter(a->
@@ -120,7 +107,12 @@ public static void tick(World world, BlockPos pos, BlockState state, MotionInvok
120107
}
121108
}
122109

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+
124116

125117
}
126118
}
@@ -133,6 +125,7 @@ protected void writeNbt(NbtCompound nbt) {
133125
nbt.putLong("nextInstruction", nextInstruction);
134126
nbt.put("instructions", instructions);
135127
nbt.putIntArray("target",target);
128+
nbt.putString("compat",compat);
136129
super.writeNbt(nbt);
137130
}
138131

@@ -141,6 +134,10 @@ public void readNbt(NbtCompound nbt) {
141134
super.readNbt(nbt);
142135
instructions = (NbtList) nbt.get("instructions");
143136
nextInstruction = nbt.getLong("nextInstruction");
137+
if(nbt.contains("compat"))
138+
{
139+
compat = nbt.getString("compat");
140+
}
144141
if(nbt.contains("target"))
145142
{
146143
target = nbt.getIntArray("target");
@@ -160,61 +157,44 @@ public void setTarget(int[] target) {
160157
markDirty();
161158
}
162159

163-
int[] target = new int[3];
164-
double ldx = -1;
165-
double ldz = -1;
166-
int flipflop = 1;
167160

168-
private void moveTowards(SeatedControllingPlayer power, LoadedServerShip ship)
169-
{
170-
if(target.length!=3) return;
171161

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+
}
189165

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+
}
199169

170+
public double getLdz() {
171+
return ldz;
200172
}
201173

202-
private double vdis(double x, double xto) {
203-
return Math.abs(x-xto);
174+
public void setLdx(double ldx) {
175+
this.ldx = ldx;
204176
}
205177

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+
*/
206188
private void moveShipForward(LoadedServerShip ship)
207189
{
208190
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);
210192
qdc = new Vector3d(qdc.x,0,qdc.z);
211-
//qdc = qdc.rotateY(-Math.PI);
212193
GameTickForceApplier gtfa = ship.getAttachment(GameTickForceApplier.class);
213194
if(gtfa!=null)
214195
{
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());
216197
gtfa.applyInvariantForceToPos(qdc,loc);
217-
//gtfa.applyInvariantForce(qdc);
218198
}
219199
}
220200
}

src/main/java/ace/actually/pirates/entities/shot/ShotEntity.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
public class ShotEntity extends ThrownItemEntity implements FlyingItemEntity {
2121
private LivingEntity in;
22-
private float damage=1;
22+
private float damage=6;
2323
private String extra="";
2424

2525

@@ -49,7 +49,7 @@ public void tick () {
4949
protected void onCollision(HitResult hitResult) {
5050
super.onCollision(hitResult);
5151
if (!this.getWorld().isClient) {
52-
this.getWorld().createExplosion(this, this.getX(), this.getY(), this.getZ(), 2.2f, false, World.ExplosionSourceType.BLOCK);
52+
this.getWorld().createExplosion(this, this.getX(), this.getY(), this.getZ(), 2.2f, extra.contains("fire"), World.ExplosionSourceType.TNT);
5353
this.discard();
5454
}
5555
}
@@ -58,7 +58,11 @@ protected void onCollision(HitResult hitResult) {
5858
protected void onEntityHit(EntityHitResult entityHitResult) {
5959
super.onEntityHit(entityHitResult);
6060
Entity entity = entityHitResult.getEntity();
61-
entity.damage(this.getDamageSources().explosion(null), 6.0f);
61+
entity.damage(this.getDamageSources().explosion(null), damage);
62+
if (!this.getWorld().isClient) {
63+
this.getWorld().createExplosion(this, this.getX(), this.getY(), this.getZ(), 2.2f, extra.contains("fire"), World.ExplosionSourceType.TNT);
64+
this.discard();
65+
}
6266
}
6367

6468
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package ace.actually.pirates.util;
2+
3+
import ace.actually.pirates.blocks.entity.MotionInvokingBlockEntity;
4+
import org.joml.Vector3dc;
5+
import org.valkyrienskies.core.api.ships.LoadedServerShip;
6+
import org.valkyrienskies.mod.api.SeatedControllingPlayer;
7+
8+
public class EurekaCompat {
9+
private static int flipflop = 1;
10+
public static void moveTowards(MotionInvokingBlockEntity be, SeatedControllingPlayer power, LoadedServerShip ship)
11+
{
12+
if(be.getTarget().length!=3) return;
13+
14+
power.setForwardImpulse(1);
15+
Vector3dc v3d = ship.getTransform().getPositionInWorld();
16+
if(be.getLdx()==-1)
17+
{
18+
//lastDistance = v3d.distanceSquared(target[0],target[1],target[2]);
19+
be.setLdx(vdis(be.getTarget()[0],v3d.x()));
20+
be.setLdz(vdis(be.getTarget()[2],v3d.z()));
21+
}
22+
else
23+
{
24+
//double currentDistance = v3d.distanceSquared(target[0],target[1],target[2]);
25+
double cdx = vdis(be.getTarget()[0],v3d.x());
26+
double cdz = vdis(be.getTarget()[2],v3d.z());
27+
//System.out.println(lastDistance+" -> "+currentDistance);
28+
if(cdx>=be.getLdx() || cdz>= be.getLdz())
29+
{
30+
power.setLeftImpulse(flipflop);
31+
32+
}
33+
else
34+
{
35+
power.setLeftImpulse(0);
36+
flipflop = -flipflop;
37+
}
38+
be.setLdx(cdx);
39+
be.setLdz(cdz);
40+
}
41+
42+
}
43+
44+
private static double vdis(double x, double xto) {
45+
return Math.abs(x-xto);
46+
}
47+
}

0 commit comments

Comments
 (0)