mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
Hunk interp
This commit is contained in:
parent
d826f968b5
commit
0d90c1d960
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
package com.volmit.iris.engine.hunk;
|
package com.volmit.iris.engine.hunk;
|
||||||
|
|
||||||
|
import com.volmit.iris.engine.data.B;
|
||||||
import com.volmit.iris.engine.hunk.io.HunkIOAdapter;
|
import com.volmit.iris.engine.hunk.io.HunkIOAdapter;
|
||||||
import com.volmit.iris.engine.hunk.storage.*;
|
import com.volmit.iris.engine.hunk.storage.*;
|
||||||
import com.volmit.iris.engine.hunk.view.*;
|
import com.volmit.iris.engine.hunk.view.*;
|
||||||
@ -42,6 +43,7 @@ import java.io.OutputStream;
|
|||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
@SuppressWarnings("ALL")
|
@SuppressWarnings("ALL")
|
||||||
@ -58,6 +60,21 @@ public interface Hunk<T> {
|
|||||||
return new HunkView<T>(src);
|
return new HunkView<T>(src);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static <A,B> Hunk<B> convertedReadView(Hunk<A> src, Function<A, B> reader)
|
||||||
|
{
|
||||||
|
return new FunctionalHunkView<A, B>(src, reader, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
static <A,B> Hunk<B> convertedWriteView(Hunk<A> src, Function<B, A> writer)
|
||||||
|
{
|
||||||
|
return new FunctionalHunkView<A, B>(src, null, writer);
|
||||||
|
}
|
||||||
|
|
||||||
|
static <A,B> Hunk<B> convertedReadWriteView(Hunk<A> src, Function<A, B> reader, Function<B, A> writer)
|
||||||
|
{
|
||||||
|
return new FunctionalHunkView<A, B>(src, reader, writer);
|
||||||
|
}
|
||||||
|
|
||||||
static Hunk<Biome> view(BiomeGrid biome) {
|
static Hunk<Biome> view(BiomeGrid biome) {
|
||||||
return new BiomeGridHunkView(biome);
|
return new BiomeGridHunkView(biome);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||||
|
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.volmit.iris.engine.hunk.view;
|
||||||
|
|
||||||
|
import com.volmit.iris.engine.hunk.Hunk;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public class FunctionalHunkView<R, T> implements Hunk<T> {
|
||||||
|
private final Hunk<R> src;
|
||||||
|
private final Function<R, T> converter;
|
||||||
|
private final Function<T, R> backConverter;
|
||||||
|
|
||||||
|
public FunctionalHunkView(Hunk<R> src, Function<R, T> converter, Function<T, R> backConverter) {
|
||||||
|
this.src = src;
|
||||||
|
this.converter = converter;
|
||||||
|
this.backConverter = backConverter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setRaw(int x, int y, int z, T t) {
|
||||||
|
if(backConverter == null)
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException("You cannot write to this hunk (Read Only)");
|
||||||
|
}
|
||||||
|
|
||||||
|
src.setRaw(x,y,z,backConverter.apply(t));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T getRaw(int x, int y, int z) {
|
||||||
|
if(converter == null)
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException("You cannot read this hunk (Write Only)");
|
||||||
|
}
|
||||||
|
|
||||||
|
return converter.apply(src.getRaw(x, y, z));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getWidth() {
|
||||||
|
return src.getWidth();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getDepth() {
|
||||||
|
return src.getDepth();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getHeight() {
|
||||||
|
return src.getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Hunk<T> getSource() {
|
||||||
|
throw new UnsupportedOperationException("You cannot read this hunk's source because it's a different type.");
|
||||||
|
}
|
||||||
|
}
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
package com.volmit.iris.engine.object;
|
package com.volmit.iris.engine.object;
|
||||||
|
|
||||||
|
import com.volmit.iris.engine.hunk.Hunk;
|
||||||
import com.volmit.iris.engine.interpolation.InterpolationMethod3D;
|
import com.volmit.iris.engine.interpolation.InterpolationMethod3D;
|
||||||
import com.volmit.iris.engine.interpolation.IrisInterpolation;
|
import com.volmit.iris.engine.interpolation.IrisInterpolation;
|
||||||
import com.volmit.iris.engine.object.annotations.Desc;
|
import com.volmit.iris.engine.object.annotations.Desc;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user