generated from Anvil-Dev/ArchitecturyExampleMod
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from ZhuRuoLing/releases/1.20.1
🌟 实现部分方块状态 物品模型 方块模型的DataProvider
- Loading branch information
Showing
23 changed files
with
1,066 additions
and
47 deletions.
There are no files selected for viewing
19 changes: 0 additions & 19 deletions
19
common/src/main/java/dev/anvilcraft/lib/data/AnvilLibBlockModelProvider.java
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
common/src/main/java/dev/anvilcraft/lib/data/AnvilLibItemModelProvider.java
This file was deleted.
Oops, something went wrong.
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
7 changes: 7 additions & 0 deletions
7
common/src/main/java/dev/anvilcraft/lib/data/JsonSerializable.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,7 @@ | ||
package dev.anvilcraft.lib.data; | ||
|
||
import com.google.gson.JsonElement; | ||
|
||
public interface JsonSerializable { | ||
JsonElement toJsonElement(); | ||
} |
10 changes: 10 additions & 0 deletions
10
common/src/main/java/dev/anvilcraft/lib/data/file/BlockModelFile.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,10 @@ | ||
package dev.anvilcraft.lib.data.file; | ||
|
||
import net.minecraft.resources.ResourceLocation; | ||
|
||
public class BlockModelFile extends ModelFile<BlockModelFile> { | ||
|
||
public BlockModelFile(ResourceLocation location) { | ||
super(location); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
common/src/main/java/dev/anvilcraft/lib/data/file/BlockStateFile.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,40 @@ | ||
package dev.anvilcraft.lib.data.file; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class BlockStateFile extends ResourceFile { | ||
|
||
private final Map<BlockStateVariantKey, BlockStateVariant> variants = new HashMap<>(); | ||
|
||
public BlockStateFile(ResourceLocation location) { | ||
super(location); | ||
} | ||
|
||
public BlockStateFile single(BlockStateVariant v) { | ||
variants.put(new BlockStateVariantKey(), v); | ||
return this; | ||
} | ||
|
||
public BlockStateFile variant( | ||
BlockStateVariantKey key, | ||
BlockStateVariant variant | ||
) { | ||
this.variants.put(key, variant); | ||
return this; | ||
} | ||
|
||
@Override | ||
public JsonElement toJsonElement() { | ||
JsonObject root = new JsonObject(); | ||
JsonObject variants = new JsonObject(); | ||
this.variants.forEach((key, var) -> variants.add(key.toString(), var.toJsonElement())); | ||
root.add("variants", variants); | ||
return root; | ||
} | ||
|
||
} |
68 changes: 68 additions & 0 deletions
68
common/src/main/java/dev/anvilcraft/lib/data/file/BlockStateVariant.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,68 @@ | ||
package dev.anvilcraft.lib.data.file; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonPrimitive; | ||
import dev.anvilcraft.lib.data.JsonSerializable; | ||
import lombok.Getter; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
import java.util.function.Consumer; | ||
|
||
@Getter | ||
public class BlockStateVariant implements JsonSerializable { | ||
|
||
private String model; | ||
private int rotationX = 0; | ||
private int rotationY = 0; | ||
private boolean uvLock = false; | ||
|
||
public BlockStateVariant model(String model) { | ||
this.model = model; | ||
return this; | ||
} | ||
|
||
public BlockStateVariant model(ResourceLocation model) { | ||
return model(model.toString()); | ||
} | ||
|
||
public BlockStateVariant rotationX(int rotation) { | ||
rotationX = rotation; | ||
return this; | ||
} | ||
|
||
public BlockStateVariant uvLock(boolean l){ | ||
this.uvLock = l; | ||
return this; | ||
} | ||
|
||
public BlockStateVariant rotationY(int rotation) { | ||
rotationY = rotation; | ||
return this; | ||
} | ||
|
||
public static BlockStateVariant build(Consumer<BlockStateVariant> builder){ | ||
BlockStateVariant key = new BlockStateVariant(); | ||
builder.accept(key); | ||
return key; | ||
} | ||
|
||
public static BlockStateVariant fromModel(ResourceLocation resourceLocation){ | ||
String ns = resourceLocation.getNamespace(); | ||
String path = resourceLocation.getPath(); | ||
if (path.startsWith("models/")){ | ||
path = path.replaceFirst("models/", ""); | ||
} | ||
return new BlockStateVariant().model(new ResourceLocation(ns, path)); | ||
} | ||
|
||
@Override | ||
public JsonElement toJsonElement() { | ||
JsonObject root = new JsonObject(); | ||
root.add("model", new JsonPrimitive(model)); | ||
root.add("x", new JsonPrimitive(rotationX)); | ||
root.add("y", new JsonPrimitive(rotationY)); | ||
root.add("uvlock", new JsonPrimitive(uvLock)); | ||
return root; | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
common/src/main/java/dev/anvilcraft/lib/data/file/BlockStateVariantKey.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,74 @@ | ||
package dev.anvilcraft.lib.data.file; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonPrimitive; | ||
import dev.anvilcraft.lib.data.JsonSerializable; | ||
import net.minecraft.world.level.block.state.properties.Property; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
|
||
public class BlockStateVariantKey implements JsonSerializable { | ||
private final List<BlockStateVariantKeyPair<?, ?>> keyPairs = new ArrayList<>(); | ||
|
||
public <T extends Property<V>, V extends Comparable<V>> BlockStateVariantKey then( | ||
T property, | ||
V value | ||
) { | ||
keyPairs.add(BlockStateVariantKeyPair.of(property, value)); | ||
return this; | ||
} | ||
|
||
public static <T extends Property<V>, V extends Comparable<V>> BlockStateVariantKey with( | ||
T property, | ||
V value | ||
) { | ||
return new BlockStateVariantKey().then(property, value); | ||
} | ||
|
||
public static BlockStateVariantKey build(Consumer<BlockStateVariantKey> builder) { | ||
BlockStateVariantKey key = new BlockStateVariantKey(); | ||
builder.accept(key); | ||
return key; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder sb = new StringBuilder(); | ||
for (int i = 0; i < keyPairs.size(); i++) { | ||
if (i != 0) { | ||
sb.append(","); | ||
} | ||
sb.append(keyPairs.get(i).toString()); | ||
} | ||
return sb.toString(); | ||
} | ||
|
||
@Override | ||
public JsonElement toJsonElement() { | ||
JsonObject root = new JsonObject(); | ||
keyPairs.forEach(kp -> kp.encodeIntoJsonObject(root)); | ||
return root; | ||
} | ||
|
||
public record BlockStateVariantKeyPair<T extends Property<V>, V extends Comparable<V>>(T property, V value) { | ||
|
||
@Override | ||
public String toString() { | ||
return property.getName() + "=" + property.getName(value); | ||
} | ||
|
||
public static <T extends Property<V>, V extends Comparable<V>> BlockStateVariantKeyPair<T, V> of( | ||
T property, | ||
V value | ||
) { | ||
return new BlockStateVariantKeyPair<>(property, value); | ||
} | ||
|
||
public void encodeIntoJsonObject(JsonObject root) { | ||
root.add(property.getName(), new JsonPrimitive(property.getName(value))); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
common/src/main/java/dev/anvilcraft/lib/data/file/ItemModelFile.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,11 @@ | ||
package dev.anvilcraft.lib.data.file; | ||
|
||
import net.minecraft.resources.ResourceLocation; | ||
|
||
public class ItemModelFile extends ModelFile<ItemModelFile> { | ||
public ItemModelFile(ResourceLocation location) { | ||
super(location); | ||
} | ||
|
||
|
||
} |
70 changes: 70 additions & 0 deletions
70
common/src/main/java/dev/anvilcraft/lib/data/file/ModelFile.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,70 @@ | ||
package dev.anvilcraft.lib.data.file; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonPrimitive; | ||
import lombok.Getter; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* simple implementation for block/item model file | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
@Getter | ||
public class ModelFile<T extends ModelFile<T>> extends ResourceFile { | ||
protected final Map<String, String> textures = new HashMap<>(); | ||
protected String parent; | ||
protected String renderType; | ||
|
||
public ModelFile(ResourceLocation location) { | ||
super(location); | ||
} | ||
|
||
public T texture(String key, String texture){ | ||
textures.put(key, texture); | ||
return (T) this; | ||
} | ||
|
||
public T texture(String key, ResourceLocation texture){ | ||
textures.put(key, texture.toString()); | ||
return (T) this; | ||
} | ||
|
||
|
||
public T parent(String p){ | ||
this.parent = p; | ||
return (T) this; | ||
} | ||
|
||
public T parent(ResourceLocation p){ | ||
this.parent = p.toString(); | ||
return (T) this; | ||
} | ||
|
||
public T renderType(String r){ | ||
this.renderType = r; | ||
return (T) this; | ||
} | ||
|
||
@Override | ||
public JsonElement toJsonElement(){ | ||
JsonObject jsonObject = new JsonObject(); | ||
if (!textures.isEmpty()){ | ||
JsonObject jTextures = new JsonObject(); | ||
textures.forEach((k,v) -> { | ||
jTextures.add(k, new JsonPrimitive(v)); | ||
}); | ||
jsonObject.add("textures", jTextures); | ||
} | ||
if (parent != null){ | ||
jsonObject.add("parent", new JsonPrimitive(parent)); | ||
} | ||
if (renderType != null){ | ||
jsonObject.add("render_type", new JsonPrimitive(renderType)); | ||
} | ||
return jsonObject; | ||
} | ||
} |
Oops, something went wrong.