filter regions?

Dieser Commit ist enthalten in:
Jesse Boyd 2019-05-04 02:33:45 +10:00
Ursprung 4116adcfef
Commit 27ed596027
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 59F1DE6293AF6E1F
9 geänderte Dateien mit 125 neuen und 22 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,16 @@
package com.boydti.fawe.beta;
public abstract class DelegateFilter implements IDelegateFilter {
private final Filter parent;
public DelegateFilter(Filter parent) {
this.parent = parent;
}
@Override
public Filter getParent() {
return parent;
}
@Override
public abstract Filter fork();
}

Datei anzeigen

@ -1,7 +1,10 @@
package com.boydti.fawe.beta;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.block.BaseBlock;
import javax.annotation.Nullable;
/**
* A filter is an interface used for setting blocks
*/
@ -13,8 +16,8 @@ public interface Filter {
* @param cz
* @return
*/
default boolean appliesChunk(final int cx, final int cz) {
return true;
default Filter appliesChunk(final int cx, final int cz) {
return this;
}
/**
@ -25,10 +28,14 @@ public interface Filter {
* @param chunk
* @return
*/
default IChunk applyChunk(final IChunk chunk) {
default IChunk applyChunk(final IChunk chunk, @Nullable Region region) {
return chunk;
}
default Filter appliesLayer(IChunk chunk, int layer) {
return this;
}
/**
* Make changes to the block here<br>
* - e.g. block.setId(...)<br>

Datei anzeigen

@ -1,15 +1,18 @@
package com.boydti.fawe.beta;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import javax.annotation.Nullable;
public interface FilterBlock {
FilterBlock init(IQueueExtent queue);
FilterBlock init(int X, int Z, IGetBlocks chunk);
void filter(IGetBlocks get, ISetBlocks set, int layer, Filter filter);
void filter(IGetBlocks get, ISetBlocks set, int layer, Filter filter, @Nullable Region region);
void setOrdinal(int ordinal);

Datei anzeigen

@ -0,0 +1,54 @@
package com.boydti.fawe.beta;
public interface IDelegateFilter extends Filter {
Filter getParent();
@Override
default Filter appliesChunk(int cx, int cz) {
Filter copy = getParent().appliesChunk(cx, cz);
if (copy == null) return null;
if (copy != getParent()) {
return newInstance(copy);
} else {
return this;
}
}
@Override
default IChunk applyChunk(IChunk chunk) {
return getParent().applyChunk(chunk);
}
@Override
default Filter appliesLayer(IChunk chunk, int layer) {
Filter copy = getParent().appliesLayer(chunk, layer);
if (copy == null) return null;
if (copy != getParent()) {
return newInstance(copy);
} else {
return this;
}
}
@Override
default void applyBlock(FilterBlock block) {
getParent().applyBlock(block);
}
@Override
default void finishChunk(IChunk chunk) {
getParent().finishChunk(chunk);
}
@Override
default void join() {
getParent().join();
}
@Override
default Filter fork() {
return newInstance(getParent().fork());
}
Filter newInstance(Filter other);
}

Datei anzeigen

@ -27,10 +27,6 @@ public interface ISetBlocks extends IBlocks {
void removeEntity(UUID uuid);
default void optimize() {
}
BlockState getBlock(int x, int y, int z);
char[] getArray(int layer);

Datei anzeigen

@ -0,0 +1,37 @@
package com.boydti.fawe.beta;
import com.sk89q.worldedit.regions.Region;
public class RegionFilter extends DelegateFilter {
private final Region region;
public RegionFilter(Filter parent, Region region) {
super(parent);
this.region = region;
}
@Override
public Filter appliesChunk(int cx, int cz) {
return getParent().appliesChunk(cx, cz);
}
@Override
public Filter appliesLayer(IChunk chunk, int layer) {
return getParent().appliesLayer(chunk, layer);
}
@Override
public void applyBlock(FilterBlock block) {
getParent().applyBlock(block);
}
@Override
public void finishChunk(IChunk chunk) {
getParent().finishChunk(chunk);
}
@Override
public Filter newInstance(Filter other) {
return new RegionFilter(other, region);
}
}

Datei anzeigen

@ -170,13 +170,13 @@ public abstract class QueueHandler implements Trimable, Runnable {
X = pos.getX();
Z = pos.getZ();
}
if (!newFilter.appliesChunk(X, Z)) {
continue;
}
IChunk chunk = queue.getCachedChunk(X, Z);
// Initialize
chunk.init(queue, X, Z);
if (!newFilter.appliesChunk(X, Z)) {
continue;
}
chunk = newFilter.applyChunk(chunk);
if (chunk == null) continue;

Datei anzeigen

@ -1,8 +1,5 @@
package com.boydti.fawe.beta.implementation.blocks;
import com.boydti.fawe.beta.CharFilterBlock;
import com.boydti.fawe.beta.Filter;
import com.boydti.fawe.beta.FilterBlock;
import com.boydti.fawe.beta.IGetBlocks;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;

Datei anzeigen

@ -41,7 +41,7 @@ public abstract class ChunkHolder implements IChunk, Supplier<IGetBlocks> {
final ISetBlocks set = getOrCreateSet();
block = block.init(X, Z, get);
for (int layer = 0; layer < 16; layer++) {
if (!get.hasSection(layer)) continue;
if (!get.hasSection(layer) || !filter.appliesLayer(this, layer)) continue;
block.filter(get, set, layer, filter);
}
filter.finishChunk(this);
@ -98,13 +98,6 @@ public abstract class ChunkHolder implements IChunk, Supplier<IGetBlocks> {
return get();
}
// @Override
// public void optimize() {
// if (set != null) {
// set.optimize();
// }
// }
@Override
public void init(final IQueueExtent extent, final int X, final int Z) {
this.extent = extent;