diff --git a/src/main/java/com/volmit/iris/engine/hunk/Hunk.java b/src/main/java/com/volmit/iris/engine/hunk/Hunk.java index a7dc1b381..0cbd82c24 100644 --- a/src/main/java/com/volmit/iris/engine/hunk/Hunk.java +++ b/src/main/java/com/volmit/iris/engine/hunk/Hunk.java @@ -18,6 +18,7 @@ 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.storage.*; 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.AtomicInteger; import java.util.function.Consumer; +import java.util.function.Function; import java.util.function.Predicate; @SuppressWarnings("ALL") @@ -58,6 +60,21 @@ public interface Hunk { return new HunkView(src); } + static Hunk convertedReadView(Hunk src, Function reader) + { + return new FunctionalHunkView(src, reader, null); + } + + static Hunk convertedWriteView(Hunk src, Function writer) + { + return new FunctionalHunkView(src, null, writer); + } + + static Hunk convertedReadWriteView(Hunk src, Function reader, Function writer) + { + return new FunctionalHunkView(src, reader, writer); + } + static Hunk view(BiomeGrid biome) { return new BiomeGridHunkView(biome); } diff --git a/src/main/java/com/volmit/iris/engine/hunk/view/FunctionalHunkView.java b/src/main/java/com/volmit/iris/engine/hunk/view/FunctionalHunkView.java new file mode 100644 index 000000000..8f94cb6ee --- /dev/null +++ b/src/main/java/com/volmit/iris/engine/hunk/view/FunctionalHunkView.java @@ -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 . + */ + +package com.volmit.iris.engine.hunk.view; + +import com.volmit.iris.engine.hunk.Hunk; + +import java.util.function.Function; + +public class FunctionalHunkView implements Hunk { + private final Hunk src; + private final Function converter; + private final Function backConverter; + + public FunctionalHunkView(Hunk src, Function converter, Function 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 getSource() { + throw new UnsupportedOperationException("You cannot read this hunk's source because it's a different type."); + } +} diff --git a/src/main/java/com/volmit/iris/engine/object/IrisInterpolator3D.java b/src/main/java/com/volmit/iris/engine/object/IrisInterpolator3D.java index c2725dce4..ec9584720 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisInterpolator3D.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisInterpolator3D.java @@ -18,6 +18,7 @@ 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.IrisInterpolation; import com.volmit.iris.engine.object.annotations.Desc;