Skip to content

Commit

Permalink
Add 22w42a (crafter) and 22w43a (copper & tuff additions) blocks (#1657)
Browse files Browse the repository at this point in the history
* 22w42a (crafter) and 22w43a (copper & tuff additions)

* code cleanup
  • Loading branch information
JustinTimeCuber authored Oct 26, 2023
1 parent 3cced1a commit 26cad1e
Show file tree
Hide file tree
Showing 9 changed files with 493 additions and 32 deletions.
47 changes: 45 additions & 2 deletions chunky/src/java/se/llbit/chunky/block/MinecraftBlockProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import se.llbit.chunky.entity.SkullEntity;
import se.llbit.chunky.model.minecraft.FlowerPotModel;
import se.llbit.chunky.model.minecraft.FlowerPotModel.Kind;
import se.llbit.chunky.resources.EntityTexture;
import se.llbit.chunky.resources.ShulkerTexture;
import se.llbit.chunky.resources.Texture;
import se.llbit.chunky.world.BlockData;
Expand Down Expand Up @@ -1005,7 +1004,6 @@ private static void addBlocks(Texture texture, String... names) {
addBlock("bamboo_mosaic_slab", (name, tag) -> slab(tag, Texture.bambooMosaic));
addBlock("bamboo_mosaic_stairs", (name, tag) -> stairs(tag, Texture.bambooMosaic));
addBlock("bamboo_trapdoor", (name, tag) -> trapdoor(tag, Texture.bambooTrapdoor));

addBlock("cherry_button", (name, tag) -> button(tag, Texture.cherryPlanks));
addBlock("cherry_door", (name, tag) -> door(tag, Texture.cherryDoorTop, Texture.cherryDoorBottom));
addBlock("cherry_fence", (name, tag) -> fence(tag, Texture.cherryPlanks));
Expand Down Expand Up @@ -1074,6 +1072,51 @@ private static void addBlocks(Texture texture, String... names) {
addBlock("bamboo_wall_hanging_sign", (name, tag) -> wallHangingSign(tag, "bamboo"));
addBlock("cherry_hanging_sign", (name, tag) -> hangingSign(tag, "cherry"));
addBlock("cherry_wall_hanging_sign", (name, tag) -> wallHangingSign(tag, "cherry"));

//1.21
addBlock("tuff_slab", (name, tag) -> slab(tag, Texture.tuff));
addBlock("tuff_stairs", (name, tag) -> stairs(tag, Texture.tuff));
addBlock("tuff_wall", (name, tag) -> wall(tag, Texture.tuff));
addBlock("polished_tuff", Texture.polishedTuff);
addBlock("polished_tuff_slab", (name, tag) -> slab(tag, Texture.polishedTuff));
addBlock("polished_tuff_stairs", (name, tag) -> stairs(tag, Texture.polishedTuff));
addBlock("polished_tuff_wall", (name, tag) -> wall(tag, Texture.polishedTuff));
addBlock("tuff_bricks", Texture.tuffBricks);
addBlock("tuff_brick_slab", (name, tag) -> slab(tag, Texture.tuffBricks));
addBlock("tuff_brick_stairs", (name, tag) -> stairs(tag, Texture.tuffBricks));
addBlock("tuff_brick_wall", (name, tag) -> wall(tag, Texture.tuffBricks));
addBlock("chiseled_tuff", Texture.chiseledTuff);
addBlock("chiseled_tuff_bricks", Texture.chiseledTuffBricks);
for(String s : new String[]{"", "waxed_"}) {
addBlock(s + "chiseled_copper", Texture.chiseledCopper);
addBlock(s + "copper_grate", (name, tag) -> new SolidNonOpaqueBlock(name, Texture.copperGrate));
addBlock(s + "copper_bulb", (name, tag) -> new CopperBulb(name, tag.get("Properties").get("lit").stringValue().equals("true"), tag.get("Properties").get("powered").stringValue().equals("true"),
Texture.copperBulbLitPowered, Texture.copperBulbLit, Texture.copperBulbPowered, Texture.copperBulb));
addBlock(s + "copper_door", (name, tag) -> door(tag, Texture.copperDoorTop, Texture.copperDoorBottom));
addBlock(s + "copper_trapdoor", (name, tag) -> trapdoor(tag, Texture.copperTrapdoor));
addBlock(s + "exposed_chiseled_copper", Texture.exposedChiseledCopper);
addBlock(s + "exposed_copper_grate", Texture.exposedCopperGrate);
addBlock(s + "exposed_copper_bulb", (name, tag) -> new CopperBulb(name, tag.get("Properties").get("lit").stringValue().equals("true"), tag.get("Properties").get("powered").stringValue().equals("true"),
Texture.exposedCopperBulbLitPowered, Texture.exposedCopperBulbLit, Texture.exposedCopperBulbPowered, Texture.exposedCopperBulb));
addBlock(s + "exposed_copper_door", (name, tag) -> door(tag, Texture.exposedCopperDoorTop, Texture.exposedCopperDoorBottom));
addBlock(s + "exposed_copper_trapdoor", (name, tag) -> trapdoor(tag, Texture.exposedCopperTrapdoor));
addBlock(s + "weathered_chiseled_copper", Texture.weatheredChiseledCopper);
addBlock(s + "weathered_copper_grate", Texture.weatheredCopperGrate);
addBlock(s + "weathered_copper_bulb", (name, tag) -> new CopperBulb(name, tag.get("Properties").get("lit").stringValue().equals("true"), tag.get("Properties").get("powered").stringValue().equals("true"),
Texture.weatheredCopperBulbLitPowered, Texture.weatheredCopperBulbLit, Texture.weatheredCopperBulbPowered, Texture.weatheredCopperBulb));
addBlock(s + "weathered_copper_door", (name, tag) -> door(tag, Texture.weatheredCopperDoorTop, Texture.weatheredCopperDoorBottom));
addBlock(s + "weathered_copper_trapdoor", (name, tag) -> trapdoor(tag, Texture.weatheredCopperTrapdoor));
addBlock(s + "oxidized_chiseled_copper", Texture.oxidizedChiseledCopper);
addBlock(s + "oxidized_copper_grate", Texture.oxidizedCopperGrate);
addBlock(s + "oxidized_copper_bulb", (name, tag) -> new CopperBulb(name, tag.get("Properties").get("lit").stringValue().equals("true"), tag.get("Properties").get("powered").stringValue().equals("true"),
Texture.oxidizedCopperBulbLitPowered, Texture.oxidizedCopperBulbLit, Texture.oxidizedCopperBulbPowered, Texture.oxidizedCopperBulb));
addBlock(s + "oxidized_copper_door", (name, tag) -> door(tag, Texture.oxidizedCopperDoorTop, Texture.oxidizedCopperDoorBottom));
addBlock(s + "oxidized_copper_trapdoor", (name, tag) -> trapdoor(tag, Texture.oxidizedCopperTrapdoor));
}
addBlock("crafter", (name, tag) -> new Crafter(name, tag.get("Properties").get("orientation").stringValue(), tag.get("Properties").get("crafting").stringValue().equals("true"), tag.get("Properties").get("triggered").stringValue().equals("true"),
Texture.crafterNorth, Texture.crafterNorthCrafting, Texture.crafterEast, Texture.crafterEastCrafting, Texture.crafterEastTriggered,
Texture.crafterSouth, Texture.crafterSouthTriggered, Texture.crafterWest, Texture.crafterWestCrafting, Texture.crafterWestTriggered,
Texture.crafterTop, Texture.crafterTopCrafting, Texture.crafterTopTriggered, Texture.crafterBottom));
}

@Override
Expand Down
12 changes: 12 additions & 0 deletions chunky/src/java/se/llbit/chunky/block/SolidNonOpaqueBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package se.llbit.chunky.block;

import se.llbit.chunky.resources.Texture;

public class SolidNonOpaqueBlock extends Block {

public SolidNonOpaqueBlock(String name, Texture texture) {
super(name, texture);
solid = true;
opaque = false;
}
}
44 changes: 44 additions & 0 deletions chunky/src/java/se/llbit/chunky/block/minecraft/CopperBulb.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2023 Chunky contributors
*
* This file is part of Chunky.
*
* Chunky 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.
*
* Chunky 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 Chunky. If not, see <http://www.gnu.org/licenses/>.
*/

package se.llbit.chunky.block.minecraft;

import se.llbit.chunky.block.MinecraftBlock;
import se.llbit.chunky.resources.Texture;

public class CopperBulb extends MinecraftBlock {
private final boolean lit;
private final boolean powered;

public CopperBulb(String name, boolean lit, boolean powered, Texture lp, Texture lnp, Texture nlp, Texture nlnp) {
super(name, lit ? (powered ? lp : lnp) : (powered ? nlp : nlnp));
this.lit = lit;
this.powered = powered;
}
public boolean isLit() {
return lit;
}

public boolean isPowered() {
return powered;
}

@Override public String description() {
return "lit=" + lit + ", powered=" + powered;
}
}
100 changes: 100 additions & 0 deletions chunky/src/java/se/llbit/chunky/block/minecraft/Crafter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Copyeast (c) 2023 Chunky contributors
*
* This file is part of Chunky.
*
* Chunky 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.
*
* Chunky 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 Chunky. If not, see <http://www.gnu.org/licenses/>.
*/

package se.llbit.chunky.block.minecraft;

import se.llbit.chunky.block.AbstractModelBlock;
import se.llbit.chunky.model.RotatableBlockModel;
import se.llbit.chunky.resources.Texture;
import se.llbit.math.Quad;
import se.llbit.math.Vector3;
import se.llbit.math.Vector4;

public class Crafter extends AbstractModelBlock {

private final String description;

public Crafter(String name, String orientation, boolean crafting, boolean triggered, Texture north, Texture northCrafting, Texture east, Texture eastCrafting, Texture eastTriggered,
Texture south, Texture southTriggered, Texture west, Texture westCrafting, Texture westTriggered, Texture top, Texture topCrafting, Texture topTriggered, Texture bottom) {
super(name, north);
this.description = "orientation=" + orientation + ", crafting=" + crafting + ", triggered=" + triggered;
RotatableBlockModel m = new RotatableBlockModel(crafting ? northCrafting : north,
crafting ? eastCrafting : (triggered ? eastTriggered : east),
triggered ? southTriggered : south,
crafting ? westCrafting : (triggered ? westTriggered : west),
crafting ? topCrafting : (triggered ? topTriggered : top),
bottom);
// Fix top quad
m.setFaceQuad(4, new Quad(
new Vector3(1, 1, 0),
new Vector3(0, 1, 0),
new Vector3(1, 1, 1),
new Vector4(1, 0, 0, 1))); // texture is mirrored for some reason??
switch(orientation) {
case "north_up":
break;
case "east_up":
m.rotateY(1);
break;
case "south_up":
m.rotateY(2);
break;
case "west_up":
m.rotateY(-1);
break;
case "up_south":
m.rotateX(1);
break;
case "up_west":
m.rotateX(1);
m.rotateY(1);
break;
case "up_north":
m.rotateX(1);
m.rotateY(2);
break;
case "up_east":
m.rotateX(1);
m.rotateY(-1);
break;
case "down_north":
m.rotateX(-1);
break;
case "down_east":
m.rotateX(-1);
m.rotateY(1);
break;
case "down_south":
m.rotateX(-1);
m.rotateY(2);
break;
case "down_west":
m.rotateX(-1);
m.rotateY(-1);
break;
}
this.model = m;
opaque = true;
solid = true;
}

@Override
public String description() {
return description;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@
import se.llbit.chunky.resources.Texture;

public class RedstoneLamp extends MinecraftBlock {
public final boolean isLit;
private final boolean lit;

public RedstoneLamp(boolean lit) {
super("redstone_lamp", lit ? Texture.redstoneLampOn : Texture.redstoneLampOff);
this.isLit = lit;
this.lit = lit;
}

public boolean isLit() {
return lit;
}

@Override public String description() {
return "lit=" + isLit;
return "lit=" + lit;
}
}
81 changes: 54 additions & 27 deletions chunky/src/java/se/llbit/chunky/chunk/BlockPalette.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import se.llbit.chunky.block.*;
import se.llbit.chunky.block.minecraft.*;
import se.llbit.chunky.plugin.PluginApi;
import se.llbit.chunky.resources.Texture;
import se.llbit.math.Octree;
import se.llbit.nbt.CompoundTag;
import se.llbit.nbt.IntTag;
Expand Down Expand Up @@ -380,7 +381,7 @@ public static Map<String, Consumer<Block>> getDefaultMaterialProperties() {
block.ior = 1.52f;
});
materialProperties.put("minecraft:redstone_lamp", block -> {
if (block instanceof RedstoneLamp && ((RedstoneLamp) block).isLit) {
if (block instanceof RedstoneLamp && ((RedstoneLamp) block).isLit()) {
block.emittance = 1.0f;
}
});
Expand Down Expand Up @@ -480,42 +481,46 @@ public static Map<String, Consumer<Block>> getDefaultMaterialProperties() {
block.metalness = 1.0f;
block.setPerceptualSmoothness(0.75);
};
Consumer<Block> lightlyWeatheredCopperConfig = block -> {
Consumer<Block> exposedCopperConfig = block -> {
block.metalness = 0.66f;
block.setPerceptualSmoothness(0.75);
};
Consumer<Block> semiWeatheredCopperConfig = block -> {
Consumer<Block> weatheredCopperConfig = block -> {
block.metalness = 0.66f;
block.setPerceptualSmoothness(0.75);
};
materialProperties.put("minecraft:copper_block", copperConfig);
materialProperties.put("minecraft:raw_copper_block", block -> {
block.metalness = 0.66f;
block.setPerceptualSmoothness(0.5);
});
materialProperties.put("minecraft:exposed_copper", lightlyWeatheredCopperConfig);
materialProperties.put("minecraft:weathered_copper", semiWeatheredCopperConfig);
materialProperties.put("minecraft:cut_copper", copperConfig);
materialProperties.put("minecraft:exposed_cut_copper", lightlyWeatheredCopperConfig);
materialProperties.put("minecraft:weathered_cut_copper", semiWeatheredCopperConfig);
materialProperties.put("minecraft:cut_copper_stairs", copperConfig);
materialProperties.put("minecraft:exposed_cut_copper_stairs", lightlyWeatheredCopperConfig);
materialProperties.put("minecraft:weathered_cut_copper_stairs", semiWeatheredCopperConfig);
materialProperties.put("minecraft:cut_copper_slab", copperConfig);
materialProperties.put("minecraft:exposed_cut_copper_slab", lightlyWeatheredCopperConfig);
materialProperties.put("minecraft:weathered_cut_copper_slab", semiWeatheredCopperConfig);
materialProperties.put("minecraft:waxed_copper_block", copperConfig);
materialProperties.put("minecraft:waxed_exposed_copper", lightlyWeatheredCopperConfig);
materialProperties.put("minecraft:waxed_weathered_copper", semiWeatheredCopperConfig);
materialProperties.put("minecraft:waxed_cut_copper", copperConfig);
materialProperties.put("minecraft:waxed_exposed_cut_copper", lightlyWeatheredCopperConfig);
materialProperties.put("minecraft:waxed_weathered_cut_copper", semiWeatheredCopperConfig);
materialProperties.put("minecraft:waxed_cut_copper_stairs", copperConfig);
materialProperties.put("minecraft:waxed_exposed_cut_copper_stairs", lightlyWeatheredCopperConfig);
materialProperties.put("minecraft:waxed_weathered_cut_copper_stairs", semiWeatheredCopperConfig);
materialProperties.put("minecraft:waxed_cut_copper_slab", copperConfig);
materialProperties.put("minecraft:waxed_exposed_cut_copper_slab", lightlyWeatheredCopperConfig);
materialProperties.put("minecraft:waxed_weathered_cut_copper_slab", semiWeatheredCopperConfig);
for(String s : new String[]{"minecraft:", "minecraft:waxed_"}) {
materialProperties.put(s + "copper_block", copperConfig);
materialProperties.put(s + "cut_copper", copperConfig);
materialProperties.put(s + "cut_copper_stairs", copperConfig);
materialProperties.put(s + "cut_copper_slab", copperConfig);
materialProperties.put(s + "chiseled_copper", copperConfig);
materialProperties.put(s + "copper_grate", copperConfig);
materialProperties.put(s + "copper_door", copperConfig);
materialProperties.put(s + "copper_trapdoor", copperConfig);

materialProperties.put(s + "exposed_copper", exposedCopperConfig);
materialProperties.put(s + "exposed_cut_copper", exposedCopperConfig);
materialProperties.put(s + "exposed_cut_copper_stairs", exposedCopperConfig);
materialProperties.put(s + "exposed_cut_copper_slab", exposedCopperConfig);
materialProperties.put(s + "exposed_chiseled_copper", exposedCopperConfig);
materialProperties.put(s + "exposed_copper_grate", exposedCopperConfig);
materialProperties.put(s + "exposed_copper_door", exposedCopperConfig);
materialProperties.put(s + "exposed_copper_trapdoor", exposedCopperConfig);

materialProperties.put(s + "weathered_copper", weatheredCopperConfig);
materialProperties.put(s + "weathered_cut_copper", weatheredCopperConfig);
materialProperties.put(s + "weathered_cut_copper_stairs", weatheredCopperConfig);
materialProperties.put(s + "weathered_cut_copper_slab", weatheredCopperConfig);
materialProperties.put(s + "weathered_chiseled_copper", weatheredCopperConfig);
materialProperties.put(s + "weathered_copper_grate", weatheredCopperConfig);
materialProperties.put(s + "weathered_copper_door", weatheredCopperConfig);
materialProperties.put(s + "weathered_copper_trapdoor", weatheredCopperConfig);
}
materialProperties.put("minecraft:lightning_rod", block -> {
// apply copper attributes only to non-powered lightning rods
if (block instanceof LightningRod && !((LightningRod) block).isPowered()) {
Expand Down Expand Up @@ -575,6 +580,28 @@ public static Map<String, Consumer<Block>> getDefaultMaterialProperties() {
materialProperties.put("minecraft:sculk_catalyst", block -> {
block.emittance = 1.0f / 15f * 6;
});
for(String s : new String[]{"minecraft:", "minecraft:waxed_"}) {
materialProperties.put(s + "copper_bulb", block -> {
if(block instanceof CopperBulb && ((CopperBulb) block).isLit()) {
block.emittance = 1.0f;
}
});
materialProperties.put(s + "exposed_copper_bulb", block -> {
if(block instanceof CopperBulb && ((CopperBulb) block).isLit()) {
block.emittance = 12 / 15f;
}
});
materialProperties.put(s + "weathered_copper_bulb", block -> {
if(block instanceof CopperBulb && ((CopperBulb) block).isLit()) {
block.emittance = 8 / 15f;
}
});
materialProperties.put(s + "oxidized_copper_bulb", block -> {
if(block instanceof CopperBulb && ((CopperBulb) block).isLit()) {
block.emittance = 4 / 15f;
}
});
}
return materialProperties;
}

Expand Down
12 changes: 12 additions & 0 deletions chunky/src/java/se/llbit/chunky/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,18 @@ public static Quad[] rotateZ(Quad[] src) {
return rot;
}

/**
* @param src source quads
* @return Quads rotated about the negative Z axis
*/
public static Quad[] rotateNegZ(Quad[] src) {
Quad[] rot = new Quad[src.length];
for (int i = 0; i < src.length; ++i) {
rot[i] = src[i].transform(Transform.NONE.rotateNegZ());
}
return rot;
}

/**
* @param src source quads
* @return Quads rotated about the Z axis by some angle
Expand Down
Loading

0 comments on commit 26cad1e

Please sign in to comment.