misc fixes including making aura effects work!

This commit is contained in:
Ellpeck 2020-01-23 02:01:05 +01:00
parent 8fb7beb49f
commit 81c6034c21
4 changed files with 16 additions and 16 deletions

View file

@ -29,8 +29,6 @@ import net.minecraft.util.math.Vec3d;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkStatus;
import net.minecraft.world.chunk.IChunk;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.capabilities.Capability;
@ -58,7 +56,7 @@ public final class Helper {
public static boolean getTileEntitiesInArea(IWorld world, BlockPos pos, int radius, Function<TileEntity, Boolean> consumer) {
for (int x = (pos.getX() - radius) >> 4; x <= (pos.getX() + radius) >> 4; x++) {
for (int z = (pos.getZ() - radius) >> 4; z <= (pos.getZ() + radius) >> 4; z++) {
Chunk chunk = getOptionalChunk(world, x, z);
Chunk chunk = getLoadedChunk(world, x, z);
if (chunk != null) {
for (BlockPos tilePos : chunk.getTileEntitiesPos()) {
if (tilePos.distanceSq(pos) <= radius * radius)
@ -74,7 +72,7 @@ public final class Helper {
public static void getAuraChunksInArea(World world, BlockPos pos, int radius, Consumer<AuraChunk> consumer) {
for (int x = (pos.getX() - radius) >> 4; x <= (pos.getX() + radius) >> 4; x++) {
for (int z = (pos.getZ() - radius) >> 4; z <= (pos.getZ() + radius) >> 4; z++) {
Chunk chunk = getOptionalChunk(world, x, z);
Chunk chunk = getLoadedChunk(world, x, z);
if (chunk != null) {
AuraChunk auraChunk = (AuraChunk) chunk.getCapability(NaturesAuraAPI.capAuraChunk, null).orElse(null);
if (auraChunk != null)
@ -95,9 +93,8 @@ public final class Helper {
return frames;
}
public static Chunk getOptionalChunk(IWorld world, int x, int z) {
IChunk chunk = world.getChunk(x, z, ChunkStatus.EMPTY, false);
return chunk instanceof Chunk ? (Chunk) chunk : null;
public static Chunk getLoadedChunk(IWorld world, int x, int z) {
return world.getChunkProvider().getChunk(x, z, false);
}
public static int blendColors(int c1, int c2, float ratio) {

View file

@ -319,32 +319,32 @@ public final class NaturesAuraAPI {
boolean isEffectPowderActive(World world, BlockPos pos, ResourceLocation name);
/**
* @see IAuraChunk#getSpotsInArea(World, BlockPos, int, BiConsumer)
* @see IAuraChunk#getSpotsInArea(IWorld, BlockPos, int, BiConsumer)
*/
void getAuraSpotsInArea(World world, BlockPos pos, int radius, BiConsumer<BlockPos, Integer> consumer);
/**
* @see IAuraChunk#getSpotAmountInArea(World, BlockPos, int)
* @see IAuraChunk#getSpotAmountInArea(IWorld, BlockPos, int)
*/
int getSpotAmountInArea(World world, BlockPos pos, int radius);
/**
* @see IAuraChunk#getAuraInArea(World, BlockPos, int)
* @see IAuraChunk#getAuraInArea(IWorld, BlockPos, int)
*/
int getAuraInArea(World world, BlockPos pos, int radius);
/**
* @see IAuraChunk#triangulateAuraInArea(World, BlockPos, int)
* @see IAuraChunk#triangulateAuraInArea(IWorld, BlockPos, int)
*/
int triangulateAuraInArea(World world, BlockPos pos, int radius);
/**
* @see IAuraChunk#getLowestSpot(World, BlockPos, int, BlockPos)
* @see IAuraChunk#getLowestSpot(IWorld, BlockPos, int, BlockPos)
*/
BlockPos getLowestAuraDrainSpot(World world, BlockPos pos, int radius, BlockPos defaultSpot);
/**
* @see IAuraChunk#getHighestSpot(World, BlockPos, int, BlockPos)
* @see IAuraChunk#getHighestSpot(IWorld, BlockPos, int, BlockPos)
*/
BlockPos getHighestAuraDrainSpot(World world, BlockPos pos, int radius, BlockPos defaultSpot);
}

View file

@ -143,6 +143,8 @@ public class AuraChunk implements IAuraChunk {
public void update() {
World world = this.chunk.getWorld();
if (this.drainSpots.size() > 0)
System.out.println("Updating with " + this.drainSpots.size());
for (Map.Entry<BlockPos, MutableInt> entry : this.drainSpots.entrySet()) {
BlockPos pos = entry.getKey();
MutableInt amount = entry.getValue();

View file

@ -22,6 +22,7 @@ import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Optional;
public class CommonEvents {
@ -47,10 +48,10 @@ public class CommonEvents {
ChunkManager manager = ((ServerChunkProvider) event.world.getChunkProvider()).chunkManager;
Iterable<ChunkHolder> chunks = (Iterable<ChunkHolder>) GET_LOADED_CHUNKS_METHOD.invoke(manager);
for (ChunkHolder holder : chunks) {
Chunk chunk = holder.func_219298_c();
if (chunk == null)
Optional<Chunk> chunkQuestionmark = holder.func_219296_a().getNow(ChunkHolder.UNLOADED_CHUNK).left();
if (!chunkQuestionmark.isPresent())
continue;
AuraChunk auraChunk = (AuraChunk) chunk.getCapability(NaturesAuraAPI.capAuraChunk, null).orElse(null);
AuraChunk auraChunk = (AuraChunk) chunkQuestionmark.get().getCapability(NaturesAuraAPI.capAuraChunk, null).orElse(null);
if (auraChunk != null)
auraChunk.update();
}