mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-06 16:37:38 +01:00
Merge branch 'new-block-api' into improvement/relative-vec
This commit is contained in:
commit
f9689bc1f3
@ -164,8 +164,7 @@ dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
api "com.github.Minestom:DependencyGetter:v1.0.1"
|
api "com.github.Minestom:DependencyGetter:v1.0.1"
|
||||||
// TODO include registry files
|
implementation 'com.github.Minestom:MinestomDataGenerator:-SNAPSHOT'
|
||||||
//implementation files('data/minestom-data-1.17.jar')
|
|
||||||
|
|
||||||
// Adventure, for user-interface
|
// Adventure, for user-interface
|
||||||
api "net.kyori:adventure-api:$adventureVersion"
|
api "net.kyori:adventure-api:$adventureVersion"
|
||||||
|
@ -172,6 +172,10 @@ public interface Point {
|
|||||||
Double.compare(point.z(), z()) == 0;
|
Double.compare(point.z(), z()) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default boolean isZero() {
|
||||||
|
return x() == 0 && y() == 0 && z() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets if two points are in the same chunk.
|
* Gets if two points are in the same chunk.
|
||||||
*
|
*
|
||||||
|
@ -914,7 +914,7 @@ public class Entity implements Viewable, Tickable, EventHandler<EntityEvent>, Da
|
|||||||
* @return true if velocity is not set to 0
|
* @return true if velocity is not set to 0
|
||||||
*/
|
*/
|
||||||
public boolean hasVelocity() {
|
public boolean hasVelocity() {
|
||||||
return !velocity.samePoint(Vec.ZERO);
|
return !velocity.isZero();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -169,11 +169,11 @@ public interface Block extends ProtocolObject, TagReadable, BlockConstants {
|
|||||||
return compare(block, Comparator.ID);
|
return compare(block, Comparator.ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
static @Nullable Block fromNamespaceId(@NotNull String namespaceID) {
|
static Block fromNamespaceId(@NotNull String namespaceID) {
|
||||||
return BlockLoader.get(namespaceID);
|
return BlockLoader.get(namespaceID);
|
||||||
}
|
}
|
||||||
|
|
||||||
static @Nullable Block fromNamespaceId(@NotNull NamespaceID namespaceID) {
|
static Block fromNamespaceId(@NotNull NamespaceID namespaceID) {
|
||||||
return fromNamespaceId(namespaceID.asString());
|
return fromNamespaceId(namespaceID.asString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ public class PerChunkThreadProvider extends ThreadProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long findThread(@NotNull Chunk chunk) {
|
public int findThread(@NotNull Chunk chunk) {
|
||||||
return chunk.hashCode();
|
return chunk.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ public class PerInstanceThreadProvider extends ThreadProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long findThread(@NotNull Chunk chunk) {
|
public int findThread(@NotNull Chunk chunk) {
|
||||||
return chunk.getInstance().hashCode();
|
return chunk.getInstance().hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ public class SingleThreadProvider extends ThreadProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long findThread(@NotNull Chunk chunk) {
|
public int findThread(@NotNull Chunk chunk) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ public abstract class ThreadProvider {
|
|||||||
*
|
*
|
||||||
* @param chunk the chunk
|
* @param chunk the chunk
|
||||||
*/
|
*/
|
||||||
public abstract long findThread(@NotNull Chunk chunk);
|
public abstract int findThread(@NotNull Chunk chunk);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines how often chunks thread should be updated.
|
* Defines how often chunks thread should be updated.
|
||||||
@ -165,7 +165,6 @@ public abstract class ThreadProvider {
|
|||||||
processRemovedEntities();
|
processRemovedEntities();
|
||||||
// Update entities chunks
|
// Update entities chunks
|
||||||
processUpdatedEntities();
|
processUpdatedEntities();
|
||||||
|
|
||||||
if (getChunkRefreshType() == RefreshType.NEVER)
|
if (getChunkRefreshType() == RefreshType.NEVER)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -175,21 +174,18 @@ public abstract class ThreadProvider {
|
|||||||
final int size = chunks.size();
|
final int size = chunks.size();
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
Chunk chunk = chunks.pollFirst();
|
final Chunk chunk = chunks.pollFirst();
|
||||||
if (!ChunkUtils.isLoaded(chunk)) {
|
if (!ChunkUtils.isLoaded(chunk)) {
|
||||||
removeChunk(chunk);
|
removeChunk(chunk);
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update chunk threads
|
// Update chunk threads
|
||||||
switchChunk(chunk);
|
switchChunk(chunk);
|
||||||
|
|
||||||
// Add back to the deque
|
// Add back to the deque
|
||||||
chunks.addLast(chunk);
|
chunks.addLast(chunk);
|
||||||
|
|
||||||
if (++counter > size)
|
if (++counter > size)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (System.currentTimeMillis() >= endTime)
|
if (System.currentTimeMillis() >= endTime)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -226,22 +222,13 @@ public abstract class ThreadProvider {
|
|||||||
this.threads.forEach(TickThread::shutdown);
|
this.threads.forEach(TickThread::shutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private void addChunk(@NotNull Chunk chunk) {
|
||||||
* Gets all the {@link TickThread tick threads}.
|
|
||||||
*
|
|
||||||
* @return the tick threads
|
|
||||||
*/
|
|
||||||
public @NotNull List<@NotNull TickThread> getThreads() {
|
|
||||||
return threads;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void addChunk(@NotNull Chunk chunk) {
|
|
||||||
ChunkEntry chunkEntry = setChunkThread(chunk, (thread) -> new ChunkEntry(thread, chunk));
|
ChunkEntry chunkEntry = setChunkThread(chunk, (thread) -> new ChunkEntry(thread, chunk));
|
||||||
this.chunkEntryMap.put(chunk, chunkEntry);
|
this.chunkEntryMap.put(chunk, chunkEntry);
|
||||||
this.chunks.add(chunk);
|
this.chunks.add(chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void switchChunk(@NotNull Chunk chunk) {
|
private void switchChunk(@NotNull Chunk chunk) {
|
||||||
ChunkEntry chunkEntry = chunkEntryMap.get(chunk);
|
ChunkEntry chunkEntry = chunkEntryMap.get(chunk);
|
||||||
if (chunkEntry == null)
|
if (chunkEntry == null)
|
||||||
return;
|
return;
|
||||||
@ -256,9 +243,9 @@ public abstract class ThreadProvider {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected @NotNull ChunkEntry setChunkThread(@NotNull Chunk chunk,
|
private @NotNull ChunkEntry setChunkThread(@NotNull Chunk chunk,
|
||||||
@NotNull Function<TickThread, ChunkEntry> chunkEntrySupplier) {
|
@NotNull Function<TickThread, ChunkEntry> chunkEntrySupplier) {
|
||||||
final int threadId = getThreadId(chunk);
|
final int threadId = Math.abs(findThread(chunk)) % threads.size();
|
||||||
TickThread thread = threads.get(threadId);
|
TickThread thread = threads.get(threadId);
|
||||||
var chunks = threadChunkMap.computeIfAbsent(thread, tickThread -> ConcurrentHashMap.newKeySet());
|
var chunks = threadChunkMap.computeIfAbsent(thread, tickThread -> ConcurrentHashMap.newKeySet());
|
||||||
|
|
||||||
@ -267,7 +254,7 @@ public abstract class ThreadProvider {
|
|||||||
return chunkEntry;
|
return chunkEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void removeChunk(Chunk chunk) {
|
private void removeChunk(Chunk chunk) {
|
||||||
ChunkEntry chunkEntry = chunkEntryMap.get(chunk);
|
ChunkEntry chunkEntry = chunkEntryMap.get(chunk);
|
||||||
if (chunkEntry != null) {
|
if (chunkEntry != null) {
|
||||||
TickThread thread = chunkEntry.thread;
|
TickThread thread = chunkEntry.thread;
|
||||||
@ -280,16 +267,6 @@ public abstract class ThreadProvider {
|
|||||||
this.chunks.remove(chunk);
|
this.chunks.remove(chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Finds the thread id associated to a {@link Chunk}.
|
|
||||||
*
|
|
||||||
* @param chunk the chunk to find the thread id from
|
|
||||||
* @return the chunk thread id
|
|
||||||
*/
|
|
||||||
protected int getThreadId(@NotNull Chunk chunk) {
|
|
||||||
return (int) (Math.abs(findThread(chunk)) % threads.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void processRemovedEntities() {
|
private void processRemovedEntities() {
|
||||||
if (removedEntities.isEmpty())
|
if (removedEntities.isEmpty())
|
||||||
return;
|
return;
|
||||||
@ -310,25 +287,15 @@ public abstract class ThreadProvider {
|
|||||||
for (Entity entity : updatableEntities) {
|
for (Entity entity : updatableEntities) {
|
||||||
var acquirableEntity = entity.getAcquirable();
|
var acquirableEntity = entity.getAcquirable();
|
||||||
ChunkEntry handlerChunkEntry = acquirableEntity.getHandler().getChunkEntry();
|
ChunkEntry handlerChunkEntry = acquirableEntity.getHandler().getChunkEntry();
|
||||||
|
|
||||||
Chunk entityChunk = entity.getChunk();
|
|
||||||
|
|
||||||
// Entity is possibly not in the correct thread
|
|
||||||
|
|
||||||
// Remove from previous list
|
// Remove from previous list
|
||||||
{
|
if (handlerChunkEntry != null) {
|
||||||
if (handlerChunkEntry != null) {
|
handlerChunkEntry.entities.remove(entity);
|
||||||
handlerChunkEntry.entities.remove(entity);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add to new list
|
// Add to new list
|
||||||
{
|
ChunkEntry chunkEntry = chunkEntryMap.get(entity.getChunk());
|
||||||
ChunkEntry chunkEntry = chunkEntryMap.get(entityChunk);
|
if (chunkEntry != null) {
|
||||||
if (chunkEntry != null) {
|
chunkEntry.entities.add(entity);
|
||||||
chunkEntry.entities.add(entity);
|
acquirableEntity.getHandler().refreshChunkEntry(chunkEntry);
|
||||||
acquirableEntity.getHandler().refreshChunkEntry(chunkEntry);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.updatableEntities.clear();
|
this.updatableEntities.clear();
|
||||||
@ -387,5 +354,4 @@ public abstract class ThreadProvider {
|
|||||||
return Objects.hash(chunk);
|
return Objects.hash(chunk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user