Skip to content

Commit

Permalink
feat: ✨ Added support for coloring backpacks in Decoration Table and …
Browse files Browse the repository at this point in the history
…in the process made decoration table code more flexible
  • Loading branch information
P3pp3rF1y committed Jan 14, 2025
1 parent c2ee981 commit 122e274
Show file tree
Hide file tree
Showing 10 changed files with 328 additions and 134 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=1.1.5
mod_version=1.2.0
mod_group_id=sophisticatedstorage
mod_authors=P3pp3rF1y, Ridanisaurus
mod_description=Fancy and functional storage containers.
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@
import net.p3pp3rf1y.sophisticatedstorage.SophisticatedStorage;
import net.p3pp3rf1y.sophisticatedstorage.block.DecorationTableBlockEntity;
import net.p3pp3rf1y.sophisticatedstorage.common.gui.DecorationTableMenu;
import net.p3pp3rf1y.sophisticatedstorage.init.ModBlocks;
import net.p3pp3rf1y.sophisticatedstorage.init.ModItems;
import net.p3pp3rf1y.sophisticatedstorage.item.StorageBlockItem;
import net.p3pp3rf1y.sophisticatedstorage.util.DecorationHelper;

import javax.annotation.Nullable;
Expand Down Expand Up @@ -100,22 +98,7 @@ public DecorationTableScreen(DecorationTableMenu menu, Inventory playerInventory

private void updatePreviewStacks() {
if (blockPreview != null) {
ItemStack storageStack = getMenu().getStorageSlot().getItem();

if (storageStack.getItem() instanceof StorageBlockItem) {
blockPreview.setPreviewStacks(List.of(getMenu().getResultSlot().getItem()));
} else if (storageStack.getItem() == ModItems.PAINTBRUSH.get() && !getMenu().getResultSlot().getItem().isEmpty()) {
ItemStack barrelPreviewStack = getMenu().decorateStack(new ItemStack(ModBlocks.LIMITED_BARREL_3_ITEM.get()));
if (getMenu().hasMaterials()) {
blockPreview.setPreviewStacks(List.of(barrelPreviewStack));
} else {
ItemStack chestPreviewStack = getMenu().decorateStack(new ItemStack(ModBlocks.CHEST_ITEM.get()));
ItemStack shulkerPreviewStack = getMenu().decorateStack(new ItemStack(ModBlocks.SHULKER_BOX_ITEM.get()));
blockPreview.setPreviewStacks(List.of(barrelPreviewStack, chestPreviewStack, shulkerPreviewStack));
}
} else {
blockPreview.setPreviewStacks(Collections.emptyList());
}
blockPreview.setPreviewStacks(getMenu().getDecoratedPreviewStacks());
}
}

Expand Down Expand Up @@ -163,10 +146,10 @@ private void addDyeElements() {
Slot topTrimSlot = menu.getSlot(DecorationTableBlockEntity.TOP_TRIM_SLOT);
Slot sideTrimSlot = menu.getSlot(DecorationTableBlockEntity.SIDE_TRIM_SLOT);

ColorButton mainColorButton = new ColorButton(new Position(leftPos + greenDyeSlot.x - 1, topPos + topTrimSlot.y), new Dimension(18, 18), menu::getMainColor,
ColorButton mainColorButton = new ColorButton(new Position(leftPos + greenDyeSlot.x - 1, topPos + topTrimSlot.y - 1), new Dimension(18, 18), menu::getMainColor,
button -> openColorPicker(menu.getMainColor(), menu::setMainColor), Component.translatable(StorageTranslationHelper.INSTANCE.translButton("pick_color")));
addRenderableWidget(mainColorButton);
ColorButton accentColorButton = new ColorButton(new Position(leftPos + greenDyeSlot.x - 1, topPos + sideTrimSlot.y), new Dimension(18, 18), menu::getAccentColor,
ColorButton accentColorButton = new ColorButton(new Position(leftPos + greenDyeSlot.x - 1, topPos + sideTrimSlot.y - 1), new Dimension(18, 18), menu::getAccentColor,
button -> openColorPicker(menu.getAccentColor(), menu::setAccentColor), Component.translatable(StorageTranslationHelper.INSTANCE.translButton("pick_color")));
addRenderableWidget(accentColorButton);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.p3pp3rf1y.sophisticatedstorage.init.ModBlocks;

import javax.annotation.Nullable;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
Expand Down Expand Up @@ -66,8 +67,8 @@ public Slot getStorageSlot() {
return storageSlot;
}

public ItemStack decorateStack(ItemStack stack) {
return blockEntity.decorateStack(stack).result();
public List<ItemStack> getDecoratedPreviewStacks() {
return blockEntity.getDecoratedPreviewStacks();
}

private void addStorageSlots() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Auto generated package-info by MCP

@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault
package net.p3pp3rf1y.sophisticatedstorage.compat.jade;

import net.minecraft.MethodsReturnNonnullByDefault;

import javax.annotation.ParametersAreNonnullByDefault;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Auto generated package-info by MCP

@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault
package net.p3pp3rf1y.sophisticatedstorage.compat.quark;

import net.minecraft.MethodsReturnNonnullByDefault;

import javax.annotation.ParametersAreNonnullByDefault;
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package net.p3pp3rf1y.sophisticatedstorage.compat.sb;

import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.p3pp3rf1y.sophisticatedbackpacks.backpack.BackpackItem;
import net.p3pp3rf1y.sophisticatedbackpacks.backpack.wrapper.BackpackWrapper;
import net.p3pp3rf1y.sophisticatedbackpacks.backpack.wrapper.IBackpackWrapper;
import net.p3pp3rf1y.sophisticatedcore.compat.ICompat;
import net.p3pp3rf1y.sophisticatedstorage.block.BarrelMaterial;
import net.p3pp3rf1y.sophisticatedstorage.block.DecorationTableBlockEntity;
import net.p3pp3rf1y.sophisticatedstorage.util.DecorationHelper;

import java.util.Map;

public class SBCompat implements ICompat {
@Override
public void setup() {
DecorationTableBlockEntity.registerItemDecorator(BackpackItem.class, new DecorationTableBlockEntity.IItemDecorator() {
@Override
public boolean supportsMaterials(ItemStack input) {
return false;
}

@Override
public boolean supportsTints(ItemStack input) {
return true;
}

@Override
public boolean supportsTopInnerTrim(ItemStack input) {
return false;
}

@Override
public ItemStack decorateWithMaterials(ItemStack input, Map<BarrelMaterial, ResourceLocation> materialsToApply) {
return ItemStack.EMPTY;
}

@Override
public DecorationTableBlockEntity.TintDecorationResult decorateWithTints(ItemStack input, int mainColorToSet, int accentColorToSet) {
if (colorsTransparentOrSameAs(input, mainColorToSet, accentColorToSet)) {
return DecorationTableBlockEntity.TintDecorationResult.EMPTY;
}

ItemStack result = input.copyWithCount(1);

IBackpackWrapper backpackWrapper = BackpackWrapper.fromStack(result);
int originalMainColor = backpackWrapper.getMainColor();
int originalAccentColor = backpackWrapper.getAccentColor();

backpackWrapper.setColors(mainColorToSet, accentColorToSet);
return new DecorationTableBlockEntity.TintDecorationResult(result, DecorationHelper.getDyePartsNeeded(mainColorToSet, accentColorToSet, originalMainColor, originalAccentColor, 20, 4));
}

private boolean colorsTransparentOrSameAs(ItemStack backpack, int mainColorToSet, int accentColorToSet) {
IBackpackWrapper backpackWrapper = BackpackWrapper.fromStack(backpack);
return (mainColorToSet == -1 || mainColorToSet == backpackWrapper.getMainColor()) && (accentColorToSet == -1 || accentColorToSet == backpackWrapper.getAccentColor());
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Auto generated package-info by MCP

@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault
package net.p3pp3rf1y.sophisticatedstorage.compat.sb;

import net.minecraft.MethodsReturnNonnullByDefault;

import javax.annotation.ParametersAreNonnullByDefault;
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
import net.p3pp3rf1y.sophisticatedcore.compat.CompatRegistry;
import net.p3pp3rf1y.sophisticatedstorage.compat.chipped.ChippedCompat;
import net.p3pp3rf1y.sophisticatedstorage.compat.quark.QuarkCompat;
import net.p3pp3rf1y.sophisticatedstorage.compat.sb.SBCompat;

public class ModCompat {
private static final String SB_MOD_ID = "sophisticatedbackpacks";
private ModCompat() {
}

public static void register() {
CompatRegistry.registerCompat(new CompatInfo(CompatModIds.QUARK, null), () -> modBus -> new QuarkCompat());
CompatRegistry.registerCompat(new CompatInfo(CompatModIds.CHIPPED, null), () -> modBus -> new ChippedCompat());
CompatRegistry.registerCompat(new CompatInfo(SB_MOD_ID, null), () -> modBus -> new SBCompat());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,17 @@ public static boolean consumeDyes(int mainColorBeingSet, int accentColorBeingSet
}

public static Map<TagKey<Item>, Integer> getDyePartsNeeded(int mainColorBeingSet, int accentColorBeingSet, int storageMainColor, int storageAccentColor) {
return getDyePartsNeeded(mainColorBeingSet, accentColorBeingSet, storageMainColor, storageAccentColor, MAIN_COLOR_PARTS, ACCENT_COLOR_PARTS);
}

public static Map<TagKey<Item>, Integer> getDyePartsNeeded(int mainColorBeingSet, int accentColorBeingSet, int storageMainColor, int storageAccentColor, int mainColorParts, int accentColorParts) {
Map<TagKey<Item>, Integer> partsNeeded = new HashMap<>();
if (mainColorBeingSet != -1 && mainColorBeingSet != storageMainColor) {
int[] rgbPartsNeeded = calculateRGBPartsNeeded(mainColorBeingSet, MAIN_COLOR_PARTS);
int[] rgbPartsNeeded = calculateRGBPartsNeeded(mainColorBeingSet, mainColorParts);
addPartsNeededIfAny(rgbPartsNeeded, partsNeeded);
}
if (accentColorBeingSet != -1 && accentColorBeingSet != storageAccentColor) {
int[] rgbPartsNeeded = calculateRGBPartsNeeded(accentColorBeingSet, ACCENT_COLOR_PARTS);
int[] rgbPartsNeeded = calculateRGBPartsNeeded(accentColorBeingSet, accentColorParts);
addPartsNeededIfAny(rgbPartsNeeded, partsNeeded);
}
return partsNeeded;
Expand Down

0 comments on commit 122e274

Please sign in to comment.