-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
52 changed files
with
3,414 additions
and
1,322 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
src/main/java/net/gensokyoreimagined/nitori/common/ai/MemoryModificationCounter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package net.gensokyoreimagined.nitori.common.ai; | ||
|
||
public interface MemoryModificationCounter { | ||
|
||
long lithium$getModCount(); | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/net/gensokyoreimagined/nitori/common/ai/WeightedListIterable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package net.gensokyoreimagined.nitori.common.ai; | ||
|
||
import net.minecraft.world.entity.ai.behavior.ShufflingList; | ||
|
||
import java.util.Iterator; | ||
|
||
public interface WeightedListIterable<U> extends Iterable<U> { | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
Iterator<U> iterator(); | ||
|
||
/** | ||
* Returns an {@link Iterable} over the elements in the {@param list}. This allows code to circumvent the usage | ||
* of streams, providing a speed-up in other areas of the game. | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
static <T> Iterable<? extends T> cast(ShufflingList<T> list) { | ||
return ((WeightedListIterable<T>) list); | ||
} | ||
|
||
/** | ||
* A wrapper type for an iterator over the entries of a {@link ShufflingList} which de-references the contained | ||
* values for consumers. | ||
* | ||
* @param <U> The value type stored in each list entry | ||
*/ | ||
class ListIterator<U> implements Iterator<U> { | ||
private final Iterator<ShufflingList.WeightedEntry<? extends U>> inner; | ||
|
||
public ListIterator(Iterator<ShufflingList.WeightedEntry<? extends U>> inner) { | ||
this.inner = inner; | ||
} | ||
|
||
@Override | ||
public boolean hasNext() { | ||
return this.inner.hasNext(); | ||
} | ||
|
||
@Override | ||
public U next() { | ||
return this.inner.next().getData(); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/net/gensokyoreimagined/nitori/common/entity/NavigatingEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package net.gensokyoreimagined.nitori.common.entity; | ||
|
||
import net.minecraft.world.entity.ai.navigation.PathNavigation; | ||
|
||
public interface NavigatingEntity { | ||
boolean lithium$isRegisteredToWorld(); | ||
|
||
void lithium$setRegisteredToWorld(PathNavigation navigation); | ||
|
||
PathNavigation lithium$getRegisteredNavigation(); | ||
|
||
void lithium$updateNavigationRegistration(); | ||
|
||
} |
149 changes: 149 additions & 0 deletions
149
src/main/java/net/gensokyoreimagined/nitori/common/util/collections/MaskedList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
package net.gensokyoreimagined.nitori.common.util.collections; | ||
|
||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; | ||
import it.unimi.dsi.fastutil.objects.ObjectArrayList; | ||
|
||
import java.util.*; | ||
import java.util.function.Consumer; | ||
|
||
public class MaskedList<E> extends AbstractList<E> { | ||
private final ObjectArrayList<E> allElements; | ||
private final BitSet visibleMask; | ||
private final Object2IntOpenHashMap<E> element2Index; | ||
private final boolean defaultVisibility; | ||
private int numCleared; | ||
|
||
public MaskedList(ObjectArrayList<E> allElements, boolean defaultVisibility) { | ||
this.allElements = new ObjectArrayList<>(); | ||
this.visibleMask = new BitSet(); | ||
this.defaultVisibility = defaultVisibility; | ||
this.element2Index = new Object2IntOpenHashMap<>(); | ||
this.element2Index.defaultReturnValue(-1); | ||
|
||
this.addAll(allElements); | ||
} | ||
|
||
public MaskedList() { | ||
this(new ObjectArrayList<>(), true); | ||
} | ||
|
||
public int totalSize() { | ||
return this.allElements.size(); | ||
} | ||
|
||
|
||
public void addOrSet(E element, boolean visible) { | ||
int index = this.element2Index.getInt(element); | ||
if (index != -1) { | ||
this.visibleMask.set(index, visible); | ||
} else { | ||
this.add(element); | ||
this.setVisible(element, visible); | ||
} | ||
} | ||
|
||
public void setVisible(E element, final boolean visible) { | ||
int index = this.element2Index.getInt(element); | ||
if (index != -1) { | ||
this.visibleMask.set(index, visible); | ||
} | ||
//ignore when the element is not in the collection | ||
} | ||
|
||
@Override | ||
public Iterator<E> iterator() { | ||
return new Iterator<>() { | ||
int nextIndex = 0; | ||
int cachedNext = -1; | ||
|
||
@Override | ||
public boolean hasNext() { | ||
return (this.cachedNext = MaskedList.this.visibleMask.nextSetBit(this.nextIndex)) != -1; | ||
} | ||
|
||
@Override | ||
public E next() { | ||
int index = this.cachedNext; | ||
this.cachedNext = -1; | ||
this.nextIndex = index + 1; | ||
return MaskedList.this.allElements.get(index); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public Spliterator<E> spliterator() { | ||
return new Spliterators.AbstractSpliterator<E>(Long.MAX_VALUE, Spliterator.ORDERED | Spliterator.NONNULL) { | ||
int nextIndex = 0; | ||
|
||
@Override | ||
public boolean tryAdvance(Consumer<? super E> action) { | ||
int index = MaskedList.this.visibleMask.nextSetBit(this.nextIndex); | ||
if (index == -1) { | ||
return false; | ||
} | ||
this.nextIndex = index + 1; | ||
action.accept(MaskedList.this.allElements.get(index)); | ||
return true; | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public boolean add(E e) { | ||
int oldIndex = this.element2Index.put(e, this.allElements.size()); | ||
if (oldIndex != -1) { | ||
throw new IllegalStateException("MaskedList must not contain duplicates! Trying to add " + e + " but it is already present at index " + oldIndex + ". Current size: " + this.allElements.size()); | ||
} | ||
this.visibleMask.set(this.allElements.size(), this.defaultVisibility); | ||
return this.allElements.add(e); | ||
} | ||
|
||
@Override | ||
public boolean remove(Object o) { | ||
int index = this.element2Index.removeInt(o); | ||
if (index == -1) { | ||
return false; | ||
} | ||
this.visibleMask.clear(index); | ||
this.allElements.set(index, null); | ||
this.numCleared++; | ||
|
||
|
||
if (this.numCleared * 2 > this.allElements.size()) { | ||
ObjectArrayList<E> clonedElements = this.allElements.clone(); | ||
BitSet clonedVisibleMask = (BitSet) this.visibleMask.clone(); | ||
this.allElements.clear(); | ||
this.visibleMask.clear(); | ||
this.element2Index.clear(); | ||
for (int i = 0; i < clonedElements.size(); i++) { | ||
E element = clonedElements.get(i); | ||
int newIndex = this.allElements.size(); | ||
this.allElements.add(element); | ||
this.visibleMask.set(newIndex, clonedVisibleMask.get(i)); | ||
this.element2Index.put(element, newIndex); | ||
} | ||
this.numCleared = 0; | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public E get(int index) { | ||
if (index < 0 || index >= this.size()) { | ||
throw new IndexOutOfBoundsException(index); | ||
} | ||
|
||
int i = 0; | ||
while (index >= 0) { | ||
index--; | ||
i = this.visibleMask.nextSetBit(i + 1); | ||
} | ||
return this.allElements.get(i); | ||
} | ||
|
||
@Override | ||
public int size() { | ||
return this.visibleMask.cardinality(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
.../java/net/gensokyoreimagined/nitori/common/util/deduplication/LithiumInternerWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package net.gensokyoreimagined.nitori.common.util.deduplication; | ||
|
||
public interface LithiumInternerWrapper<T> { | ||
|
||
T lithium$getCanonical(T value); | ||
|
||
void lithium$deleteCanonical(T value); | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/net/gensokyoreimagined/nitori/common/world/ServerWorldExtended.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package net.gensokyoreimagined.nitori.common.world; | ||
|
||
import net.minecraft.world.entity.Mob; | ||
|
||
public interface ServerWorldExtended { | ||
void lithium$setNavigationActive(Mob mobEntity); | ||
|
||
void lithium$setNavigationInactive(Mob mobEntity); | ||
} |
142 changes: 142 additions & 0 deletions
142
src/main/java/net/gensokyoreimagined/nitori/common/world/blockview/SingleBlockBlockView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
package net.gensokyoreimagined.nitori.common.world.blockview; | ||
|
||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.phys.shapes.CollisionContext; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.level.material.FluidState; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.phys.AABB; | ||
import net.minecraft.world.phys.Vec3; | ||
import net.minecraft.world.phys.shapes.VoxelShape; | ||
import net.minecraft.world.level.BlockGetter; | ||
import net.minecraft.world.level.CollisionGetter; | ||
import net.minecraft.world.level.border.WorldBorder; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public record SingleBlockBlockView(BlockState state, BlockPos pos) implements BlockGetter, CollisionGetter { | ||
public static SingleBlockBlockView of(BlockState blockState, BlockPos blockPos) { | ||
return new SingleBlockBlockView(blockState, blockPos.immutable()); | ||
} | ||
|
||
@Override | ||
public BlockState getBlockState(BlockPos pos) { | ||
if (pos.equals(this.pos())) { | ||
return this.state(); | ||
} else { | ||
throw SingleBlockViewException.INSTANCE; | ||
} | ||
} | ||
|
||
@Override | ||
public FluidState getFluidState(BlockPos pos) { | ||
if (pos.equals(this.pos())) { | ||
return this.state().getFluidState(); | ||
} else { | ||
throw SingleBlockViewException.INSTANCE; | ||
} | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public BlockEntity getBlockEntity(BlockPos pos) { | ||
throw SingleBlockViewException.INSTANCE; | ||
} | ||
|
||
@Override | ||
public int getHeight() { | ||
throw SingleBlockViewException.INSTANCE; | ||
} | ||
|
||
@Override | ||
public int getMinBuildHeight() { | ||
throw SingleBlockViewException.INSTANCE; | ||
} | ||
|
||
@Override | ||
public WorldBorder getWorldBorder() { | ||
throw SingleBlockViewException.INSTANCE; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public BlockGetter getChunkForCollisions(int chunkX, int chunkZ) { | ||
throw SingleBlockViewException.INSTANCE; | ||
} | ||
|
||
@Override | ||
public boolean isUnobstructed(@Nullable Entity except, VoxelShape shape) { | ||
throw SingleBlockViewException.INSTANCE; | ||
} | ||
|
||
@Override | ||
public boolean isUnobstructed(BlockState state, BlockPos pos, CollisionContext context) { | ||
throw SingleBlockViewException.INSTANCE; | ||
} | ||
|
||
@Override | ||
public boolean isUnobstructed(Entity entity) { | ||
throw SingleBlockViewException.INSTANCE; | ||
} | ||
|
||
@Override | ||
public boolean noCollision(@Nullable Entity entity, AABB box) { | ||
throw SingleBlockViewException.INSTANCE; | ||
} | ||
|
||
@Override | ||
public List<VoxelShape> getEntityCollisions(@Nullable Entity entity, AABB box) { | ||
throw SingleBlockViewException.INSTANCE; | ||
} | ||
|
||
@Override | ||
public Iterable<VoxelShape> getCollisions(@Nullable Entity entity, AABB box) { | ||
throw SingleBlockViewException.INSTANCE; | ||
} | ||
|
||
@Override | ||
public Iterable<VoxelShape> getBlockCollisions(@Nullable Entity entity, AABB box) { | ||
throw SingleBlockViewException.INSTANCE; | ||
} | ||
|
||
@Override | ||
public boolean collidesWithSuffocatingBlock(@Nullable Entity entity, AABB box) { | ||
throw SingleBlockViewException.INSTANCE; | ||
} | ||
|
||
@Override | ||
public Optional<Vec3> findFreePosition(@Nullable Entity entity, VoxelShape shape, Vec3 target, double x, double y, double z) { | ||
throw SingleBlockViewException.INSTANCE; | ||
} | ||
|
||
public static class SingleBlockViewException extends RuntimeException { | ||
|
||
public static final SingleBlockViewException INSTANCE = new SingleBlockViewException(); | ||
|
||
private SingleBlockViewException() { | ||
this.setStackTrace(new StackTraceElement[0]); | ||
} | ||
|
||
@Override | ||
public synchronized Throwable fillInStackTrace() { | ||
this.setStackTrace(new StackTraceElement[0]); | ||
return this; | ||
} | ||
} | ||
|
||
@javax.annotation.Nullable | ||
@Override | ||
public BlockState getBlockStateIfLoaded(@NotNull BlockPos block) { | ||
throw SingleBlockViewException.INSTANCE; | ||
} | ||
|
||
@javax.annotation.Nullable | ||
@Override | ||
public FluidState getFluidIfLoaded(@NotNull BlockPos block) { | ||
throw SingleBlockViewException.INSTANCE; | ||
} | ||
} |
Oops, something went wrong.