Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Texture. #1755

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions chunky/src/java/se/llbit/chunky/block/AbstractModelBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import se.llbit.chunky.model.BlockModel;
import se.llbit.chunky.plugin.PluginApi;
import se.llbit.chunky.renderer.scene.Scene;
import se.llbit.chunky.resources.Texture;
import se.llbit.chunky.resources.texture.AbstractTexture;
import se.llbit.math.Ray;
import se.llbit.math.Vector3;

Expand All @@ -14,7 +14,7 @@ public abstract class AbstractModelBlock extends MinecraftBlock implements Model

protected BlockModel model;

public AbstractModelBlock(String name, Texture texture) {
public AbstractModelBlock(String name, AbstractTexture texture) {
super(name, texture);
localIntersect = true;
opaque = false;
Expand Down
6 changes: 2 additions & 4 deletions chunky/src/java/se/llbit/chunky/block/Block.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package se.llbit.chunky.block;

import se.llbit.chunky.entity.Entity;
import se.llbit.chunky.model.TexturedBlockModel;
import se.llbit.chunky.renderer.scene.Scene;
import se.llbit.chunky.resources.Texture;
import se.llbit.chunky.resources.texture.AbstractTexture;
import se.llbit.chunky.world.Material;
import se.llbit.json.JsonString;
import se.llbit.json.JsonValue;
Expand All @@ -13,7 +12,6 @@
import se.llbit.nbt.CompoundTag;
import se.llbit.nbt.Tag;

import java.util.List;
import java.util.Random;

public abstract class Block extends Material {
Expand All @@ -33,7 +31,7 @@ public abstract class Block extends Material {
*/
public boolean invisible = false;

public Block(String name, Texture texture) {
public Block(String name, AbstractTexture texture) {
super(name, texture);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package se.llbit.chunky.block;

import se.llbit.chunky.model.FixedTopBottomRotatableTexturedBlockModel;
import se.llbit.chunky.resources.Texture;
import se.llbit.chunky.resources.texture.AbstractTexture;

/**
* A textured block that can have one of four orientations but have a fixed top and bottom that does NOT rotate.
* E.g. chiseled bookshelves.
* If the top and bottom should rotate with the rest of the block, use TopBottomOrientedTexturedBlock.
*/
public class FixedTopBottomRotatableTexturedBlock extends AbstractModelBlock {
public FixedTopBottomRotatableTexturedBlock(String name, String facing, Texture front, Texture side, Texture top) {
public FixedTopBottomRotatableTexturedBlock(String name, String facing, AbstractTexture front, AbstractTexture side, AbstractTexture top) {
this(name, facing, front, side, side, side, top, top);
}

public FixedTopBottomRotatableTexturedBlock(String name, String facing, Texture front, Texture side, Texture top, Texture bottom) {
public FixedTopBottomRotatableTexturedBlock(String name, String facing, AbstractTexture front, AbstractTexture side, AbstractTexture top, AbstractTexture bottom) {
this(name, facing, front, side, side, side, top, bottom);
}

public FixedTopBottomRotatableTexturedBlock(String name, String facing, Texture front, Texture south, Texture east, Texture west, Texture top, Texture bottom) {
public FixedTopBottomRotatableTexturedBlock(String name, String facing, AbstractTexture front, AbstractTexture south, AbstractTexture east, AbstractTexture west, AbstractTexture top, AbstractTexture bottom) {
super(name, front);
this.model = new FixedTopBottomRotatableTexturedBlockModel(facing, front, south, east, west, top, bottom);
solid = true;
Expand Down
3 changes: 2 additions & 1 deletion chunky/src/java/se/llbit/chunky/block/MinecraftBlock.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package se.llbit.chunky.block;

import se.llbit.chunky.resources.Texture;
import se.llbit.chunky.resources.texture.AbstractTexture;
import se.llbit.chunky.world.Material;

/**
Expand All @@ -9,7 +10,7 @@
public class MinecraftBlock extends Block {
public static final Material STONE = new MinecraftBlock("stone", Texture.stone);

public MinecraftBlock(String name, Texture texture) {
public MinecraftBlock(String name, AbstractTexture texture) {
super("minecraft:" + name, texture);
opaque = true;
solid = true;
Expand Down
62 changes: 32 additions & 30 deletions chunky/src/java/se/llbit/chunky/block/MinecraftBlockProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import se.llbit.chunky.model.minecraft.FlowerPotModel.Kind;
import se.llbit.chunky.resources.ShulkerTexture;
import se.llbit.chunky.resources.Texture;
import se.llbit.chunky.resources.texture.AbstractTexture;
import se.llbit.chunky.resources.texture.BitmapTexture;
import se.llbit.nbt.ListTag;
import se.llbit.nbt.Tag;

Expand Down Expand Up @@ -931,11 +933,11 @@ private static void addBlocks(BiFunction<String, Tag, Block> factory, String...
}
}

private static void addBlock(String name, Texture texture) {
private static void addBlock(String name, BitmapTexture texture) {
addBlock(name, (n, tag) -> new MinecraftBlock(n, texture));
}

private static void addBlocks(Texture texture, String... names) {
private static void addBlocks(BitmapTexture texture, String... names) {
addBlocks((name, tag) -> new MinecraftBlock(name, texture), names);
}

Expand Down Expand Up @@ -1302,7 +1304,7 @@ public Block getBlockByTag(String namespacedName, Tag tag) {
case "detector_rail": {
Tag properties = tag.get("Properties");
String powered = properties.get("powered").stringValue("false");
Texture straightTrack =
AbstractTexture straightTrack =
powered.equals("true") ? Texture.detectorRailOn : Texture.detectorRail;
return rail(tag, straightTrack);
}
Expand Down Expand Up @@ -1744,7 +1746,7 @@ public Block getBlockByTag(String namespacedName, Tag tag) {
case "activator_rail": {
Tag properties = tag.get("Properties");
String powered = properties.get("powered").stringValue("false");
Texture straightTrack =
AbstractTexture straightTrack =
powered.equals("true") ? Texture.activatorRailPowered : Texture.activatorRail;
return rail(tag, straightTrack);
}
Expand Down Expand Up @@ -3096,31 +3098,31 @@ public Block getBlockByTag(String namespacedName, Tag tag) {
}
}

public static Block largeFlower(Tag tag, Texture top, Texture bottom) {
public static Block largeFlower(Tag tag, AbstractTexture top, AbstractTexture bottom) {
String name = BlockProvider.blockName(tag);
String half = tag.get("Properties").get("half").stringValue("lower");
return new SpriteBlock(name, half.equals("upper") ? top : bottom);
}

public static Block log(Tag tag, Texture side, Texture top) {
public static Block log(Tag tag, AbstractTexture side, AbstractTexture top) {
String name = BlockProvider.blockName(tag);
String axis = tag.get("Properties").get("axis").stringValue("y");
return new Log(name, side, top, axis);
}

public static Block slab(Tag tag, Texture texture) {
public static Block slab(Tag tag, AbstractTexture texture) {
String name = BlockProvider.blockName(tag);
String type = tag.get("Properties").get("type").stringValue("bottom");
return new Slab(name, texture, type);
}

public static Block slab(Tag tag, Texture sideTexture, Texture topTexture) {
public static Block slab(Tag tag, AbstractTexture sideTexture, AbstractTexture topTexture) {
String name = BlockProvider.blockName(tag);
String type = tag.get("Properties").get("type").stringValue("bottom");
return new Slab(name, sideTexture, topTexture, type);
}

public static Block stairs(Tag tag, Texture texture) {
public static Block stairs(Tag tag, AbstractTexture texture) {
String name = BlockProvider.blockName(tag);
Tag properties = tag.get("Properties");
String half = properties.get("half").stringValue("bottom");
Expand All @@ -3129,7 +3131,7 @@ public static Block stairs(Tag tag, Texture texture) {
return new Stairs(name, texture, half, shape, facing);
}

public static Block stairs(Tag tag, Texture side, Texture top, Texture bottom) {
public static Block stairs(Tag tag, AbstractTexture side, AbstractTexture top, AbstractTexture bottom) {
String name = BlockProvider.blockName(tag);
Tag properties = tag.get("Properties");
String half = properties.get("half").stringValue("bottom");
Expand All @@ -3138,20 +3140,20 @@ public static Block stairs(Tag tag, Texture side, Texture top, Texture bottom) {
return new Stairs(name, side, top, bottom, half, shape, facing);
}

private static Block glazedTerracotta(Tag tag, Texture texture) {
private static Block glazedTerracotta(Tag tag, AbstractTexture texture) {
String name = BlockProvider.blockName(tag);
String facing = BlockProvider.facing(tag, "south");
return new GlazedTerracotta(name, texture, facing);
}

private static Block bed(Tag tag, Texture texture) {
private static Block bed(Tag tag, AbstractTexture texture) {
String name = BlockProvider.blockName(tag);
String part = tag.get("Properties").get("part").stringValue("head");
String facing = BlockProvider.facing(tag, "south");
return new Bed(name, texture, part, facing);
}

private static Block hugeMushroom(Tag tag, Texture skin) {
private static Block hugeMushroom(Tag tag, AbstractTexture skin) {
String name = BlockProvider.blockName(tag);
Tag properties = tag.get("Properties");
String east = properties.get("east").stringValue("true");
Expand Down Expand Up @@ -3194,7 +3196,7 @@ private static Block pistonHead(Tag tag) {
return new PistonHead(name, type.equals("sticky"), facing);
}

private static Block rail(Tag tag, Texture straightTrack) {
private static Block rail(Tag tag, AbstractTexture straightTrack) {
String name = BlockProvider.blockName(tag);
Tag properties = tag.get("Properties");
String shape = properties.get("shape").stringValue("north-south");
Expand All @@ -3204,7 +3206,7 @@ private static Block rail(Tag tag, Texture straightTrack) {
private static Block poweredRail(Tag tag) {
Tag properties = tag.get("Properties");
String powered = properties.get("powered").stringValue("false");
Texture straightTrack = powered.equals("true") ? Texture.poweredRailOn : Texture.poweredRailOff;
AbstractTexture straightTrack = powered.equals("true") ? Texture.poweredRailOn : Texture.poweredRailOff;
return rail(tag, straightTrack);
}

Expand Down Expand Up @@ -3235,7 +3237,7 @@ private static Block chest(Tag tag, boolean trapped) {
return new Chest(name, type, facing, trapped);
}

private static Block chain(Tag tag, String name, Texture texture) {
private static Block chain(Tag tag, String name, AbstractTexture texture) {
String axis = tag.get("Properties").get("axis").stringValue("y");
return new Chain(name, texture, axis);
}
Expand Down Expand Up @@ -3311,7 +3313,7 @@ private static Block beehive(Tag tag) {
Texture.beehiveEnd);
}

private static Block door(Tag tag, Texture upper, Texture lower) {
private static Block door(Tag tag, AbstractTexture upper, AbstractTexture lower) {
Tag properties = tag.get("Properties");
String name = BlockProvider.blockName(tag);
String facing = BlockProvider.facing(tag);
Expand Down Expand Up @@ -3345,13 +3347,13 @@ private static Block wallHangingSign(Tag tag, String material) {
return new WallHangingSign(BlockProvider.blockName(tag), material, BlockProvider.facing(tag));
}

private static Block banner(Tag tag, Texture texture, BannerDesign.Color color) {
private static Block banner(Tag tag, AbstractTexture texture, BannerDesign.Color color) {
String name = BlockProvider.blockName(tag);
int rotation = BlockProvider.stringToInt(tag.get("Properties").get("rotation"), 0);
return new Banner(name, texture, rotation, color);
}

private static Block wallBanner(Tag tag, Texture texture, BannerDesign.Color color) {
private static Block wallBanner(Tag tag, AbstractTexture texture, BannerDesign.Color color) {
String name = BlockProvider.blockName(tag);
String facing = BlockProvider.facing(tag);
return new WallBanner(name, texture, facing, color);
Expand All @@ -3371,7 +3373,7 @@ private static Block lever(Tag tag) {
return new Lever(face, facing, powered.equals("true"));
}

private static Block button(Tag tag, Texture texture) {
private static Block button(Tag tag, AbstractTexture texture) {
String name = BlockProvider.blockName(tag);
Tag properties = tag.get("Properties");
String face = properties.get("face").stringValue("floor");
Expand All @@ -3397,7 +3399,7 @@ private static Block comparator(Tag tag) {
return new Comparator(facing, mode, powered.equals("true"));
}

private static Block fence(Tag tag, Texture texture) {
private static Block fence(Tag tag, AbstractTexture texture) {
String name = BlockProvider.blockName(tag);
Tag properties = tag.get("Properties");
String north = properties.get("north").stringValue("false");
Expand All @@ -3413,7 +3415,7 @@ private static Block fence(Tag tag, Texture texture) {
west.equals("true"));
}

private static Block fenceGate(Tag tag, Texture texture) {
private static Block fenceGate(Tag tag, AbstractTexture texture) {
String name = BlockProvider.blockName(tag);
Tag properties = tag.get("Properties");
String facing = BlockProvider.facing(tag);
Expand All @@ -3422,7 +3424,7 @@ private static Block fenceGate(Tag tag, Texture texture) {
return new FenceGate(name, texture, facing, in_wall.equals("true"), open.equals("true"));
}

private Block glassPane(Tag tag, Texture side, Texture top) {
private Block glassPane(Tag tag, AbstractTexture side, AbstractTexture top) {
String name = BlockProvider.blockName(tag);
Tag properties = tag.get("Properties");
String north = properties.get("north").stringValue("false");
Expand All @@ -3449,7 +3451,7 @@ private Block ironBars(Tag tag) {
north.equals("true"), south.equals("true"), east.equals("true"), west.equals("true"));
}

private static Block trapdoor(Tag tag, Texture texture) {
private static Block trapdoor(Tag tag, AbstractTexture texture) {
String name = BlockProvider.blockName(tag);
Tag properties = tag.get("Properties");
String half = properties.get("half").stringValue("bottom");
Expand Down Expand Up @@ -3498,7 +3500,7 @@ private Block cocoa(Tag tag) {
return new Cocoa(facing, age);
}

private static Block wall(Tag tag, Texture texture) {
private static Block wall(Tag tag, AbstractTexture texture) {
String name = BlockProvider.blockName(tag);
Tag properties = tag.get("Properties");
String north = properties.get("north").stringValue("false");
Expand All @@ -3509,13 +3511,13 @@ private static Block wall(Tag tag, Texture texture) {
return new Wall(name, texture, north, south, east, west, up.equals("true"));
}

private Block skull(Tag tag, Texture texture, SkullEntity.Kind type) {
private Block skull(Tag tag, AbstractTexture texture, SkullEntity.Kind type) {
String name = BlockProvider.blockName(tag);
int rotation = BlockProvider.stringToInt(tag.get("Properties").get("rotation"), 0);
return new Head(name, texture, type, rotation);
}

private Block wallSkull(Tag tag, Texture texture, SkullEntity.Kind type) {
private Block wallSkull(Tag tag, AbstractTexture texture, SkullEntity.Kind type) {
String name = BlockProvider.blockName(tag);
String facing = BlockProvider.facing(tag);
return new WallHead(name, texture, type, facing);
Expand All @@ -3542,7 +3544,7 @@ private static Block seaPickle(Tag tag) {

private static Block structureBlock(Tag tag) {
Tag properties = tag.get("Properties");
Texture texture = Texture.structureBlock;
AbstractTexture texture = Texture.structureBlock;
String mode = properties.get("mode").stringValue("");
switch (mode) {
case "corner":
Expand All @@ -3561,14 +3563,14 @@ private static Block structureBlock(Tag tag) {
return new MinecraftBlock("structure_block", texture);
}

private static Block candle(Tag tag, Texture candleTexture, Texture candleTextureLit) {
private static Block candle(Tag tag, AbstractTexture candleTexture, AbstractTexture candleTextureLit) {
Tag properties = tag.get("Properties");
return new Candle(BlockProvider.blockName(tag), candleTexture, candleTextureLit,
BlockProvider.stringToInt(properties.get("candles"), 1),
properties.get("lit").stringValue("false").equals("true"));
}

private static Block candleCake(Tag tag, Texture candleTexture, Texture candleTextureLit) {
private static Block candleCake(Tag tag, AbstractTexture candleTexture, AbstractTexture candleTextureLit) {
Tag properties = tag.get("Properties");
return new CakeWithCandle(BlockProvider.blockName(tag), candleTexture, candleTextureLit,
properties.get("lit").stringValue("false").equals("true"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package se.llbit.chunky.block;

import se.llbit.chunky.resources.Texture;
import se.llbit.chunky.resources.texture.AbstractTexture;

/**
* Non-opaque block.
*/
public class MinecraftBlockTranslucent extends MinecraftBlock {
public MinecraftBlockTranslucent(String name, Texture texture) {
public MinecraftBlockTranslucent(String name, AbstractTexture texture) {
super(name, texture);
opaque = false;
solid = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package se.llbit.chunky.block;

import se.llbit.chunky.resources.Texture;
import se.llbit.chunky.resources.texture.AbstractTexture;

public class SolidNonOpaqueBlock extends Block {

public SolidNonOpaqueBlock(String name, Texture texture) {
public SolidNonOpaqueBlock(String name, AbstractTexture texture) {
super(name, texture);
solid = true;
opaque = false;
Expand Down
Loading
Loading