Skip to content

Commit 529362e

Browse files
committed
Start work on prepping for Hytale's Update 5
1 parent 767b329 commit 529362e

62 files changed

Lines changed: 341 additions & 271 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/main/java/com/github/skriptdev/skript/api/hytale/objects/Block.java

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import com.hypixel.hytale.component.Store;
77
import com.hypixel.hytale.math.util.ChunkUtil;
88
import com.hypixel.hytale.math.vector.Location;
9-
import com.hypixel.hytale.math.vector.Vector3i;
109
import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType;
1110
import com.hypixel.hytale.server.core.asset.type.blocktype.config.Rotation;
1211
import com.hypixel.hytale.server.core.asset.type.blocktype.config.RotationTuple;
@@ -29,6 +28,8 @@
2928
import io.github.syst3ms.skriptparser.util.color.Color;
3029
import org.jetbrains.annotations.NotNull;
3130
import org.jetbrains.annotations.Nullable;
31+
import org.joml.RoundingMode;
32+
import org.joml.Vector3i;
3233

3334
import java.util.Map;
3435
import java.util.function.Predicate;
@@ -55,11 +56,11 @@ public Block(@NotNull Location location) {
5556
if (world == null) {
5657
throw new IllegalArgumentException("World '" + location.getWorld() + "' not found.");
5758
}
58-
this(world, location.getPosition().toVector3i());
59+
this(world, new Vector3i(location.getPosition(), RoundingMode.FLOOR));
5960
}
6061

6162
public long getChunkIndex() {
62-
return ChunkUtil.indexChunkFromBlock(this.pos.getX(), this.pos.getZ());
63+
return ChunkUtil.indexChunkFromBlock(this.pos.x(), this.pos.z());
6364
}
6465

