Much improve the StackInfoHUD and move it to RC

This commit is contained in:
ProfessorProspector 2016-12-07 22:09:13 -08:00
parent 24455a148c
commit 467544ebfe
3 changed files with 85 additions and 185 deletions

View file

@ -15,9 +15,13 @@ import net.minecraft.util.text.translation.I18n;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
import reborncore.RebornCore;
import reborncore.client.hud.StackInfoElement;
import reborncore.client.hud.StackInfoHUD;
import reborncore.common.util.ChatUtils;
import reborncore.common.util.Color;
import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.config.ConfigTechReborn;
import techreborn.init.ModItems;
import techreborn.lib.MessageIDs;
import java.util.List;
@ -29,31 +33,42 @@ public class ItemFrequencyTransmitter extends ItemTextureBase implements ITextur
setCreativeTab(TechRebornCreativeTabMisc.instance);
setMaxStackSize(1);
RebornCore.jsonDestroyer.registerObject(this);
StackInfoHUD.registerElement(new StackInfoFreqTransmitter());
}
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos,
EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack stack = player.getHeldItem(hand);
stack.setTagCompound(new NBTTagCompound());
stack.getTagCompound().setInteger("x", pos.getX());
stack.getTagCompound().setInteger("y", pos.getY());
stack.getTagCompound().setInteger("z", pos.getZ());
stack.getTagCompound().setInteger("dim", world.provider.getDimension());
if (player.isSneaking()) {
stack.setTagCompound(null);
if (!world.isRemote && ConfigTechReborn.FreqTransmitterChat) {
ChatUtils.sendNoSpamMessages(MessageIDs.freqTransmitterID, new TextComponentString(
TextFormatting.GRAY + I18n.translateToLocal("techreborn.message.coordsHaveBeen") + " "
+ TextFormatting.GOLD + I18n.translateToLocal("techreborn.message.cleared")));
}
return EnumActionResult.PASS;
} else {
stack.setTagCompound(new NBTTagCompound());
stack.getTagCompound().setInteger("x", pos.getX());
stack.getTagCompound().setInteger("y", pos.getY());
stack.getTagCompound().setInteger("z", pos.getZ());
stack.getTagCompound().setInteger("dim", world.provider.getDimension());
if (!world.isRemote && ConfigTechReborn.FreqTransmitterChat) {
ChatUtils.sendNoSpamMessages(MessageIDs.freqTransmitterID, new TextComponentString(
TextFormatting.GRAY + I18n.translateToLocal("techreborn.message.setTo") + " X: " +
TextFormatting.GOLD + pos.getX() +
TextFormatting.GRAY + " Y: " +
TextFormatting.GOLD + pos.getY() +
TextFormatting.GRAY + " Z: " +
TextFormatting.GOLD + pos.getZ() +
TextFormatting.GRAY + " " + I18n.translateToLocal("techreborn.message.in") + " " +
TextFormatting.GOLD + DimensionManager.getProviderType(world.provider.getDimension())
.getName() + " (" + world.provider.getDimension() + ")"));
if (!world.isRemote && ConfigTechReborn.FreqTransmitterChat) {
ChatUtils.sendNoSpamMessages(MessageIDs.freqTransmitterID, new TextComponentString(
TextFormatting.GRAY + I18n.translateToLocal("techreborn.message.setTo") + " X: " +
TextFormatting.GOLD + pos.getX() +
TextFormatting.GRAY + " Y: " +
TextFormatting.GOLD + pos.getY() +
TextFormatting.GRAY + " Z: " +
TextFormatting.GOLD + pos.getZ() +
TextFormatting.GRAY + " " + I18n.translateToLocal("techreborn.message.in") + " " +
TextFormatting.GOLD + DimensionManager.getProviderType(world.provider.getDimension())
.getName() + " (" + world.provider.getDimension() + ")"));
}
return EnumActionResult.SUCCESS;
}
return EnumActionResult.SUCCESS;
}
@Override
@ -100,4 +115,29 @@ public class ItemFrequencyTransmitter extends ItemTextureBase implements ITextur
public String getTextureName(int arg0) {
return "techreborn:items/tool/frequency_transmitter";
}
public static class StackInfoFreqTransmitter extends StackInfoElement {
public StackInfoFreqTransmitter() {
super(ModItems.frequencyTransmitter);
}
@Override
public String getText(ItemStack stack) {
String text = "";
Color gold = Color.GOLD;
Color grey = Color.GRAY;
if (stack.getItem() instanceof ItemFrequencyTransmitter) {
if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("x") && stack.getTagCompound().hasKey("y") && stack.getTagCompound().hasKey("z") && stack.getTagCompound().hasKey("dim")) {
int coordX = stack.getTagCompound().getInteger("x");
int coordY = stack.getTagCompound().getInteger("y");
int coordZ = stack.getTagCompound().getInteger("z");
int coordDim = stack.getTagCompound().getInteger("dim");
text = grey + "X: " + gold + coordX + grey + " Y: " + gold + coordY + grey + " Z: " + gold + coordZ + grey + " Dim: " + gold + DimensionManager.getProviderType(coordDim).getName() + " (" + coordDim + ")";
} else {
text = grey + I18n.translateToLocal("techreborn.message.noCoordsSet");
}
}
return text;
}
}
}