Skip to content

Commit

Permalink
Fix particles for multi-state copycats
Browse files Browse the repository at this point in the history
It is still impossible to accurately get the particles for a specific part, but it is at least a bit more accurate now and doesn't display copycat base particles when a material is available.
  • Loading branch information
hlysine committed Aug 1, 2024
1 parent 0a0ea09 commit b7d2c61
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public boolean partExists(BlockState state, String property) {

@Override
public Set<String> storageProperties() {
return Set.of(SlabType.BOTTOM.getSerializedName(), SlabType.TOP.getSerializedName());
return Set.of(SlabType.TOP.getSerializedName(), SlabType.BOTTOM.getSerializedName());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ default IMultiStateCopycatBlockEntity getCopycatBlockEntity(BlockGetter worldIn,

/**
* When it is impossible to determine the specific part involved in an interaction, this property is used.
* The return value must be an element returned by {@link IMultiStateCopycatBlock#storageProperties}.
* It should represent one of the topmost parts of the copycat.
*/
String defaultProperty();

Expand All @@ -105,6 +107,7 @@ default IMultiStateCopycatBlockEntity getCopycatBlockEntity(BlockGetter worldIn,

/**
* The string keys of all parts that can be stored in the copycat.
* Ideally, the keys should be sorted from top to bottom in 3D space.
*/
Set<String> storageProperties();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,24 +244,28 @@ public void emitBlockQuads(BlockAndTintGetter blockView, BlockState state, Block
protected void prepareModelCore(BlockAndTintGetter blockView, BlockState state, BlockPos pos, Supplier<RandomSource> randomSupplier, BlockState material, Object renderAttachmentData) {
core.prepareForRender();
}

@Override
public TextureAtlasSprite getParticleIcon(Object data) {
if (data instanceof BlockState state) {
BlockState material = getMaterial(state);
return getIcon(getModelOf(material), null);
if (!material.is(AllBlocks.COPYCAT_BASE.get()))
return getIcon(getModelOf(material), null);
} else if (data instanceof Pair<?, ?> pair && pair.getSecond() instanceof BlockState material) {
return getIcon(getModelOf(material), pair.getFirst());
if (!material.is(AllBlocks.COPYCAT_BASE.get()))
return getIcon(getModelOf(material), pair.getFirst());
} else if (data instanceof Map<?, ?> mats) {
for (Map.Entry<?, ?> entry : mats.entrySet()) {
if (entry.getValue() instanceof Pair<?, ?> pair && pair.getSecond() instanceof BlockState material3) {
return getIcon(getModelOf(material3), pair.getFirst());
if (!material3.is(AllBlocks.COPYCAT_BASE.get()))
return getIcon(getModelOf(material3), pair.getFirst());
} else if (entry.getValue() instanceof BlockState material4) {
return getIcon(getModelOf(material4), null);
if (!material4.is(AllBlocks.COPYCAT_BASE.get()))
return getIcon(getModelOf(material4), null);
}
}
}

return CustomParticleIconModel.super.getParticleIcon(data);
return getIcon(getModelOf(AllBlocks.COPYCAT_BASE.getDefaultState()), null);
}

public BakedModel getModelForEntry(CopycatModelCore.ModelEntry entry, BlockState state, BlockState material) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,10 @@ protected void prepareModelCore(@NotNull BlockState state, @NotNull RandomSource
if (material.isEmpty())
return super.getParticleIcon(data);

Map.Entry<String, BlockState> key = material.entrySet().stream().findFirst().get();
Map.Entry<String, BlockState> key = material.entrySet().stream()
.filter(s -> !s.getValue().is(AllBlocks.COPYCAT_BASE.get()))
.findFirst()
.orElse(material.entrySet().iterator().next());

return getModelOf(key.getValue()).getParticleIcon(getWrappedData(data).get(key.getKey()));
}
Expand Down

0 comments on commit b7d2c61

Please sign in to comment.