-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make Sunken variants data-driven (#191)
- Loading branch information
Showing
16 changed files
with
468 additions
and
248 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
54 changes: 54 additions & 0 deletions
54
src/main/java/fr/hugman/promenade/entity/SunkenVariant.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,54 @@ | ||
package fr.hugman.promenade.entity; | ||
|
||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import net.minecraft.loot.LootTable; | ||
import net.minecraft.registry.RegistryKey; | ||
import net.minecraft.registry.RegistryKeys; | ||
import net.minecraft.util.Identifier; | ||
|
||
import java.util.Objects; | ||
|
||
public final class SunkenVariant { | ||
public static final Codec<SunkenVariant> CODEC = RecordCodecBuilder.create(instance -> instance.group( | ||
Identifier.CODEC.fieldOf("texture").forGetter(sunken -> sunken.texture), | ||
RegistryKey.createCodec(RegistryKeys.LOOT_TABLE).fieldOf("loot_table").forGetter(sunken -> sunken.lootTable) | ||
).apply(instance, SunkenVariant::new)); | ||
|
||
private final Identifier texture; | ||
private final RegistryKey<LootTable> lootTable; | ||
|
||
private final Identifier texturePath; | ||
|
||
public SunkenVariant(Identifier texture, RegistryKey<LootTable> lootTable) { | ||
this.texture = texture; | ||
this.lootTable = lootTable; | ||
|
||
this.texturePath = getTexturePath(texture); | ||
} | ||
|
||
public Identifier texture() { | ||
return texturePath; | ||
} | ||
|
||
public RegistryKey<LootTable> lootTable() { | ||
return lootTable; | ||
} | ||
|
||
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 = (SunkenVariant) obj; | ||
return Objects.equals(this.texture, that.texture); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(texture); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/fr/hugman/promenade/entity/SunkenVariants.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,18 @@ | ||
package fr.hugman.promenade.entity; | ||
|
||
import fr.hugman.promenade.Promenade; | ||
import fr.hugman.promenade.registry.PromenadeRegistryKeys; | ||
import net.minecraft.registry.RegistryKey; | ||
import net.minecraft.util.Identifier; | ||
|
||
public class SunkenVariants { | ||
public static final RegistryKey<SunkenVariant> BUBBLE = of("bubble"); | ||
|
||
private static RegistryKey<SunkenVariant> of(String path) { | ||
return of(Promenade.id(path)); | ||
} | ||
|
||
public static RegistryKey<SunkenVariant> of(Identifier id) { | ||
return RegistryKey.of(PromenadeRegistryKeys.SUNKEN_VARIANT, id); | ||
} | ||
} |
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
2 changes: 2 additions & 0 deletions
2
src/main/java/fr/hugman/promenade/registry/PromenadeRegistries.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 |
---|---|---|
@@ -1,10 +1,12 @@ | ||
package fr.hugman.promenade.registry; | ||
|
||
import fr.hugman.promenade.entity.CapybaraVariant; | ||
import fr.hugman.promenade.entity.SunkenVariant; | ||
import net.fabricmc.fabric.api.event.registry.DynamicRegistries; | ||
|
||
public class PromenadeRegistries { | ||
public static void register() { | ||
DynamicRegistries.registerSynced(PromenadeRegistryKeys.CAPYBARA_VARIANT, CapybaraVariant.CODEC); | ||
DynamicRegistries.registerSynced(PromenadeRegistryKeys.SUNKEN_VARIANT, SunkenVariant.CODEC); | ||
} | ||
} |
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
Oops, something went wrong.