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
|
@ -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.util.ActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
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.iface.IAltarReader;
|
||||
import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
|
||||
|
@ -60,22 +55,10 @@ public class ItemSigilDivination extends ItemSigilBase implements IAltarReader
|
|||
{
|
||||
IBloodAltar altar = (IBloodAltar) tile;
|
||||
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 capacity = altar.getCapacity();
|
||||
altar.checkTier();
|
||||
ChatUtil.sendNoSpam(player, new TextComponentTranslation(tooltipBase + "currentAltarTier", NumeralHelper.toRoman(tier)), new TextComponentTranslation(tooltipBase + "currentEssence", currentEssence), new TextComponentTranslation(tooltipBase + "currentAltarCapacity", capacity));
|
||||
}
|
||||
int currentEssence = altar.getCurrentBlood();
|
||||
int capacity = altar.getCapacity();
|
||||
altar.checkTier();
|
||||
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)
|
||||
{
|
||||
TileIncenseAltar altar = (TileIncenseAltar) tile;
|
||||
|
@ -93,9 +76,4 @@ public class ItemSigilDivination extends ItemSigilBase implements IAltarReader
|
|||
|
||||
return super.onItemRightClick(stack, world, player, hand);
|
||||
}
|
||||
|
||||
public String prettifyBlockPosString(BlockPos pos)
|
||||
{
|
||||
return "[" + pos.getX() + ", " + pos.getY() + ", " + pos.getZ() + "]";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue