Skip to content

Commit

Permalink
fix: 🐛 Fixed storage blocks not to get defaulted to black color in so…
Browse files Browse the repository at this point in the history
…me cases despite the base block / item having no tint
  • Loading branch information
P3pp3rF1y committed Nov 11, 2024
1 parent 77a326f commit c2acf6f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 51 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.10.52
mod_version=0.10.53
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 @@ -17,64 +17,69 @@

public class StorageBlockItem extends BlockItemBase implements ITintableBlockItem {

public StorageBlockItem(Block block, Properties properties) {
super(block, properties);
}
public StorageBlockItem(Block block, Properties properties) {
super(block, properties);
}

public static Optional<CompoundTag> getEntityWrapperTagFromStack(ItemStack barrelStack) {
CustomData customData = barrelStack.get(DataComponents.BLOCK_ENTITY_DATA);
CustomData customData = barrelStack.get(DataComponents.BLOCK_ENTITY_DATA);
if (customData == null) {
return Optional.empty();
}
return Optional.of(customData.copyTag().getCompound(STORAGE_WRAPPER_TAG));
return Optional.empty();
}
return Optional.of(customData.copyTag().getCompound(STORAGE_WRAPPER_TAG));
}

public static Optional<Integer> getMainColorFromStack(ItemStack storageStack) {
return getEntityWrapperTagFromStack(storageStack).map(tag -> tag.getInt(StorageWrapper.MAIN_COLOR_TAG)).or(() -> Optional.ofNullable(storageStack.get(ModCoreDataComponents.MAIN_COLOR)));
return getEntityWrapperTagFromStack(storageStack)
.flatMap(tag -> tag.contains(StorageWrapper.MAIN_COLOR_TAG) ? Optional.of(tag.getInt(StorageWrapper.MAIN_COLOR_TAG)) : Optional.empty())
.or(() -> Optional.ofNullable(storageStack.get(ModCoreDataComponents.MAIN_COLOR)));
}

public static Optional<Integer> getAccentColorFromStack(ItemStack storageStack) {
return getEntityWrapperTagFromStack(storageStack).map(tag -> tag.getInt(StorageWrapper.ACCENT_COLOR_TAG)).or(() -> Optional.ofNullable(storageStack.get(ModCoreDataComponents.ACCENT_COLOR)));
return getEntityWrapperTagFromStack(storageStack)
.flatMap(tag -> tag.contains(StorageWrapper.ACCENT_COLOR_TAG) ? Optional.of(tag.getInt(StorageWrapper.ACCENT_COLOR_TAG)) : Optional.empty())
.or(() -> Optional.ofNullable(storageStack.get(ModCoreDataComponents.ACCENT_COLOR)));
}

@Override
public void setMainColor(ItemStack storageStack, int mainColor) {
storageStack.set(ModCoreDataComponents.MAIN_COLOR, mainColor);
}

@Override
public Optional<Integer> getMainColor(ItemStack storageStack) {
return StorageBlockItem.getMainColorFromStack(storageStack);
}

@Override
public void setAccentColor(ItemStack storageStack, int accentColor) {
storageStack.set(ModCoreDataComponents.ACCENT_COLOR, accentColor);
}

@Override
public void removeMainColor(ItemStack stack) {
stack.remove(ModCoreDataComponents.MAIN_COLOR);
}

@Override
public void removeAccentColor(ItemStack stack) {
stack.remove(ModCoreDataComponents.ACCENT_COLOR);
}

@Override
public Optional<Integer> getAccentColor(ItemStack stack) {
return StorageBlockItem.getAccentColorFromStack(stack);
}

public static boolean showsTier(ItemStack stack) {
return stack.getOrDefault(ModDataComponents.SHOWS_TIER, true);
}

public static void setShowsTier(ItemStack stack, boolean showsTier) {
if (showsTier) {
stack.remove(ModDataComponents.SHOWS_TIER);
} else {
stack.set(ModDataComponents.SHOWS_TIER, false);
}
}
@Override
public void setMainColor(ItemStack storageStack, int mainColor) {
storageStack.set(ModCoreDataComponents.MAIN_COLOR, mainColor);
}

@Override
public Optional<Integer> getMainColor(ItemStack storageStack) {
return StorageBlockItem.getMainColorFromStack(storageStack);
}

@Override
public void setAccentColor(ItemStack storageStack, int accentColor) {
storageStack.set(ModCoreDataComponents.ACCENT_COLOR, accentColor);
}

@Override
public void removeMainColor(ItemStack stack) {
stack.remove(ModCoreDataComponents.MAIN_COLOR);
}

@Override
public void removeAccentColor(ItemStack stack) {
stack.remove(ModCoreDataComponents.ACCENT_COLOR);
}

@Override
public Optional<Integer> getAccentColor(ItemStack stack) {
return StorageBlockItem.getAccentColorFromStack(stack);
}

public static boolean showsTier(ItemStack stack) {
return stack.getOrDefault(ModDataComponents.SHOWS_TIER, true);
}

public static void setShowsTier(ItemStack stack, boolean showsTier) {
if (showsTier) {
stack.remove(ModDataComponents.SHOWS_TIER);
} else {
stack.set(ModDataComponents.SHOWS_TIER, false);
}
}
}

0 comments on commit c2acf6f

Please sign in to comment.