6566
public WorldChunk getChunk() {
@@ -72,7 +73,7 @@ public WorldChunk getChunk() {
7273
}
7374

7475
public void setType(@NotNull BlockType type, int settings) {
75-
Runnable r = () -> Block.this.world.setBlock(Block.this.pos.getX(), Block.this.pos.getY(), Block.this.pos.getZ(), type.getId(), settings);
76+
Runnable r = () -> Block.this.world.setBlock(Block.this.pos.x(), Block.this.pos.y(), Block.this.pos.z(), type.getId(), settings);
7677
if (this.world.isInThread()) {
7778
r.run();
7879
} else {
@@ -95,11 +96,11 @@ public void setRotation(Vector3i rotation) {
9596
BlockChunk blockChunk = chunk.getBlockChunk();
9697
if (blockChunk == null) return;
9798

98-
Rotation pitch = getRotationFromInt(rotation.getX());
99-
Rotation yaw = getRotationFromInt(rotation.getY());
100-
Rotation roll = getRotationFromInt(rotation.getZ());
99+
Rotation pitch = getRotationFromInt(rotation.x());
100+
Rotation yaw = getRotationFromInt(rotation.y());
101+
Rotation roll = getRotationFromInt(rotation.z());
101102
int rotationIndex = RotationTuple.of(yaw, pitch, roll).index();
102-
blockChunk.setBlock(this.pos.getX(), this.pos.getY(), this.pos.getZ(),
103+
blockChunk.setBlock(this.pos.x(), this.pos.y(), this.pos.z(),
103104
blockId, rotationIndex, 0);
104105
}
105106

@@ -109,7 +110,7 @@ public void setRotation(Vector3i rotation) {
109110
* @return Rotation of block represented as a Vector3i(yaw, pitch, roll).
110111
*/
111112
public Vector3i getRotation() {
112-
int blockRotationIndex = getWorld().getBlockRotationIndex(this.pos.getX(), this.pos.getY(), this.pos.getZ());
113+
int blockRotationIndex = getWorld().getBlockRotationIndex(this.pos.x(), this.pos.y(), this.pos.z());
113114
RotationTuple rotationTuple = RotationTuple.get(blockRotationIndex);
114115

115116
int yaw = getIntFromRotation(rotationTuple.yaw());
@@ -138,8 +139,8 @@ public Color getTint() {
138139
BlockChunk blockChunk = getChunk().getBlockChunk();
139140
if (blockChunk == null) return null;
140141

141-
int x = this.pos.getX() % 32;
142-
int z = this.pos.getZ() % 32;
142+
int x = this.pos.x() % 32;
143+
int z = this.pos.z() % 32;
143144
int tintInt = blockChunk.getTint(x, z);
144145
return Color.of(tintInt);
145146
}
@@ -152,8 +153,8 @@ public void setTint(Color color, boolean updateChunk) {
152153
BlockChunk blockChunk = getChunk().getBlockChunk();
153154
if (blockChunk == null) return;
154155

155-
int x = this.pos.getX() % 32;
156-
int z = this.pos.getZ() % 32;
156+
int x = this.pos.x() % 32;
157+
int z = this.pos.z() % 32;
157158
blockChunk.setTint(x, z, color.toJavaColor().getRGB());
158159
if (updateChunk) {
159160
updateChunk();
@@ -169,14 +170,14 @@ public byte getFluidLevel() {
169170
ChunkColumn column = store.getComponent(columnRef, ChunkColumn.getComponentType());
170171
if (column == null) return 0;
171172

172-
Ref<ChunkStore> section = column.getSection(ChunkUtil.chunkCoordinate(this.pos.getY()));
173+
Ref<ChunkStore> section = column.getSection(ChunkUtil.chunkCoordinate(this.pos.y()));
173174
if (section == null) {
174175
return 0;
175176
} else {
176177
FluidSection fluidSection = store.getComponent(section, FluidSection.getComponentType());
177178
if (fluidSection == null) return 0;
178179

179-
return fluidSection.getFluidLevel(this.pos.getX(), this.pos.getY(), this.pos.getZ());
180+
return fluidSection.getFluidLevel(this.pos.x(), this.pos.y(), this.pos.z());
180181
}
181182
}
182183

@@ -187,7 +188,7 @@ public void setFluidLevel(byte level) {
187188
ChunkColumn column = store.getComponent(columnRef, ChunkColumn.getComponentType());
188189
if (column == null) return null;
189190

190-
Ref<ChunkStore> section = column.getSection(ChunkUtil.chunkCoordinate(this.pos.getY()));
191+
Ref<ChunkStore> section = column.getSection(ChunkUtil.chunkCoordinate(this.pos.y()));
191192
if (section == null) {
192193
return null;
193194
} else {
@@ -196,17 +197,17 @@ public void setFluidLevel(byte level) {
196197
return null;
197198
}
198199

199-
Fluid fluid = fluidSection.getFluid(this.pos.getX(), this.pos.getY(), this.pos.getZ());
200+
Fluid fluid = fluidSection.getFluid(this.pos.x(), this.pos.y(), this.pos.z());
200201
if (fluid == null) return null;
201202
byte fluidLevel = (byte) Math.clamp((int) level, 0, fluid.getMaxFluidLevel());
202-
fluidSection.setFluid(this.pos.getX(), this.pos.getY(), this.pos.getZ(), fluid, fluidLevel);
203+
fluidSection.setFluid(this.pos.x(), this.pos.y(), this.pos.z(), fluid, fluidLevel);
203204
}
204205
return chunk;
205206
});
206207
}
207208

208209
public Fluid getFluid() {
209-
int fluidId = this.world.getFluidId(this.pos.getX(), this.pos.getY(), this.pos.getZ());
210+
int fluidId = this.world.getFluidId(this.pos.x(), this.pos.y(), this.pos.z());
210211
if (fluidId == -1) {
211212
return null;
212213
}
@@ -220,7 +221,7 @@ public void setFluid(@NotNull Fluid fluid, @Nullable Integer level) {
220221
ChunkColumn column = store.getComponent(columnRef, ChunkColumn.getComponentType());
221222
if (column == null) return null;
222223

223-
Ref<ChunkStore> section = column.getSection(ChunkUtil.chunkCoordinate(this.pos.getY()));
224+
Ref<ChunkStore> section = column.getSection(ChunkUtil.chunkCoordinate(this.pos.y()));
224225
if (section == null) {
225226
return null;
226227
} else {
@@ -234,18 +235,18 @@ public void setFluid(@NotNull Fluid fluid, @Nullable Integer level) {
234235
if (level != null) {
235236
fluidLevel = level.byteValue();
236237
} else {
237-
fluidLevel = fluidSection.getFluidLevel(this.pos.getX(), this.pos.getY(), this.pos.getZ());
238+
fluidLevel = fluidSection.getFluidLevel(this.pos.x(), this.pos.y(), this.pos.z());
238239
if (fluidLevel <= 0) fluidLevel = (byte) fluid.getMaxFluidLevel();
239240
}
240241
fluidLevel = (byte) Math.clamp((int) fluidLevel, 0, fluid.getMaxFluidLevel());
241-
fluidSection.setFluid(this.pos.getX(), this.pos.getY(), this.pos.getZ(), fluid, fluidLevel);
242+
fluidSection.setFluid(this.pos.x(), this.pos.y(), this.pos.z(), fluid, fluidLevel);
242243
}
243244
return chunk;
244245
});
245246
}
246247

247248
public void breakBlock(int settings) {
248-
this.world.breakBlock(this.pos.getX(), this.pos.getY(), this.pos.getZ(), settings);
249+
this.world.breakBlock(this.pos.x(), this.pos.y(), this.pos.z(), settings);
249250
}
250251

251252
public void damage(@Nullable LivingEntity performer, @Nullable ItemStack itemStack, float damage) {
@@ -268,7 +269,6 @@ public void damage(@Nullable LivingEntity performer, @Nullable ItemStack itemSta
268269
chunkStore);
269270
} else {
270271
BlockHarvestUtils.performBlockDamage(
271-
performer,
272272
performer.getReference(),
273273
this.pos,
274274
itemStack,
@@ -312,8 +312,8 @@ public void setBlockHealth(float health) {
312312

313313
if (!blockHealth.isDestroyed()) {
314314
Predicate<PlayerRef> filter = (player) -> true;
315-
world.getNotificationHandler().updateBlockDamage(this.pos.getX(), this.pos.getY(),
316-
this.pos.getZ(), blockHealth.getHealth(), health, filter);
315+
world.getNotificationHandler().updateBlockDamage(this.pos.x(), this.pos.y(),
316+
this.pos.z(), blockHealth.getHealth(), health, filter);
317317
}
318318
}
319319

@@ -326,16 +326,16 @@ public void setBlockHealth(float health) {
326326
}
327327

328328
public @NotNull Location getLocation() {
329-
return new Location(this.world.getName(), this.pos.getX(), this.pos.getY(), this.pos.getZ());
329+
return new Location(this.world.getName(), this.pos.x(), this.pos.y(), this.pos.z());
330330
}
331331

332332
public String toTypeString() {
333333
return String.format("[%s] block at (%s,%s,%s) in '%s'",
334-
this.getType().getId(), this.pos.getX(), this.pos.getY(), this.pos.getZ(), this.world.getName());
334+
this.getType().getId(), this.pos.x(), this.pos.y(), this.pos.z(), this.world.getName());
335335
}
336336

337337
public String toVariableNameString() {
338-
return String.format("%s_%s_%s_%s_%s", this.world.getName(), this.getType().getId(), this.pos.getX(), this.pos.getY(), this.pos.getZ());
338+
return String.format("%s_%s_%s_%s_%s", this.world.getName(), this.getType().getId(), this.pos.x(), this.pos.y(), this.pos.z());
339339
}
340340

341341
@Override

src/main/java/com/github/skriptdev/skript/api/hytale/objects/Direction.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.github.skriptdev.skript.api.hytale.utils.LocationUtils;
44
import com.hypixel.hytale.math.vector.Location;
5-
import com.hypixel.hytale.math.vector.Vector3d;
5+
import org.joml.Vector3d;
66

77
import java.util.ArrayList;
88
import java.util.Arrays;
@@ -53,7 +53,9 @@ public String getVariableName() {
5353

5454
private static Location create(Location location, Number offset, int x, int y, int z) {
5555
double value = offset.doubleValue();
56-
Vector3d add = location.getPosition().clone().add(x * value, y * value, z * value);
56+
57+
Vector3d position = new Vector3d(location.getPosition());
58+
Vector3d add = position.add(x * value, y * value, z * value);
5759
return new Location(location.getWorld(), add);
5860
}
5961

src/main/java/com/github/skriptdev/skript/api/hytale/objects/UserMapMarkerOverride.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.github.skriptdev.skript.api.hytale.objects;
22

3-
import com.hypixel.hytale.math.vector.Vector3d;
43
import com.hypixel.hytale.protocol.packets.worldmap.ContextMenuItem;
54
import com.hypixel.hytale.protocol.packets.worldmap.MapMarker;
65
import com.hypixel.hytale.server.core.universe.world.worldmap.markers.user.UserMapMarker;
6+
import org.joml.Vector3d;
77

88
import java.util.ArrayList;
99
import java.util.List;
@@ -20,8 +20,8 @@ public class UserMapMarkerOverride extends UserMapMarker {
2020
private final List<ContextMenuItem> contextMenuItems = new ArrayList<>();
2121

2222
public void setPosition(Vector3d pos) {
23-
this.blockY = (float) pos.getY();
24-
super.setPosition((float) pos.getX(), (float) pos.getZ());
23+
this.blockY = (float) pos.y();
24+
super.setPosition((float) pos.x(), (float) pos.z());
2525
}
2626

2727
public void addContextMenuItem(ContextMenuItem contextMenuItem) {

src/main/java/com/github/skriptdev/skript/api/hytale/utils/EntityReferenceUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.hypixel.hytale.component.Ref;
66
import com.hypixel.hytale.component.Store;
77
import com.hypixel.hytale.component.spatial.SpatialResource;
8-
import com.hypixel.hytale.math.vector.Vector3d;
98
import com.hypixel.hytale.server.core.entity.Entity;
109
import com.hypixel.hytale.server.core.entity.entities.Player;
1110
import com.hypixel.hytale.server.core.modules.entity.EntityModule;
@@ -14,6 +13,7 @@
1413
import com.hypixel.hytale.server.npc.entities.NPCEntity;
1514
import org.jetbrains.annotations.NotNull;
1615
import org.jetbrains.annotations.Nullable;
16+
import org.joml.Vector3d;
1717

1818
import javax.annotation.Nonnull;
1919
import java.util.ArrayList;

src/main/java/com/github/skriptdev/skript/api/hytale/utils/EntityUtils.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
import com.hypixel.hytale.component.Ref;
99
import com.hypixel.hytale.component.Store;
1010
import com.hypixel.hytale.math.vector.Location;
11-
import com.hypixel.hytale.math.vector.Vector3d;
12-
import com.hypixel.hytale.math.vector.Vector3f;
11+
import com.hypixel.hytale.math.vector.Rotation3f;
1312
import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType;
1413
import com.hypixel.hytale.server.core.asset.type.item.config.Item;
1514
import com.hypixel.hytale.server.core.asset.type.model.config.Model;
@@ -43,6 +42,8 @@
4342
import io.github.syst3ms.skriptparser.util.Pair;
4443
import org.jetbrains.annotations.NotNull;
4544
import org.jetbrains.annotations.Nullable;
45+
import org.joml.Vector3d;
46+
import org.joml.Vector3f;
4647

4748
import javax.annotation.Nonnull;
4849
import java.util.UUID;
@@ -249,10 +250,10 @@ public static <ECS, T extends Component<ECS>> void tryRemoveComponent(Entity ent
249250
}
250251

251252
Vector3d position = location.getPosition();
252-
Vector3f rotation = location.getRotation();
253+
Rotation3f rotation = location.getRotation();
253254

254255
Holder<EntityStore> itemEntityHolder = ItemComponent.generateItemDrop(store, itemStack, position, rotation,
255-
velocity.getX(), velocity.getY(), velocity.getZ());
256+
velocity.x(), velocity.y(), velocity.z());
256257
if (itemEntityHolder == null) {
257258
return new Pair<>(null, null);
258259
}

src/main/java/com/github/skriptdev/skript/api/hytale/utils/LocationUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.github.skriptdev.skript.api.hytale.utils;
22

33
import com.hypixel.hytale.math.vector.Location;
4+
import org.joml.Vector3d;
45

56
/**
67
* Untilities for {@link Location Locations}
@@ -16,7 +17,7 @@ public class LocationUtils {
1617
*/
1718
public static Location clone(Location location) {
1819
return new Location(location.getWorld(),
19-
location.getPosition().clone(),
20+
new Vector3d(location.getPosition()),
2021
location.getRotation().clone());
2122
}
2223

src/main/java/com/github/skriptdev/skript/api/hytale/utils/PlayerUtils.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.hypixel.hytale.component.Store;
55
import com.hypixel.hytale.component.spatial.SpatialResource;
66
import com.hypixel.hytale.math.vector.Location;
7-
import com.hypixel.hytale.math.vector.Vector3d;
87
import com.hypixel.hytale.server.core.NameMatching;
98
import com.hypixel.hytale.server.core.entity.entities.Player;
109
import com.hypixel.hytale.server.core.modules.entity.EntityModule;
@@ -14,6 +13,7 @@
1413
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
1514
import org.jetbrains.annotations.NotNull;
1615
import org.jetbrains.annotations.Nullable;
16+
import org.joml.Vector3d;
1717

1818
import java.util.ArrayList;
1919
import java.util.List;
@@ -147,8 +147,8 @@ public static List<PlayerRef> getPlayerRefs(@Nullable World world) {
147147
Store<EntityStore> store = world.getEntityStore().getStore();
148148
if (store == null) return List.of();
149149

150-
Vector3d min = Vector3d.min(loc1.getPosition(), loc2.getPosition());
151-
Vector3d max = Vector3d.max(loc1.getPosition(), loc2.getPosition());
150+
Vector3d min = loc1.getPosition().min(loc2.getPosition());
151+
Vector3d max = loc1.getPosition().max(loc2.getPosition());
152152

153153
List<Ref<EntityStore>> results = SpatialResource.getThreadLocalReferenceList();
154154
SpatialResource<Ref<EntityStore>, EntityStore> playerSpatialResource = store.getResource(EntityModule.get()
@@ -163,4 +163,10 @@ public static List<PlayerRef> getPlayerRefs(@Nullable World world) {
163163
return players;
164164
}
165165

166+
public static String getUsername(Player player) {
167+
PlayerRef playerRef = getPlayerRef(player);
168+
assert playerRef != null;
169+
return playerRef.getUsername();
170+
}
171+
166172
}

src/main/java/com/github/skriptdev/skript/api/skript/event/PlayerContext.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.github.skriptdev.skript.api.skript.event;
22

3+
import com.github.skriptdev.skript.api.hytale.utils.PlayerUtils;
34
import com.hypixel.hytale.server.core.entity.entities.Player;
5+
import com.hypixel.hytale.server.core.universe.PlayerRef;
46
import io.github.syst3ms.skriptparser.lang.TriggerContext;
57

68
/**
@@ -10,4 +12,8 @@ public interface PlayerContext extends TriggerContext {
1012

1113
Player getPlayer();
1214

15+
default PlayerRef getPlayerRef() {
16+
return PlayerUtils.getPlayerRef(getPlayer());
17+
}
18+
1319
}

src/main/java/com/github/skriptdev/skript/api/skript/testing/TestRunner.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.github.skriptdev.skript.api.utils.Utils;
55
import com.hypixel.hytale.math.util.ChunkUtil;
66
import com.hypixel.hytale.math.vector.Transform;
7-
import com.hypixel.hytale.math.vector.Vector3i;
87
import com.hypixel.hytale.server.core.HytaleServer;
98
import com.hypixel.hytale.server.core.Message;
109
import com.hypixel.hytale.server.core.command.system.CommandManager;
@@ -23,6 +22,8 @@
2322
import io.github.syst3ms.skriptparser.parsing.ScriptLoader;
2423
import io.github.syst3ms.skriptparser.registration.SkriptAddon;
2524
import io.github.syst3ms.skriptparser.variables.Variables;
25+
import org.joml.RoundingMode;
26+
import org.joml.Vector3i;
2627

2728
import java.io.File;
2829
import java.nio.file.Path;
@@ -63,11 +64,11 @@ public void start() {
6364
this.world.execute(() -> {
6465
ISpawnProvider spawnProvider = this.world.getWorldConfig().getSpawnProvider();
6566
Transform spawnPoint = spawnProvider.getSpawnPoint(this.world, UUID.randomUUID());
66-
Vector3i pos = spawnPoint.getPosition().toVector3i();
67+
Vector3i pos = new Vector3i(spawnPoint.getPosition(), RoundingMode.FLOOR);
6768

6869

69-
for (int x = pos.getX() - 64; x < pos.getX() + 64; x += 32) {
70-
for (int z = pos.getZ() - 64; z < pos.getZ() + 64; z += 32) {
70+
for (int x = pos.x() - 64; x < pos.x() + 64; x += 32) {
71+
for (int z = pos.z() - 64; z < pos.z() + 64; z += 32) {
7172
long index = ChunkUtil.indexChunkFromBlock(x, z);
7273
WorldChunk chunk = this.world.getChunk(index);
7374
chunk.addKeepLoaded();

0 commit comments

Comments
 (0)