Skip to content

Commit

Permalink
Better texture paths for Capybara variants
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugman76 committed Apr 6, 2024
1 parent 9bb6329 commit 7c1a774
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ public Data(RegistryEntry<CapybaraVariant> variant) {
/* TEXTURES */
/*==============*/

public Identifier getBaseTexture() {
public Identifier getTexture() {
var variant = this.getVariant().value();
if (this.hasClosedEyes()) {
return variant.closedEyesTexture();
Expand Down
82 changes: 67 additions & 15 deletions src/main/java/fr/hugman/promenade/entity/CapybaraVariant.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,75 @@

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import fr.hugman.promenade.registry.PromenadeRegistryKeys;
import net.minecraft.registry.entry.RegistryElementCodec;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.util.Identifier;

//TODO : .withPath(oldPath -> "textures/" + oldPath + ".png")
public record CapybaraVariant(
int spawnWeight,
Identifier smallEyesTexture,
Identifier largeEyesTexture,
Identifier closedEyesTexture
) {
import java.util.Objects;

public final class CapybaraVariant {
public static final Codec<CapybaraVariant> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codec.INT.fieldOf("spawn_weight").forGetter(CapybaraVariant::spawnWeight),
Identifier.CODEC.fieldOf("small_eyes_texture").forGetter(CapybaraVariant::smallEyesTexture),
Identifier.CODEC.fieldOf("large_eyes_texture").forGetter(CapybaraVariant::largeEyesTexture),
Identifier.CODEC.fieldOf("closed_eyes_texture").forGetter(CapybaraVariant::closedEyesTexture)
Identifier.CODEC.fieldOf("small_eyes_texture").forGetter(capybara -> capybara.smallEyesTexture),
Identifier.CODEC.fieldOf("large_eyes_texture").forGetter(capybara -> capybara.largeEyesTexture),
Identifier.CODEC.fieldOf("closed_eyes_texture").forGetter(capybara -> capybara.closedEyesTexture),
Codec.INT.fieldOf("spawn_weight").forGetter(CapybaraVariant::spawnWeight)
).apply(instance, CapybaraVariant::new));
public static final Codec<RegistryEntry<CapybaraVariant>> ENTRY_CODEC = RegistryElementCodec.of(PromenadeRegistryKeys.CAPYBARA_VARIANT, CODEC);

private final Identifier smallEyesTexture;
private final Identifier largeEyesTexture;
private final Identifier closedEyesTexture;
private final int spawnWeight;

private final Identifier smallEyesTexturePath;
private final Identifier largeEyesTexturePath;
private final Identifier closedEyesTexturePath;

public CapybaraVariant(
Identifier smallEyesTexture,
Identifier largeEyesTexture,
Identifier closedEyesTexture,
int spawnWeight
) {
this.smallEyesTexture = smallEyesTexture;
this.smallEyesTexturePath = getTexturePath(smallEyesTexture);
this.largeEyesTexture = largeEyesTexture;
this.largeEyesTexturePath = getTexturePath(largeEyesTexture);
this.closedEyesTexture = closedEyesTexture;
this.closedEyesTexturePath = getTexturePath(closedEyesTexture);
this.spawnWeight = spawnWeight;
}

public Identifier smallEyesTexture() {
return smallEyesTexturePath;
}

public Identifier largeEyesTexture() {
return largeEyesTexturePath;
}

public Identifier closedEyesTexture() {
return closedEyesTexturePath;
}

public int spawnWeight() {
return spawnWeight;
}

private static Identifier getTexturePath(Identifier id) {
return id.withPath(oldPath -> "textures/" + oldPath + ".png");
}

@Override
public boolean equals(Object obj) {
if (obj == this) return true;
if (obj == null || obj.getClass() != this.getClass()) return false;
var that = (CapybaraVariant) obj;
return this.spawnWeight == that.spawnWeight &&
Objects.equals(this.smallEyesTexture, that.smallEyesTexture) &&
Objects.equals(this.largeEyesTexture, that.largeEyesTexture) &&
Objects.equals(this.closedEyesTexture, that.closedEyesTexture);
}

@Override
public int hashCode() {
return Objects.hash(spawnWeight, smallEyesTexture, largeEyesTexture, closedEyesTexture);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"spawn_weight": 1,
"small_eyes_texture": "promenade:textures/entity/capybara/albino/small_eyes.png",
"large_eyes_texture": "promenade:textures/entity/capybara/albino/large_eyes.png",
"closed_eyes_texture": "promenade:textures/entity/capybara/albino/closed_eyes.png"
"small_eyes_texture": "promenade:entity/capybara/albino/small_eyes",
"large_eyes_texture": "promenade:entity/capybara/albino/large_eyes",
"closed_eyes_texture": "promenade:entity/capybara/albino/closed_eyes",
"spawn_weight": 1
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"spawn_weight": 49,
"small_eyes_texture": "promenade:textures/entity/capybara/brown/small_eyes.png",
"large_eyes_texture": "promenade:textures/entity/capybara/brown/large_eyes.png",
"closed_eyes_texture": "promenade:textures/entity/capybara/brown/closed_eyes.png"
"small_eyes_texture": "promenade:entity/capybara/brown/small_eyes",
"large_eyes_texture": "promenade:entity/capybara/brown/large_eyes",
"closed_eyes_texture": "promenade:entity/capybara/brown/closed_eyes",
"spawn_weight": 49
}

0 comments on commit 7c1a774

Please sign in to comment.