Un-hardcode block documentation
Opens it up for all our custom blocks to be able to provide information. Need a texture from @Yulife.
This commit is contained in:
parent
e406a4fa6f
commit
d0c0700fda
9 changed files with 166 additions and 28 deletions
|
@ -215,7 +215,9 @@ public class Constants
|
||||||
SIGIL_TELEPOSITION("ItemSigilTeleposition"),
|
SIGIL_TELEPOSITION("ItemSigilTeleposition"),
|
||||||
EXPERIENCE_TOME("ItemExperienceBook"),
|
EXPERIENCE_TOME("ItemExperienceBook"),
|
||||||
SIGIL_TRANSPOSITION("ItemSigilTransposition"),
|
SIGIL_TRANSPOSITION("ItemSigilTransposition"),
|
||||||
RITUAL_READER("ItemRitualReader");
|
RITUAL_READER("ItemRitualReader"),
|
||||||
|
SANGUINE_BOOK("ItemSanguineBook"),
|
||||||
|
;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final String regName;
|
private final String regName;
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
package WayofTime.bloodmagic.api.iface;
|
||||||
|
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.text.ITextComponent;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks blocks as one that is documented.
|
||||||
|
*
|
||||||
|
* This documentation can be read by an {@link WayofTime.bloodmagic.item.ItemSanguineBook} (or child)
|
||||||
|
*/
|
||||||
|
public interface IDocumentedBlock
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Provides the documentation to provide to the player. Usually a short'n'sweet description about basic usage.
|
||||||
|
*
|
||||||
|
* @param player
|
||||||
|
* - The EntityPlayer attempting to view the Documentation.
|
||||||
|
* @param world
|
||||||
|
* - The World interaction is happening in.
|
||||||
|
* @param pos
|
||||||
|
* - The BlockPos being interacted at.
|
||||||
|
* @param state
|
||||||
|
* - The IBlockState of the interacted Block.
|
||||||
|
*
|
||||||
|
* @return - A list of formatted ITextComponent to provide to the player. Provide an empty list if there is no available documentation.
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
List<ITextComponent> getDocumentation(EntityPlayer player, World world, BlockPos pos, IBlockState state);
|
||||||
|
}
|
|
@ -3,6 +3,10 @@ package WayofTime.bloodmagic.block;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import WayofTime.bloodmagic.altar.BloodAltar;
|
||||||
|
import WayofTime.bloodmagic.api.altar.EnumAltarComponent;
|
||||||
|
import WayofTime.bloodmagic.api.altar.IBloodAltar;
|
||||||
|
import WayofTime.bloodmagic.api.iface.IDocumentedBlock;
|
||||||
import net.minecraft.block.BlockContainer;
|
import net.minecraft.block.BlockContainer;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
@ -13,6 +17,8 @@ import net.minecraft.util.EnumBlockRenderType;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.EnumHand;
|
import net.minecraft.util.EnumHand;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.text.ITextComponent;
|
||||||
|
import net.minecraft.util.text.TextComponentTranslation;
|
||||||
import net.minecraft.world.IBlockAccess;
|
import net.minecraft.world.IBlockAccess;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
@ -33,7 +39,7 @@ import WayofTime.bloodmagic.util.Utils;
|
||||||
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
|
|
||||||
public class BlockAltar extends BlockContainer implements IVariantProvider
|
public class BlockAltar extends BlockContainer implements IVariantProvider, IDocumentedBlock
|
||||||
{
|
{
|
||||||
public BlockAltar()
|
public BlockAltar()
|
||||||
{
|
{
|
||||||
|
@ -167,6 +173,8 @@ public class BlockAltar extends BlockContainer implements IVariantProvider
|
||||||
super.breakBlock(world, blockPos, blockState);
|
super.breakBlock(world, blockPos, blockState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IVariantProvider
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Pair<Integer, String>> getVariants()
|
public List<Pair<Integer, String>> getVariants()
|
||||||
{
|
{
|
||||||
|
@ -174,4 +182,18 @@ public class BlockAltar extends BlockContainer implements IVariantProvider
|
||||||
ret.add(new ImmutablePair<Integer, String>(0, "normal"));
|
ret.add(new ImmutablePair<Integer, String>(0, "normal"));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IDocumentedBlock
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ITextComponent> getDocumentation(EntityPlayer player, World world, BlockPos pos, IBlockState state)
|
||||||
|
{
|
||||||
|
List<ITextComponent> docs = new ArrayList<ITextComponent>();
|
||||||
|
IBloodAltar altar = ((IBloodAltar) world.getTileEntity(pos));
|
||||||
|
Pair<BlockPos, EnumAltarComponent> missingBlock = BloodAltar.getAltarMissingBlock(world, pos, altar.getTier().toInt());
|
||||||
|
if (missingBlock != null)
|
||||||
|
docs.add(new TextComponentTranslation("chat.BloodMagic.altar.nextTier", new TextComponentTranslation(missingBlock.getRight().getKey()), Utils.prettifyBlockPosString(missingBlock.getLeft())));
|
||||||
|
|
||||||
|
return docs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
package WayofTime.bloodmagic.item;
|
||||||
|
|
||||||
|
import WayofTime.bloodmagic.BloodMagic;
|
||||||
|
import WayofTime.bloodmagic.api.Constants;
|
||||||
|
import WayofTime.bloodmagic.api.iface.IDocumentedBlock;
|
||||||
|
import WayofTime.bloodmagic.client.IVariantProvider;
|
||||||
|
import WayofTime.bloodmagic.util.ChatUtil;
|
||||||
|
import WayofTime.bloodmagic.util.helper.TextHelper;
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.EnumActionResult;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.util.EnumHand;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.text.ITextComponent;
|
||||||
|
import net.minecraft.util.text.TextFormatting;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ItemSanguineBook extends Item implements IVariantProvider
|
||||||
|
{
|
||||||
|
public ItemSanguineBook()
|
||||||
|
{
|
||||||
|
setUnlocalizedName(Constants.Mod.MODID + ".sanguineBook");
|
||||||
|
setCreativeTab(BloodMagic.tabBloodMagic);
|
||||||
|
setMaxStackSize(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
|
||||||
|
{
|
||||||
|
if (world.isRemote)
|
||||||
|
return super.onItemUse(stack, player, world, pos, hand, facing, hitX, hitY, hitZ);
|
||||||
|
|
||||||
|
IBlockState hitState = world.getBlockState(pos);
|
||||||
|
if (player.isSneaking() && hitState.getBlock() instanceof IDocumentedBlock)
|
||||||
|
{
|
||||||
|
IDocumentedBlock documentedBlock = (IDocumentedBlock) hitState.getBlock();
|
||||||
|
List<ITextComponent> docs = documentedBlock.getDocumentation(player, world, pos, hitState);
|
||||||
|
if (!docs.isEmpty())
|
||||||
|
{
|
||||||
|
ChatUtil.sendNoSpam(player, docs.toArray(new ITextComponent[docs.size()]));
|
||||||
|
return EnumActionResult.SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.onItemUse(stack, player, world, pos, hand, facing, hitX, hitY, hitZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced)
|
||||||
|
{
|
||||||
|
tooltip.add(TextHelper.localizeEffect("tooltip.BloodMagic.book.shifting"));
|
||||||
|
tooltip.add(TextFormatting.OBFUSCATED + "~ILikeTehNutsAndICannotLie");
|
||||||
|
}
|
||||||
|
|
||||||
|
// IVariantProvider
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Pair<Integer, String>> getVariants()
|
||||||
|
{
|
||||||
|
return Collections.singletonList(Pair.of(0, "type=normal"));
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,16 +8,11 @@ import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.ActionResult;
|
import net.minecraft.util.ActionResult;
|
||||||
import net.minecraft.util.EnumHand;
|
import net.minecraft.util.EnumHand;
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.util.math.RayTraceResult;
|
import net.minecraft.util.math.RayTraceResult;
|
||||||
import net.minecraft.util.text.ITextComponent;
|
import net.minecraft.util.text.ITextComponent;
|
||||||
import net.minecraft.util.text.TextComponentTranslation;
|
import net.minecraft.util.text.TextComponentTranslation;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
|
||||||
|
|
||||||
import WayofTime.bloodmagic.altar.BloodAltar;
|
|
||||||
import WayofTime.bloodmagic.api.altar.EnumAltarComponent;
|
|
||||||
import WayofTime.bloodmagic.api.altar.IBloodAltar;
|
import WayofTime.bloodmagic.api.altar.IBloodAltar;
|
||||||
import WayofTime.bloodmagic.api.iface.IAltarReader;
|
import WayofTime.bloodmagic.api.iface.IAltarReader;
|
||||||
import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
|
import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
|
||||||
|
@ -60,22 +55,10 @@ public class ItemSigilDivination extends ItemSigilBase implements IAltarReader
|
||||||
{
|
{
|
||||||
IBloodAltar altar = (IBloodAltar) tile;
|
IBloodAltar altar = (IBloodAltar) tile;
|
||||||
int tier = altar.getTier().ordinal() + 1;
|
int tier = altar.getTier().ordinal() + 1;
|
||||||
|
|
||||||
if (player.isSneaking())
|
|
||||||
{
|
|
||||||
Pair<BlockPos, EnumAltarComponent> missingBlock = BloodAltar.getAltarMissingBlock(world, position.getBlockPos(), tier);
|
|
||||||
if (missingBlock != null)
|
|
||||||
{
|
|
||||||
ChatUtil.sendNoSpam(player, new TextComponentTranslation("chat.BloodMagic.altar.nextTier", new TextComponentTranslation(missingBlock.getRight().getKey()), prettifyBlockPosString(missingBlock.getLeft())));
|
|
||||||
}
|
|
||||||
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
int currentEssence = altar.getCurrentBlood();
|
int currentEssence = altar.getCurrentBlood();
|
||||||
int capacity = altar.getCapacity();
|
int capacity = altar.getCapacity();
|
||||||
altar.checkTier();
|
altar.checkTier();
|
||||||
ChatUtil.sendNoSpam(player, new TextComponentTranslation(tooltipBase + "currentAltarTier", NumeralHelper.toRoman(tier)), new TextComponentTranslation(tooltipBase + "currentEssence", currentEssence), new TextComponentTranslation(tooltipBase + "currentAltarCapacity", capacity));
|
ChatUtil.sendNoSpam(player, new TextComponentTranslation(tooltipBase + "currentAltarTier", NumeralHelper.toRoman(tier)), new TextComponentTranslation(tooltipBase + "currentEssence", currentEssence), new TextComponentTranslation(tooltipBase + "currentAltarCapacity", capacity));
|
||||||
}
|
|
||||||
} else if (tile != null && tile instanceof TileIncenseAltar)
|
} else if (tile != null && tile instanceof TileIncenseAltar)
|
||||||
{
|
{
|
||||||
TileIncenseAltar altar = (TileIncenseAltar) tile;
|
TileIncenseAltar altar = (TileIncenseAltar) tile;
|
||||||
|
@ -93,9 +76,4 @@ public class ItemSigilDivination extends ItemSigilBase implements IAltarReader
|
||||||
|
|
||||||
return super.onItemRightClick(stack, world, player, hand);
|
return super.onItemRightClick(stack, world, player, hand);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String prettifyBlockPosString(BlockPos pos)
|
|
||||||
{
|
|
||||||
return "[" + pos.getX() + ", " + pos.getY() + ", " + pos.getZ() + "]";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ import WayofTime.bloodmagic.item.ItemSlate;
|
||||||
import WayofTime.bloodmagic.item.ItemTelepositionFocus;
|
import WayofTime.bloodmagic.item.ItemTelepositionFocus;
|
||||||
import WayofTime.bloodmagic.item.ItemUpgradeTome;
|
import WayofTime.bloodmagic.item.ItemUpgradeTome;
|
||||||
import WayofTime.bloodmagic.item.ItemUpgradeTrainer;
|
import WayofTime.bloodmagic.item.ItemUpgradeTrainer;
|
||||||
|
import WayofTime.bloodmagic.item.ItemSanguineBook;
|
||||||
import WayofTime.bloodmagic.item.alchemy.ItemCuttingFluid;
|
import WayofTime.bloodmagic.item.alchemy.ItemCuttingFluid;
|
||||||
import WayofTime.bloodmagic.item.armour.ItemLivingArmour;
|
import WayofTime.bloodmagic.item.armour.ItemLivingArmour;
|
||||||
import WayofTime.bloodmagic.item.armour.ItemSentientArmour;
|
import WayofTime.bloodmagic.item.armour.ItemSentientArmour;
|
||||||
|
@ -154,6 +155,8 @@ public class ModItems
|
||||||
|
|
||||||
public static Item cuttingFluid;
|
public static Item cuttingFluid;
|
||||||
|
|
||||||
|
public static Item sanguineBook;
|
||||||
|
|
||||||
public static Item.ToolMaterial boundToolMaterial = EnumHelper.addToolMaterial("BoundToolMaterial", 4, 1, 10, 8, 50);
|
public static Item.ToolMaterial boundToolMaterial = EnumHelper.addToolMaterial("BoundToolMaterial", 4, 1, 10, 8, 50);
|
||||||
public static Item.ToolMaterial soulToolMaterial = EnumHelper.addToolMaterial("SoulToolMaterial", 4, 520, 7, 8, 50);
|
public static Item.ToolMaterial soulToolMaterial = EnumHelper.addToolMaterial("SoulToolMaterial", 4, 520, 7, 8, 50);
|
||||||
|
|
||||||
|
@ -250,6 +253,8 @@ public class ModItems
|
||||||
baseItemFilter = registerItem(new ItemRouterFilter(), Constants.BloodMagicItem.ROUTER_FILTER.getRegName());
|
baseItemFilter = registerItem(new ItemRouterFilter(), Constants.BloodMagicItem.ROUTER_FILTER.getRegName());
|
||||||
|
|
||||||
cuttingFluid = registerItem(new ItemCuttingFluid(), Constants.BloodMagicItem.CUTTING_FLUID.getRegName());
|
cuttingFluid = registerItem(new ItemCuttingFluid(), Constants.BloodMagicItem.CUTTING_FLUID.getRegName());
|
||||||
|
|
||||||
|
sanguineBook = registerItem(new ItemSanguineBook(), Constants.BloodMagicItem.SANGUINE_BOOK.getRegName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initRenders()
|
public static void initRenders()
|
||||||
|
|
|
@ -95,6 +95,11 @@ public class Utils
|
||||||
return String.valueOf(input.charAt(0)).toUpperCase(Locale.ENGLISH) + input.substring(1);
|
return String.valueOf(input.charAt(0)).toUpperCase(Locale.ENGLISH) + input.substring(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String prettifyBlockPosString(BlockPos pos)
|
||||||
|
{
|
||||||
|
return "[" + pos.getX() + ", " + pos.getY() + ", " + pos.getZ() + "]";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param tile
|
* @param tile
|
||||||
* - The {@link TileInventory} to input the item to
|
* - The {@link TileInventory} to input the item to
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
{
|
||||||
|
"forge_marker": 1,
|
||||||
|
"defaults": {
|
||||||
|
"model": "builtin/generated",
|
||||||
|
"transform": "forge:default-item"
|
||||||
|
},
|
||||||
|
"variants": {
|
||||||
|
"type": {
|
||||||
|
"normal": {
|
||||||
|
"textures": {
|
||||||
|
"layer0": "bloodmagic:items/SanguineBook"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -163,6 +163,7 @@ item.BloodMagic.itemFilter.modItems.name=Mod Item Filter
|
||||||
item.BloodMagic.itemFilter.oreDict.name=Ore Dictionary Item Filter
|
item.BloodMagic.itemFilter.oreDict.name=Ore Dictionary Item Filter
|
||||||
|
|
||||||
item.BloodMagic.experienceTome.name=Tome of Peritia
|
item.BloodMagic.experienceTome.name=Tome of Peritia
|
||||||
|
item.BloodMagic.sanguineBook.name=Book of Sanguine
|
||||||
|
|
||||||
# Blocks
|
# Blocks
|
||||||
tile.BloodMagic.fluid.lifeEssence.name=Life Essence
|
tile.BloodMagic.fluid.lifeEssence.name=Life Essence
|
||||||
|
@ -389,6 +390,8 @@ tooltip.BloodMagic.decoration.notSafe=Dangerous for decoration
|
||||||
|
|
||||||
tooltip.BloodMagic.cuttingFluidRatio=%d/%d uses remaining
|
tooltip.BloodMagic.cuttingFluidRatio=%d/%d uses remaining
|
||||||
|
|
||||||
|
tooltip.BloodMagic.book.shifting=These symbols seem to be... &oshifting...
|
||||||
|
|
||||||
# Ritual
|
# Ritual
|
||||||
ritual.BloodMagic.blockRange.tooBig=The block range given is too big! Needs to be at most %s blocks.
|
ritual.BloodMagic.blockRange.tooBig=The block range given is too big! Needs to be at most %s blocks.
|
||||||
ritual.BloodMagic.blockRange.tooFar=The block range given is too far! Needs to be within a vertical range of %s blocks and a horizontal range of %s blocks.
|
ritual.BloodMagic.blockRange.tooFar=The block range given is too far! Needs to be within a vertical range of %s blocks and a horizontal range of %s blocks.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue