2025-11-24 22:52:51 +03:00

95 lines
3.9 KiB
Java

/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* com.mojang.datafixers.kinds.App
* com.mojang.datafixers.kinds.Applicative
* com.mojang.serialization.Codec
* com.mojang.serialization.MapCodec
* com.mojang.serialization.codecs.RecordCodecBuilder
*/
package net.minecraft.client.renderer.block.model;
import com.mojang.datafixers.kinds.App;
import com.mojang.datafixers.kinds.Applicative;
import com.mojang.math.OctahedralGroup;
import com.mojang.math.Quadrant;
import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.client.renderer.block.model.BlockModelPart;
import net.minecraft.client.renderer.block.model.SimpleModelWrapper;
import net.minecraft.client.renderer.block.model.VariantMutator;
import net.minecraft.client.resources.model.BlockModelRotation;
import net.minecraft.client.resources.model.ModelBaker;
import net.minecraft.client.resources.model.ModelState;
import net.minecraft.client.resources.model.ResolvableModel;
import net.minecraft.resources.Identifier;
public record Variant(Identifier modelLocation, SimpleModelState modelState) implements BlockModelPart.Unbaked
{
public static final MapCodec<Variant> MAP_CODEC = RecordCodecBuilder.mapCodec(i -> i.group((App)Identifier.CODEC.fieldOf("model").forGetter(Variant::modelLocation), (App)SimpleModelState.MAP_CODEC.forGetter(Variant::modelState)).apply((Applicative)i, Variant::new));
public static final Codec<Variant> CODEC = MAP_CODEC.codec();
public Variant(Identifier modelLocation) {
this(modelLocation, SimpleModelState.DEFAULT);
}
public Variant withXRot(Quadrant x) {
return this.withState(this.modelState.withX(x));
}
public Variant withYRot(Quadrant y) {
return this.withState(this.modelState.withY(y));
}
public Variant withUvLock(boolean uvLock) {
return this.withState(this.modelState.withUvLock(uvLock));
}
public Variant withModel(Identifier modelLocation) {
return new Variant(modelLocation, this.modelState);
}
public Variant withState(SimpleModelState modelState) {
return new Variant(this.modelLocation, modelState);
}
public Variant with(VariantMutator mutator) {
return (Variant)mutator.apply(this);
}
@Override
public BlockModelPart bake(ModelBaker modelBakery) {
return SimpleModelWrapper.bake(modelBakery, this.modelLocation, this.modelState.asModelState());
}
@Override
public void resolveDependencies(ResolvableModel.Resolver resolver) {
resolver.markDependency(this.modelLocation);
}
public record SimpleModelState(Quadrant x, Quadrant y, boolean uvLock) {
public static final MapCodec<SimpleModelState> MAP_CODEC = RecordCodecBuilder.mapCodec(i -> i.group((App)Quadrant.CODEC.optionalFieldOf("x", (Object)Quadrant.R0).forGetter(SimpleModelState::x), (App)Quadrant.CODEC.optionalFieldOf("y", (Object)Quadrant.R0).forGetter(SimpleModelState::y), (App)Codec.BOOL.optionalFieldOf("uvlock", (Object)false).forGetter(SimpleModelState::uvLock)).apply((Applicative)i, SimpleModelState::new));
public static final SimpleModelState DEFAULT = new SimpleModelState(Quadrant.R0, Quadrant.R0, false);
public ModelState asModelState() {
BlockModelRotation rotation = BlockModelRotation.get(OctahedralGroup.fromXYAngles(this.x, this.y));
return this.uvLock ? rotation.withUvLock() : rotation;
}
public SimpleModelState withX(Quadrant x) {
return new SimpleModelState(x, this.y, this.uvLock);
}
public SimpleModelState withY(Quadrant y) {
return new SimpleModelState(this.x, y, this.uvLock);
}
public SimpleModelState withUvLock(boolean uvLock) {
return new SimpleModelState(this.x, this.y, uvLock);
}
}
}