Skip to content

Commit

Permalink
Merge pull request #218 from SteveKunG/1.20.4
Browse files Browse the repository at this point in the history
Fixed crash when decorated pot try to render invalid pattern
  • Loading branch information
FoundationGames authored Jun 13, 2024
2 parents c0666ed + ecebaef commit 819fe74
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.block.DecoratedPotPatterns;
import net.minecraft.block.entity.DecoratedPotBlockEntity;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.registry.Registries;
import net.minecraft.registry.RegistryKey;
import net.minecraft.util.Identifier;
Expand Down Expand Up @@ -82,6 +83,14 @@ public void writeModelIndices(BlockRenderView view, BlockState state, BlockPos p
}

private int getPatternIndex(Item sherd, int max) {
return MathHelper.clamp(this.potteryPatterns.indexOf(DecoratedPotPatterns.fromSherd(sherd)), 0, max - 1);
return MathHelper.clamp(this.potteryPatterns.indexOf(getPatternFromSherd(sherd)), 0, max - 1);
}

private static RegistryKey<String> getPatternFromSherd(Item item) {
RegistryKey<String> registryKey = DecoratedPotPatterns.fromSherd(item);
if (registryKey == null) {
return DecoratedPotPatterns.fromSherd(Items.BRICK);
}
return registryKey;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
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.item.Item;
import net.minecraft.item.Items;
import net.minecraft.registry.Registries;
import net.minecraft.registry.RegistryKey;
import net.minecraft.util.math.MathHelper;
Expand Down Expand Up @@ -87,18 +89,26 @@ public void render(BlockEntityRenderer<BlockEntity> renderer, BlockEntity blockE
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);
this.potPatternModels.get(getPatternFromSherd(sherds.back()))[0], light, overlay);
EBEUtil.renderBakedModel(vertexConsumers, blockEntity.getCachedState(), matrices,
this.potPatternModels.get(DecoratedPotPatterns.fromSherd(sherds.left()))[1], light, overlay);
this.potPatternModels.get(getPatternFromSherd(sherds.left()))[1], light, overlay);
EBEUtil.renderBakedModel(vertexConsumers, blockEntity.getCachedState(), matrices,
this.potPatternModels.get(DecoratedPotPatterns.fromSherd(sherds.right()))[2], light, overlay);
this.potPatternModels.get(getPatternFromSherd(sherds.right()))[2], light, overlay);
EBEUtil.renderBakedModel(vertexConsumers, blockEntity.getCachedState(), matrices,
this.potPatternModels.get(DecoratedPotPatterns.fromSherd(sherds.front()))[3], light, overlay);
this.potPatternModels.get(getPatternFromSherd(sherds.front()))[3], light, overlay);

matrices.pop();
}
}

private static RegistryKey<String> getPatternFromSherd(Item item) {
RegistryKey<String> registryKey = DecoratedPotPatterns.fromSherd(item);
if (registryKey == null) {
return DecoratedPotPatterns.fromSherd(Items.BRICK);
}
return registryKey;
}

@Override
public void onModelsReload() {
this.baseModel = null;
Expand Down

0 comments on commit 819fe74

Please sign in to comment.