Skip to content

Commit

Permalink
Fix tank modifier models discarding the non-fluid and offsetting weir…
Browse files Browse the repository at this point in the history
…dly (#5227)

Turns out the method of using the model bakery applies an origin to the transformation, meaning we get a funny offset with the fluid quads. Thus, we just reverse that before calling the method
No idea why this is not needed in the fluid container model, perhaps we just do no scaling there so it does not end up mattering?
  • Loading branch information
KnightMiner committed May 18, 2024
1 parent cfe73b9 commit 053f8f5
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.collect.ImmutableList;
import com.mojang.math.Transformation;
import com.mojang.math.Vector3f;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.BlockElement;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
Expand All @@ -17,12 +18,12 @@
import slimeknights.mantle.client.model.util.ColoredBlockModel;
import slimeknights.mantle.util.ItemLayerPixels;
import slimeknights.tconstruct.TConstruct;
import slimeknights.tconstruct.library.client.model.FluidContainerModel;
import slimeknights.tconstruct.library.modifiers.Modifier;
import slimeknights.tconstruct.library.modifiers.ModifierEntry;
import slimeknights.tconstruct.library.tools.capability.ToolFluidCapability;
import slimeknights.tconstruct.library.tools.capability.ToolFluidCapability.FluidModifierHook;
import slimeknights.tconstruct.library.tools.nbt.IToolStackView;
import slimeknights.tconstruct.library.client.model.FluidContainerModel;

import javax.annotation.Nullable;
import java.util.List;
Expand All @@ -35,6 +36,12 @@ public class FluidModifierModel extends NormalModifierModel {
/** Location used for baking dynamic models, name does not matter so just using a constant */
private static final ResourceLocation BAKE_LOCATION = TConstruct.getResource("dynamic_fluid_model");

/**
* The vanilla model bakery uses an orgin of 0.5,0.5,0.5, and forges dynamic fluid code uses the vanilla model bakery. (see{@link net.minecraft.client.renderer.block.model.FaceBakery} {@code #rotateVertexBy()} for vanilla bakery)
* However, item layer wants an origin of 0,0,0, which is what we expect in our tool models. So cancel out the origin.
*/
private static final Vector3f ORIGIN = new Vector3f(-0.5f, -0.5f, -0.5f);

/** Constant unbaked model instance, as they are all the same */
public static final IUnbakedModifierModel UNBAKED_INSTANCE = (smallGetter, largeGetter) -> {
Material smallTexture = smallGetter.apply("");
Expand Down Expand Up @@ -94,8 +101,8 @@ public ImmutableList<BakedQuad> getQuads(IToolStackView tool, ModifierEntry entr
TextureAtlasSprite fluidSprite = spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, attributes.getStillTexture(fluid)));

// build fluid like the forge dynamic container model
List<BlockElement> unbaked = UnbakedGeometryHelper.createUnbakedItemMaskElements(1, spriteGetter.apply(template)); // Use template as mask
List<BakedQuad> fluidQuads = UnbakedGeometryHelper.bakeElements(unbaked, mat -> fluidSprite, new SimpleModelState(transforms.compose(FluidContainerModel.FLUID_TRANSFORM), false), BAKE_LOCATION); // Bake with fluid texture
List<BlockElement> unbaked = UnbakedGeometryHelper.createUnbakedItemMaskElements(-1, spriteGetter.apply(template)); // Use template as mask
List<BakedQuad> fluidQuads = UnbakedGeometryHelper.bakeElements(unbaked, mat -> fluidSprite, new SimpleModelState(transforms.applyOrigin(ORIGIN).compose(FluidContainerModel.FLUID_TRANSFORM), false), BAKE_LOCATION); // Bake with fluid texture

// apply brightness and color
int luminosity = fluid.getFluid().getFluidType().getLightLevel(fluid);
Expand All @@ -106,7 +113,8 @@ public ImmutableList<BakedQuad> getQuads(IToolStackView tool, ModifierEntry entr
if (color != -1) {
ColoredBlockModel.applyColorQuadTransformer(color).processInPlace(fluidQuads);
}
quads = ImmutableList.copyOf(fluidQuads);

quads = ImmutableList.<BakedQuad>builder().addAll(quads).addAll(fluidQuads).build();
}
}
return quads;
Expand Down

0 comments on commit 053f8f5

Please sign in to comment.