Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add WAILA plugin for cauldron contents
- Loading branch information
1 parent
5a3a485
commit a61676a
Showing
11 changed files
with
155 additions
and
9 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
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
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
71 changes: 71 additions & 0 deletions
71
src/main/java/knightminer/inspirations/plugins/waila/CauldronProvider.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,71 @@ | ||
package knightminer.inspirations.plugins.waila; | ||
|
||
import java.util.List; | ||
|
||
import knightminer.inspirations.library.InspirationsRegistry; | ||
import knightminer.inspirations.library.Util; | ||
import knightminer.inspirations.library.recipe.cauldron.ICauldronRecipe.CauldronState; | ||
import knightminer.inspirations.recipes.block.BlockEnhancedCauldron; | ||
import knightminer.inspirations.recipes.tileentity.TileCauldron; | ||
import mcp.mobius.waila.api.IWailaConfigHandler; | ||
import mcp.mobius.waila.api.IWailaDataAccessor; | ||
import mcp.mobius.waila.api.IWailaDataProvider; | ||
import net.minecraft.block.state.IBlockState; | ||
import net.minecraft.item.EnumDyeColor; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraftforge.fluids.Fluid; | ||
import net.minecraftforge.fluids.FluidStack; | ||
|
||
public class CauldronProvider implements IWailaDataProvider { | ||
@Override | ||
public List<String> getWailaBody(ItemStack itemStack, List<String> current, IWailaDataAccessor accessor, IWailaConfigHandler config) { | ||
if(!config.getConfig(WailaRegistrar.CONFIG_CAULDRON)) { | ||
return current; | ||
} | ||
|
||
// first, ensure it is a cauldron | ||
IBlockState state = accessor.getBlockState(); | ||
if(state.getBlock() instanceof BlockEnhancedCauldron) { | ||
int level = ((BlockEnhancedCauldron)state.getBlock()).getLevel(state); | ||
String colorString = null; | ||
|
||
// if we have a TE and the levels are at least 1, try fancy string | ||
if(level > 0 && accessor.getTileEntity() instanceof TileCauldron) { | ||
CauldronState cauldron = ((TileCauldron) accessor.getTileEntity()).getState(); | ||
|
||
// fluids are pretty simple, unlocalized name | ||
if(cauldron.getFluid() != null) { | ||
Fluid fluid = cauldron.getFluid(); | ||
current.add(fluid.getLocalizedName(new FluidStack(fluid, 1000))); | ||
|
||
// likewise potions are simple | ||
} else if(cauldron.getPotion() != null) { | ||
current.add(Util.translate(cauldron.getPotion().getNamePrefixed("potion.effect."))); | ||
|
||
// dyes are a bit more work | ||
} else if(cauldron.getColor() != -1) { | ||
int color = cauldron.getColor(); | ||
colorString = "#" + Integer.toHexString(color).toUpperCase(); | ||
|
||
// first, try a dye color | ||
EnumDyeColor dyeColor = Util.getDyeForColor(color); | ||
if(dyeColor != null) { | ||
current.add(Util.translateFormatted("gui.jei.cauldron.color", Util.translate("item.fireworksCharge.%s", dyeColor.getUnlocalizedName()))); | ||
} else { | ||
// if not a dye color, just display as is and display the color on the next line | ||
current.add(Util.translate("gui.inspirations.cauldron.dye")); | ||
} | ||
} | ||
} | ||
|
||
// add bottles | ||
current.add(Util.translateFormatted("gui.waila.inspirations.cauldron.bottles", level, InspirationsRegistry.getCauldronMax())); | ||
|
||
// if we were given a color string, show it | ||
if(colorString != null && accessor.getPlayer().isSneaking()) { | ||
current.add(Util.translateFormatted("gui.waila.inspirations.cauldron.color", colorString)); | ||
} | ||
} | ||
return current; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/knightminer/inspirations/plugins/waila/WailaPlugin.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,17 @@ | ||
package knightminer.inspirations.plugins.waila; | ||
|
||
import com.google.common.eventbus.Subscribe; | ||
|
||
import net.minecraftforge.fml.common.event.FMLInterModComms; | ||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; | ||
import slimeknights.mantle.pulsar.pulse.Pulse; | ||
|
||
@Pulse(id = "WailaPlugin", modsRequired = WailaPlugin.modid, defaultEnable = true) | ||
public class WailaPlugin { | ||
public static final String modid = "waila"; | ||
|
||
@Subscribe | ||
public void preInit(FMLPreInitializationEvent event) { | ||
FMLInterModComms.sendMessage(modid, "register", "knightminer.inspirations.plugins.waila.WailaRegistrar.registerWaila"); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/knightminer/inspirations/plugins/waila/WailaRegistrar.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,18 @@ | ||
package knightminer.inspirations.plugins.waila; | ||
|
||
import knightminer.inspirations.Inspirations; | ||
import knightminer.inspirations.library.Util; | ||
import knightminer.inspirations.recipes.tileentity.TileCauldron; | ||
import mcp.mobius.waila.api.IWailaRegistrar; | ||
|
||
public class WailaRegistrar { | ||
|
||
static final String CONFIG_CAULDRON = Util.prefix("cauldron"); | ||
public static void registerWaila(IWailaRegistrar registrar) { | ||
// config entries | ||
registrar.addConfig(Inspirations.modName, CONFIG_CAULDRON, true); | ||
|
||
// cauldron info | ||
registrar.registerBodyProvider(new CauldronProvider(), TileCauldron.class); | ||
} | ||
} |
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
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