-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved fluids a lot, added BlockEvents.randomTick, ID icon, fixed m…
…ixin issue (again)
- Loading branch information
1 parent
a32e2a7
commit 2328e65
Showing
33 changed files
with
532 additions
and
257 deletions.
There are no files selected for viewing
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
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
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
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
8 changes: 8 additions & 0 deletions
8
src/main/java/dev/latvian/mods/kubejs/block/BlockRenderType.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 dev.latvian.mods.kubejs.block; | ||
|
||
public enum BlockRenderType { | ||
SOLID, | ||
CUTOUT, | ||
CUTOUT_MIPPED, | ||
TRANSLUCENT | ||
} |
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
37 changes: 37 additions & 0 deletions
37
src/main/java/dev/latvian/mods/kubejs/block/RandomTickKubeEvent.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,37 @@ | ||
package dev.latvian.mods.kubejs.block; | ||
|
||
import dev.latvian.mods.kubejs.level.BlockContainerJS; | ||
import dev.latvian.mods.kubejs.level.KubeLevelEvent; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.util.RandomSource; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
|
||
public class RandomTickKubeEvent implements KubeLevelEvent { | ||
private final ServerLevel level; | ||
private final BlockPos pos; | ||
private final BlockState state; | ||
public final RandomSource random; | ||
private BlockContainerJS block; | ||
|
||
public RandomTickKubeEvent(ServerLevel level, BlockPos pos, BlockState state, RandomSource random) { | ||
this.level = level; | ||
this.pos = pos; | ||
this.state = state; | ||
this.random = random; | ||
} | ||
|
||
@Override | ||
public ServerLevel getLevel() { | ||
return level; | ||
} | ||
|
||
public BlockContainerJS getBlock() { | ||
if (block == null) { | ||
block = new BlockContainerJS(level, pos); | ||
block.cachedState = state; | ||
} | ||
|
||
return block; | ||
} | ||
} |
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
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
128 changes: 128 additions & 0 deletions
128
src/main/java/dev/latvian/mods/kubejs/client/LoadedTexture.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,128 @@ | ||
package dev.latvian.mods.kubejs.client; | ||
|
||
import dev.latvian.mods.kubejs.KubeJS; | ||
import dev.latvian.mods.kubejs.KubeJSPaths; | ||
import dev.latvian.mods.kubejs.color.Color; | ||
import it.unimi.dsi.fastutil.ints.Int2IntArrayMap; | ||
import net.minecraft.resources.ResourceLocation; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import javax.imageio.ImageIO; | ||
import java.awt.Graphics2D; | ||
import java.awt.RenderingHints; | ||
import java.awt.image.BufferedImage; | ||
import java.io.BufferedInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.util.Map; | ||
|
||
public class LoadedTexture { | ||
public static final LoadedTexture EMPTY = new LoadedTexture(0, 0, new int[0], null); | ||
|
||
public static LoadedTexture load(ResourceLocation id) { | ||
try { | ||
var path = KubeJSPaths.ASSETS.resolve(id.getNamespace() + "/textures/" + id.getPath() + ".png"); | ||
|
||
if (Files.exists(path)) { | ||
try (var in = new BufferedInputStream(Files.newInputStream(path))) { | ||
var metaPath = KubeJSPaths.ASSETS.resolve(id.getNamespace() + "/textures/" + id.getPath() + ".png.mcmeta"); | ||
return new LoadedTexture(ImageIO.read(in), Files.exists(metaPath) ? Files.readAllBytes(metaPath) : null); | ||
} | ||
} else if (id.getNamespace().equals(KubeJS.MOD_ID)) { | ||
var path1 = KubeJS.thisMod.getModInfo().getOwningFile().getFile().findResource("assets", "kubejs", "textures", id.getPath() + ".png"); | ||
|
||
if (Files.exists(path1)) { | ||
try (var in = new BufferedInputStream(Files.newInputStream(path1))) { | ||
var metaPath = KubeJS.thisMod.getModInfo().getOwningFile().getFile().findResource("assets", "kubejs", "textures", id.getPath() + ".png.mcmeta"); | ||
return new LoadedTexture(ImageIO.read(in), Files.exists(metaPath) ? Files.readAllBytes(metaPath) : null); | ||
} | ||
} | ||
} | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
return EMPTY; | ||
} | ||
|
||
public final int width; | ||
public final int height; | ||
public final int[] pixels; | ||
public final byte[] mcmeta; | ||
|
||
public LoadedTexture(int width, int height, int[] pixels, @Nullable byte[] mcmeta) { | ||
this.width = width; | ||
this.height = height; | ||
this.pixels = pixels; | ||
this.mcmeta = mcmeta; | ||
} | ||
|
||
public LoadedTexture(BufferedImage img, @Nullable byte[] mcmeta) { | ||
this.width = img.getWidth(); | ||
this.height = img.getHeight(); | ||
this.pixels = new int[width * height]; | ||
img.getRGB(0, 0, width, height, pixels, 0, width); | ||
this.mcmeta = mcmeta; | ||
} | ||
|
||
public byte[] toBytes() { | ||
var img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); | ||
img.setRGB(0, 0, width, height, pixels, 0, width); | ||
|
||
var out = new ByteArrayOutputStream(); | ||
|
||
try { | ||
ImageIO.write(img, "png", out); | ||
} catch (Exception ex) { | ||
throw new RuntimeException(ex); | ||
} | ||
|
||
return out.toByteArray(); | ||
} | ||
|
||
public LoadedTexture copy() { | ||
return new LoadedTexture(width, height, pixels.clone(), mcmeta); | ||
} | ||
|
||
public LoadedTexture remap(Map<Color, Color> remap) { | ||
if (remap.isEmpty()) { | ||
return this; | ||
} | ||
|
||
var colorMap = new Int2IntArrayMap(remap.size()); | ||
|
||
for (var entry : remap.entrySet()) { | ||
var k = entry.getKey(); | ||
var v = entry.getValue(); | ||
colorMap.put(k.getArgbJS(), v.getArgbJS()); | ||
} | ||
|
||
int[] result = new int[pixels.length]; | ||
|
||
for (int i = 0; i < pixels.length; i++) { | ||
result[i] = ((pixels[i] & 0xFF000000) == 0) ? 0 : colorMap.getOrDefault(pixels[i], pixels[i]); | ||
} | ||
|
||
return new LoadedTexture(width, height, result, mcmeta); | ||
} | ||
|
||
public LoadedTexture resize(int newWidth, int newHeight) { | ||
if (width == newWidth && height == newHeight) { | ||
return this; | ||
} | ||
|
||
var source = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); | ||
source.setRGB(0, 0, width, height, pixels, 0, width); | ||
|
||
BufferedImage dst = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB); | ||
Graphics2D bg = dst.createGraphics(); | ||
bg.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); | ||
float sx = (float) newWidth / (float) width; | ||
float sy = (float) newHeight / (float) height; | ||
bg.scale(sx, sy); | ||
bg.drawImage(source, 0, 0, null); | ||
bg.dispose(); | ||
return new LoadedTexture(dst, mcmeta); | ||
} | ||
} |
Oops, something went wrong.