-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 1.20.4 decorated pot animations for inserting items
- Loading branch information
1 parent
e3fb4fc
commit 9329310
Showing
9 changed files
with
213 additions
and
16 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
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
107 changes: 107 additions & 0 deletions
107
...s/enhancedblockentities/client/render/entity/DecoratedPotBlockEntityRendererOverride.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,107 @@ | ||
package foundationgames.enhancedblockentities.client.render.entity; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import foundationgames.enhancedblockentities.client.model.ModelIdentifiers; | ||
import foundationgames.enhancedblockentities.client.render.BlockEntityRendererOverride; | ||
import foundationgames.enhancedblockentities.util.EBEUtil; | ||
import foundationgames.enhancedblockentities.util.duck.BakedModelManagerAccess; | ||
import net.minecraft.block.DecoratedPotPatterns; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.block.entity.DecoratedPotBlockEntity; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.render.VertexConsumerProvider; | ||
import net.minecraft.client.render.block.entity.BlockEntityRenderer; | ||
import net.minecraft.client.render.model.BakedModel; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.registry.Registries; | ||
import net.minecraft.registry.RegistryKey; | ||
import net.minecraft.util.math.MathHelper; | ||
import net.minecraft.util.math.RotationAxis; | ||
|
||
import java.util.Map; | ||
|
||
public class DecoratedPotBlockEntityRendererOverride extends BlockEntityRendererOverride { | ||
public static final float WOBBLE_STRENGTH = 1f / 64; | ||
|
||
private BakedModel baseModel = null; | ||
private Map<RegistryKey<String>, BakedModel[]> potPatternModels = null; | ||
|
||
private void tryGetModels() { | ||
var models = (BakedModelManagerAccess) MinecraftClient.getInstance().getBakedModelManager(); | ||
|
||
if (this.baseModel == null) { | ||
this.baseModel = models.getModel(ModelIdentifiers.DECORATED_POT_BASE); | ||
} | ||
|
||
if (this.potPatternModels == null) { | ||
var builder = ImmutableMap.<RegistryKey<String>, BakedModel[]>builder(); | ||
|
||
Registries.DECORATED_POT_PATTERN.getKeys().forEach(k -> { | ||
var patternModelIDs = ModelIdentifiers.POTTERY_PATTERNS.get(k); | ||
BakedModel[] patternPerFaceModels = new BakedModel[patternModelIDs.length]; | ||
|
||
for (int i = 0; i < patternModelIDs.length; i++) { | ||
patternPerFaceModels[i] = models.getModel(patternModelIDs[i]); | ||
} | ||
|
||
builder.put(k, patternPerFaceModels); | ||
}); | ||
|
||
this.potPatternModels = builder.build(); | ||
} | ||
} | ||
|
||
@Override | ||
public void render(BlockEntityRenderer<BlockEntity> renderer, BlockEntity blockEntity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) { | ||
tryGetModels(); | ||
|
||
if (blockEntity instanceof DecoratedPotBlockEntity pot) { | ||
matrices.push(); | ||
|
||
var dir = pot.getHorizontalFacing(); | ||
|
||
matrices.translate(0.5f, 0, 0.5f); | ||
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180 - dir.asRotation())); | ||
matrices.translate(-0.5f, 0, -0.5f); | ||
|
||
var wobbleType = pot.lastWobbleType; | ||
if (wobbleType != null && pot.getWorld() != null) { | ||
float tilt = ((float)(pot.getWorld().getTime() - pot.lastWobbleTime) + tickDelta) / (float)wobbleType.lengthInTicks; | ||
if (tilt >= 0.0F && tilt <= 1.0F) { | ||
if (wobbleType == DecoratedPotBlockEntity.WobbleType.POSITIVE) { | ||
float animPeriod = tilt * MathHelper.TAU; | ||
|
||
float tiltX = -1.5f * (MathHelper.cos(animPeriod) + 0.5f) * MathHelper.sin(animPeriod * 0.5f); | ||
matrices.multiply(RotationAxis.POSITIVE_X.rotation(tiltX * WOBBLE_STRENGTH), 0.5f, 0f, 0.5f); | ||
|
||
float tiltZ = MathHelper.sin(animPeriod); | ||
matrices.multiply(RotationAxis.POSITIVE_Z.rotation(tiltZ * WOBBLE_STRENGTH), 0.5f, 0f, 0.5f); | ||
} else { | ||
float yaw = (1f - tilt) * MathHelper.sin(-tilt * 3 * MathHelper.PI) * 0.125f; | ||
matrices.multiply(RotationAxis.POSITIVE_Y.rotation(yaw), 0.5f, 0f, 0.5f); | ||
} | ||
} | ||
} | ||
|
||
var sherds = pot.getSherds(); | ||
EBEUtil.renderBakedModel(vertexConsumers, blockEntity.getCachedState(), matrices, this.baseModel, light, overlay); | ||
|
||
EBEUtil.renderBakedModel(vertexConsumers, blockEntity.getCachedState(), matrices, | ||
this.potPatternModels.get(DecoratedPotPatterns.fromSherd(sherds.back()))[0], light, overlay); | ||
EBEUtil.renderBakedModel(vertexConsumers, blockEntity.getCachedState(), matrices, | ||
this.potPatternModels.get(DecoratedPotPatterns.fromSherd(sherds.left()))[1], light, overlay); | ||
EBEUtil.renderBakedModel(vertexConsumers, blockEntity.getCachedState(), matrices, | ||
this.potPatternModels.get(DecoratedPotPatterns.fromSherd(sherds.right()))[2], light, overlay); | ||
EBEUtil.renderBakedModel(vertexConsumers, blockEntity.getCachedState(), matrices, | ||
this.potPatternModels.get(DecoratedPotPatterns.fromSherd(sherds.front()))[3], light, overlay); | ||
|
||
matrices.pop(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onModelsReload() { | ||
this.baseModel = null; | ||
this.potPatternModels = null; | ||
} | ||
} |
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
5 changes: 5 additions & 0 deletions
5
src/main/resources/assets/minecraft/models/block/decorated_pot_shaking.json
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,5 @@ | ||
{ | ||
"textures": { | ||
"particle": "minecraft:block/terracotta" | ||
} | ||
} |