generated from FabricMC/fabric-example-mod
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[v3.1.0+1.21] re-integrates with shulker box tooltip (#79)
* checkout shulkerboxtooltip integrations from 1.20 * re-added shulkerboxtooltip configs * replaced `new Identifier` with `Identifier.of` * re-registered shulkerboxtooltip entrypoint * bump up mod version to v3.1.0+1.21
- Loading branch information
Showing
5 changed files
with
114 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...nkish/reinfshulker/integration/shulkerboxtooltip/ReinforcedShulkerBoxPreviewProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package atonkish.reinfshulker.integration.shulkerboxtooltip; | ||
|
||
import com.misterpemodder.shulkerboxtooltip.api.PreviewContext; | ||
import com.misterpemodder.shulkerboxtooltip.api.color.ColorKey; | ||
import com.misterpemodder.shulkerboxtooltip.api.provider.BlockEntityPreviewProvider; | ||
|
||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
|
||
import net.minecraft.block.Block; | ||
import net.minecraft.util.DyeColor; | ||
|
||
import atonkish.reinfcore.util.ReinforcingMaterial; | ||
import atonkish.reinfshulker.block.ReinforcedShulkerBoxBlock; | ||
|
||
public class ReinforcedShulkerBoxPreviewProvider extends BlockEntityPreviewProvider { | ||
protected final int maxRowSize; | ||
private final ReinforcingMaterial material; | ||
|
||
public ReinforcedShulkerBoxPreviewProvider(ReinforcingMaterial material) { | ||
super(material.getSize(), true); | ||
|
||
int size = material.getSize(); | ||
this.maxRowSize = size <= 81 ? 9 : size / 9; | ||
|
||
this.material = material; | ||
} | ||
|
||
@Override | ||
public boolean showTooltipHints(PreviewContext context) { | ||
return true; | ||
} | ||
|
||
@Override | ||
@Environment(EnvType.CLIENT) | ||
public ColorKey getWindowColorKey(PreviewContext context) { | ||
DyeColor dye = ((ReinforcedShulkerBoxBlock) Block.getBlockFromItem(context.stack().getItem())).getColor(); | ||
|
||
if (dye == null) | ||
return ColorKey.SHULKER_BOX; | ||
return switch (dye) { | ||
case ORANGE -> ColorKey.ORANGE_SHULKER_BOX; | ||
case MAGENTA -> ColorKey.MAGENTA_SHULKER_BOX; | ||
case LIGHT_BLUE -> ColorKey.LIGHT_BLUE_SHULKER_BOX; | ||
case YELLOW -> ColorKey.YELLOW_SHULKER_BOX; | ||
case LIME -> ColorKey.LIME_SHULKER_BOX; | ||
case PINK -> ColorKey.PINK_SHULKER_BOX; | ||
case GRAY -> ColorKey.GRAY_SHULKER_BOX; | ||
case LIGHT_GRAY -> ColorKey.LIGHT_GRAY_SHULKER_BOX; | ||
case CYAN -> ColorKey.CYAN_SHULKER_BOX; | ||
case PURPLE -> ColorKey.PURPLE_SHULKER_BOX; | ||
case BLUE -> ColorKey.BLUE_SHULKER_BOX; | ||
case BROWN -> ColorKey.BROWN_SHULKER_BOX; | ||
case GREEN -> ColorKey.GREEN_SHULKER_BOX; | ||
case RED -> ColorKey.RED_SHULKER_BOX; | ||
case BLACK -> ColorKey.BLACK_SHULKER_BOX; | ||
default -> ColorKey.WHITE_SHULKER_BOX; | ||
}; | ||
} | ||
|
||
@Override | ||
public int getMaxRowSize(PreviewContext context) { | ||
return this.maxRowSize; | ||
} | ||
|
||
public ReinforcingMaterial getMaterial() { | ||
return this.material; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/atonkish/reinfshulker/integration/shulkerboxtooltip/ShulkerBoxTooltip.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package atonkish.reinfshulker.integration.shulkerboxtooltip; | ||
|
||
import com.misterpemodder.shulkerboxtooltip.api.ShulkerBoxTooltipApi; | ||
import com.misterpemodder.shulkerboxtooltip.api.provider.PreviewProvider; | ||
import com.misterpemodder.shulkerboxtooltip.api.provider.PreviewProviderRegistry; | ||
|
||
import net.minecraft.block.entity.BlockEntityType; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.util.Identifier; | ||
|
||
import atonkish.reinfcore.util.ReinforcingMaterial; | ||
import atonkish.reinfcore.util.ReinforcingMaterials; | ||
import atonkish.reinfshulker.block.entity.ModBlockEntityType; | ||
import atonkish.reinfshulker.item.ModItems; | ||
|
||
public class ShulkerBoxTooltip implements ShulkerBoxTooltipApi { | ||
private static void register(PreviewProviderRegistry registry, String namespace, String id, | ||
PreviewProvider provider, Item... items) { | ||
registry.register(Identifier.of(namespace, id), provider, items); | ||
} | ||
|
||
@Override | ||
public void registerProviders(PreviewProviderRegistry registry) { | ||
for (ReinforcingMaterial material : ReinforcingMaterials.MAP.values()) { | ||
String namespace = BlockEntityType.getId(ModBlockEntityType.REINFORCED_SHULKER_BOX_MAP.get(material)) | ||
.getNamespace(); | ||
String id = material.getName() + "_shulker_box"; | ||
Item[] items = ModItems.REINFORCED_SHULKER_BOX_MAP.get(material).values().toArray(new Item[0]); | ||
register(registry, namespace, id, new ReinforcedShulkerBoxPreviewProvider(material), items); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters