Skip to content

Commit

Permalink
fix: 🐛 Fixed decoration table to drop its contents when broken
Browse files Browse the repository at this point in the history
  • Loading branch information
P3pp3rF1y committed Dec 4, 2024
1 parent 6898af1 commit f9a62ef
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ loader_version_range=[4,)
mod_id=sophisticatedstorage
mod_name=Sophisticated Storage
mod_license=GNU General Public License v3.0
mod_version=0.11.2
mod_version=0.11.3
mod_group_id=sophisticatedstorage
mod_authors=P3pp3rF1y, Ridanisaurus
mod_description=Fancy and functional storage containers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import net.p3pp3rf1y.sophisticatedcore.util.BlockBase;
import net.p3pp3rf1y.sophisticatedstorage.common.gui.DecorationTableMenu;
import net.p3pp3rf1y.sophisticatedstorage.init.ModBlocks;

import javax.annotation.Nullable;

public class DecorationTableBlock extends BlockBase implements EntityBlock {
//TODO block loot table and axe tag
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
protected static final VoxelShape SHAPE = Shapes.or(
Block.box(0, 12, 0, 16, 16, 16),
Expand Down Expand Up @@ -69,6 +69,12 @@ public boolean onDestroyedByPlayer(BlockState state, Level level, BlockPos pos,
return super.onDestroyedByPlayer(state, level, pos, player, willHarvest, fluid);
}

@Override
protected void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean movedByPiston) {
level.getBlockEntity(pos, ModBlocks.DECORATION_TABLE_BLOCK_ENTITY_TYPE.get()).ifPresent(DecorationTableBlockEntity::dropContents);
super.onRemove(state, level, pos, newState, movedByPiston);
}

@Nullable
@Override
public DecorationTableBlockEntity newBlockEntity(BlockPos pos, BlockState state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private void updateResult() {
(InventoryHelper.isEmpty(decorativeBlocks)
|| !(storage.getItem() instanceof BarrelBlockItem)
|| isTintedStorage(storage)
) && colorsTransparentOrSameAs(storage))) { //TODO once dyes and materials can be combined make sure to create combined result here
) && colorsTransparentOrSameAs(storage))) {
result = ItemStack.EMPTY;
return;
}
Expand All @@ -140,7 +140,6 @@ private void updateResult() {
return;
}

//TODO remove the check for tinted barrel here once barrel model can support combination of tinted and material
if (InventoryHelper.isEmpty(decorativeBlocks)) {
result = ItemStack.EMPTY;
return;
Expand All @@ -158,7 +157,6 @@ private void updateResult() {
return;
}

//TODO if dyed and any of the parts doesn't have material make sure that dye shows
result = storage.copy();
result.setCount(1);

Expand Down Expand Up @@ -391,7 +389,7 @@ private void saveData(CompoundTag tag, HolderLookup.Provider registries) {
}

public void consumeIngredientsOnCraft() {
if (InventoryHelper.isEmpty(decorativeBlocks)) { //TODO once dyes and materials can be combined make sure to consume from both here and change the dye calculation to only count with parts visible
if (InventoryHelper.isEmpty(decorativeBlocks)) {
consumeDyes();
} else {
consumeMaterials();
Expand Down Expand Up @@ -568,4 +566,10 @@ public void setAccentColor(int accentColor) {
public Map<ResourceLocation, Integer> getPartsStored() {
return remainingParts;
}

public void dropContents() {
InventoryHelper.dropItems(decorativeBlocks, level, worldPosition);
InventoryHelper.dropItems(dyes, level, worldPosition);
InventoryHelper.dropItems(storageBlock, level, worldPosition);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ public BakedModel resolve(BakedModel model, ItemStack stack, @Nullable ClientLev
boolean hasAccentColor = StorageBlockItem.getAccentColorFromStack(stack).isPresent();
Map<BarrelMaterial, ResourceLocation> materials = BarrelBlockItem.getMaterials(stack);
String woodName = WoodStorageBlockItem.getWoodType(stack).map(WoodType::name)
.orElse(barrelBakedModel.barrelHasAccentColor && barrelBakedModel.barrelHasMainColor && materials.isEmpty() ? null : WoodType.ACACIA.name()); //TODO possibly remove materials check from here if a separate dynamic model is going to be used for materials
.orElse(barrelBakedModel.barrelHasAccentColor && barrelBakedModel.barrelHasMainColor && materials.isEmpty() ? null : WoodType.ACACIA.name());
boolean packed = WoodStorageBlockItem.isPacked(stack);
boolean barrelShowsTier = StorageBlockItem.showsTier(stack);
Item item = stack.getItem();
Expand Down

0 comments on commit f9a62ef

Please sign in to comment.