Skip to content

Commit

Permalink
fix: AnimModel (5)
Browse files Browse the repository at this point in the history
  • Loading branch information
MegumiKasuga committed Dec 2, 2024
1 parent a411153 commit 2047e4e
Show file tree
Hide file tree
Showing 14 changed files with 158 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"variants": {
"facing=north": {
"model": "kasuga_lib:block/test/test_model_complicate"
},
"facing=south": {
"model": "kasuga_lib:block/test/test_model_complicate",
"y": 180
},
"facing=east": {
"model": "kasuga_lib:block/test/test_model_complicate",
"y": 270
},
"facing=west": {
"model": "kasuga_lib:block/test/test_model_complicate",
"y": 90
}
},
"model": "kasuga_lib:block/test/rotation_test_model"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"format_version": "1.12.0",
"minecraft:geometry": [
{
"description": {
"identifier": "geometry.unknown",
"texture_width": 16,
"texture_height": 16,
"visible_bounds_width": 3,
"visible_bounds_height": 1.5,
"visible_bounds_offset": [0, 0.25, 0]
},
"bones": [
{
"name": "bb_main",
"pivot": [0, 0, 0],
"cubes": [
{
"origin": [-1, 0, 6],
"size": [2, 2, 2],
"uv": {
"north": {"uv": [0, 0], "uv_size": [2, 2]},
"east": {"uv": [0, 2], "uv_size": [2, 2]},
"south": {"uv": [2, 0], "uv_size": [2, 2]},
"west": {"uv": [2, 2], "uv_size": [2, 2]},
"up": {"uv": [0, 4], "uv_size": [2, 2]},
"down": {"uv": [4, 2], "uv_size": [2, -2]}
}
},
{
"origin": [-1, 0, -8],
"size": [2, 2, 2],
"uv": {
"north": {"uv": [0, 0], "uv_size": [2, 2]},
"east": {"uv": [0, 2], "uv_size": [2, 2]},
"south": {"uv": [2, 0], "uv_size": [2, 2]},
"west": {"uv": [2, 2], "uv_size": [2, 2]},
"up": {"uv": [0, 4], "uv_size": [2, 2]},
"down": {"uv": [4, 2], "uv_size": [2, -2]}
}
},
{
"origin": [6, 0, -1],
"size": [2, 2, 2],
"uv": {
"north": {"uv": [0, 0], "uv_size": [2, 2]},
"east": {"uv": [0, 2], "uv_size": [2, 2]},
"south": {"uv": [2, 0], "uv_size": [2, 2]},
"west": {"uv": [2, 2], "uv_size": [2, 2]},
"up": {"uv": [0, 4], "uv_size": [2, 2]},
"down": {"uv": [4, 2], "uv_size": [2, -2]}
}
},
{
"origin": [-8, 0, -1],
"size": [2, 2, 2],
"uv": {
"north": {"uv": [0, 0], "uv_size": [2, 2]},
"east": {"uv": [0, 2], "uv_size": [2, 2]},
"south": {"uv": [2, 0], "uv_size": [2, 2]},
"west": {"uv": [2, 2], "uv_size": [2, 2]},
"up": {"uv": [0, 4], "uv_size": [2, 2]},
"down": {"uv": [4, 2], "uv_size": [2, -2]}
}
}
]
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"loader": "kasuga_lib:bedrock_model",
"model": "kasuga_lib:block/test/rotation_test_model",
"texture": "kasuga_lib:block/test/rotation_test_model",
"identifier": "kasuga_lib:rotation_test_model",
"render_type": "solid"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"loader": "kasuga_lib:bedrock_model",
"model": "kasuga_lib:default/missing_model",
"texture": "kasuga_lib:default/missing_model",
"particle":"kasuga_lib:default/missing_model"
"particle": "kasuga_lib:default/particle"
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public AnimModel read(JsonObject jsonObject, JsonDeserializationContext deserial
}

public @Nullable AnimModel getModel(ResourceLocation location) {
return MODELS.get(location);
AnimModel model = MODELS.get(location);
if (model == null) return null;
model.init();
return model;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ public static BedrockModel readModel(JsonObject jsonObject, @Nullable JsonDeseri
Material texture = new Material(TextureAtlas.LOCATION_BLOCKS,
new ResourceLocation(jsonObject.get("texture").getAsString()));
materials.add(texture);
if (jsonObject.has("particle")) {
String particleStr = jsonObject.get("particle").getAsString();
ResourceLocation location = new ResourceLocation(particleStr);
materials.add(new Material(TextureAtlas.LOCATION_PARTICLES, location));
}
// if (jsonObject.has("particle")) {
// String particleStr = jsonObject.get("particle").getAsString();
// ResourceLocation location = new ResourceLocation(particleStr);
// // could not read particles? why?
// materials.add(new Material(TextureAtlas.LOCATION_PARTICLES, location));
// }
BedrockModel model = new BedrockModel(
new ResourceLocation(ml.getNamespace(), "models/" + ml.getPath() + ".geo.json"),
flipV, texture, materials);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public static LazyRecomputable<AnimateTicker> getTickerInstance(
return new LazyRecomputable<>(() -> {
AnimModel model = AnimModelLoader.INSTANCE.getModel(modelLoc);
if (model == null) return null;
model.init();
if (!model.isValidForRender()) model.init();
AnimationFile file = AnimationFile.fromFile(animFile).get();
if (file == null) return null;
Animation anim = file.getAnimation(animName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public static LazyRecomputable<MultiAnimateTicker> getTickerInstance(
int counter = 0;
AnimModel model = AnimModelLoader.INSTANCE.getModel(modelLoc);
if (model == null) return null;
model.init();
if (!model.isValidForRender()) model.init();
for (Pair<ResourceLocation, String> a : anims) {
AnimationFile file = AnimationFile.fromFile(a.getFirst()).get();
if (file == null) return null;
Expand Down
24 changes: 6 additions & 18 deletions src/main/java/kasuga/lib/core/client/model/model_json/Cube.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.mojang.math.Vector3f;
import kasuga.lib.core.client.model.Rotationable;
import kasuga.lib.core.client.render.texture.Vec2f;
import lombok.Getter;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.model.Material;
Expand All @@ -25,13 +26,16 @@

@OnlyIn(Dist.CLIENT)
public class Cube implements Rotationable {

@Getter
private final Vector3f origin, size, pivot, rotation;
private final ArrayList<UnbakedUV> uvs;

public final Geometry model;

public final Bone bone;
public final boolean mirror, visible, emissive;
@Getter
private final float inflate;
public static final Vector3f BASE_OFFSET = new Vector3f(.5f, 0, .5f),
BASE_SCALE = new Vector3f(1, 1, 1);
Expand Down Expand Up @@ -112,18 +116,6 @@ public List<Quad> getQuads() {
return result;
}

public Vector3f getOrigin() {
return origin;
}

public Vector3f getSize() {
return size;
}

public Vector3f getRotation() {
return rotation;
}

@Override
public boolean hasParent() {
return true;
Expand All @@ -139,10 +131,6 @@ public Vector3f getPivot() {
return pivot;
}

public float getInflate() {
return inflate;
}

public void addQuads(IGeometryBakingContext owner, IModelBuilder<?> modelBuilder, ModelBakery bakery,
Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelTransform, ResourceLocation modelLocation) {

Expand All @@ -167,8 +155,8 @@ public void addQuads(IGeometryBakingContext owner, IModelBuilder<?> modelBuilder
quads = rotQuads(quads, pivot, position, context.quaternions());
if (!modelTransform.getRotation().getLeftRotation().equals(Quaternion.ONE))
quads = rotQuads(quads, Vector3f.ZERO, modelTransform.getRotation().getLeftRotation());
if (!universalOffset.equals(BASE_OFFSET))
quads = translateQuads(quads, universalOffset);
// if (!universalOffset.equals(BASE_OFFSET))
quads = translateQuads(quads, universalOffset);
if (!universalScale.equals(BASE_SCALE))
quads = scaleQuads(quads, Vector3f.ZERO, universalScale);
HashMap<Direction, int[]> aint = fillVertices(quads, u0, v0, width, height);
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/kasuga/lib/example_env/AllExampleElements.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import kasuga.lib.core.menu.base.GuiMenuRegistry;
import kasuga.lib.core.menu.base.GuiMenuType;
import kasuga.lib.core.util.Envs;
import kasuga.lib.example_env.block.RotationTestBlock;
import kasuga.lib.example_env.block.fluid.ExampleFluid;
import kasuga.lib.example_env.block.fluid.ExampleFluidBlock;
import kasuga.lib.example_env.block.green_apple.GreenAppleBlock;
Expand Down Expand Up @@ -114,6 +115,14 @@ public class AllExampleElements {

public static final CreativeTabReg tab = new CreativeTabReg("test")
.icon(greenAppleItem).submit(REGISTRY);

public static final BlockReg<RotationTestBlock> rotationTest =
new BlockReg<RotationTestBlock>("rotation_test")
.blockType(RotationTestBlock::new)
.defaultBlockItem()
.tabTo(tab)
.addProperty(BlockBehaviour.Properties::noCollission)
.submit(REGISTRY);
/*
public static final AnimReg test_anim =
new AnimReg("test_anim", REGISTRY.asResource("models/entity/test/wuling/wuling_anim.json"))
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/kasuga/lib/example_env/block/RotationTestBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package kasuga.lib.example_env.block;

import com.sk89q.worldedit.registry.state.EnumProperty;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.DirectionalBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import org.jetbrains.annotations.Nullable;

public class RotationTestBlock extends DirectionalBlock {

public RotationTestBlock(Properties pProperties) {
super(pProperties);
this.stateDefinition.any().setValue(FACING, Direction.NORTH);
}

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> pBuilder) {
super.createBlockStateDefinition(pBuilder.add(FACING));
}

@Override
public @Nullable BlockState getStateForPlacement(BlockPlaceContext pContext) {
return super.getStateForPlacement(pContext).setValue(FACING, pContext.getHorizontalDirection().getOpposite());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fluids.FluidType;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
Expand Down Expand Up @@ -442,7 +443,7 @@ public void onCustomItemRendererReg(Map<ResourceLocation, BakedModel> registry)
@Inner
@SubscribeEvent
@OnlyIn(Dist.CLIENT)
public void hookFluidAndRenders(ModelEvent.RegisterAdditional event) {
public void hookFluidAndRenders(FMLLoadCompleteEvent event) {
for (Map.Entry<FluidReg<?>, RenderType> entry : KasugaLibStacks.FLUID_RENDERS.entrySet()) {
ItemBlockRenderTypes.setRenderLayer(entry.getKey().stillFluid(), entry.getValue());
ItemBlockRenderTypes.setRenderLayer(entry.getKey().flowingFluid(), entry.getValue());
Expand Down

0 comments on commit 2047e4e

Please sign in to comment.