2016-03-30 07:45:15 +02:00
|
|
|
package techreborn.items;
|
|
|
|
|
2016-12-10 02:01:19 +01:00
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
2016-03-30 07:45:15 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2016-12-10 02:01:19 +01:00
|
|
|
import net.minecraft.item.IItemPropertyGetter;
|
2016-03-30 07:45:15 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2016-05-11 07:35:09 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2016-12-10 02:01:19 +01:00
|
|
|
import net.minecraft.util.*;
|
2016-05-11 07:35:09 +02:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.text.TextComponentString;
|
2016-05-13 08:46:17 +02:00
|
|
|
import net.minecraft.util.text.TextFormatting;
|
2016-05-12 03:44:28 +02:00
|
|
|
import net.minecraft.util.text.translation.I18n;
|
2016-03-30 07:45:15 +02:00
|
|
|
import net.minecraft.world.World;
|
2016-05-11 07:35:09 +02:00
|
|
|
import net.minecraftforge.common.DimensionManager;
|
2016-12-10 02:01:19 +01:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2016-12-08 07:09:13 +01:00
|
|
|
import reborncore.client.hud.StackInfoElement;
|
2016-05-12 03:44:28 +02:00
|
|
|
import reborncore.common.util.ChatUtils;
|
2016-12-08 07:09:13 +01:00
|
|
|
import reborncore.common.util.Color;
|
2016-03-30 07:45:15 +02:00
|
|
|
import techreborn.client.TechRebornCreativeTabMisc;
|
2016-05-11 07:35:09 +02:00
|
|
|
import techreborn.config.ConfigTechReborn;
|
2016-12-08 07:09:13 +01:00
|
|
|
import techreborn.init.ModItems;
|
2016-05-22 06:51:26 +02:00
|
|
|
import techreborn.lib.MessageIDs;
|
2016-05-11 07:35:09 +02:00
|
|
|
|
2016-12-10 02:01:19 +01:00
|
|
|
import javax.annotation.Nullable;
|
2016-05-11 07:35:09 +02:00
|
|
|
import java.util.List;
|
2016-03-30 07:45:15 +02:00
|
|
|
|
2016-12-10 02:01:19 +01:00
|
|
|
public class ItemFrequencyTransmitter extends ItemTRNoDestroy {
|
2016-03-30 07:45:15 +02:00
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public ItemFrequencyTransmitter() {
|
2016-03-30 07:45:15 +02:00
|
|
|
setUnlocalizedName("techreborn.frequencyTransmitter");
|
|
|
|
setCreativeTab(TechRebornCreativeTabMisc.instance);
|
2016-05-12 07:37:55 +02:00
|
|
|
setMaxStackSize(1);
|
2016-12-10 02:01:19 +01:00
|
|
|
this.addPropertyOverride(new ResourceLocation("techreborn:coords"), new IItemPropertyGetter() {
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public float apply(ItemStack stack,
|
|
|
|
@Nullable
|
|
|
|
World worldIn,
|
|
|
|
@Nullable
|
|
|
|
EntityLivingBase entityIn) {
|
|
|
|
if (stack != ItemStack.EMPTY && stack.hasTagCompound() && stack.getTagCompound() != null && stack.getTagCompound().hasKey("x") && stack.getTagCompound().hasKey("y") && stack.getTagCompound().hasKey("z") && stack.getTagCompound().hasKey("dim")) {
|
|
|
|
return 1.0F;
|
|
|
|
}
|
|
|
|
return 0.0F;
|
|
|
|
}
|
|
|
|
});
|
2016-03-30 07:45:15 +02:00
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
@Override
|
2016-11-19 13:50:08 +01:00
|
|
|
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos,
|
2016-10-08 21:46:16 +02:00
|
|
|
EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
|
2016-11-19 13:50:08 +01:00
|
|
|
ItemStack stack = player.getHeldItem(hand);
|
2016-12-11 19:07:56 +01:00
|
|
|
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());
|
2016-05-11 07:35:09 +02:00
|
|
|
|
2016-12-11 19:07:56 +01:00
|
|
|
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() + ")"));
|
2016-05-11 07:35:09 +02:00
|
|
|
}
|
2016-12-11 19:07:56 +01:00
|
|
|
return EnumActionResult.SUCCESS;
|
2016-05-11 07:35:09 +02:00
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
@Override
|
2016-11-19 13:50:08 +01:00
|
|
|
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player,
|
2016-10-08 21:46:16 +02:00
|
|
|
EnumHand hand) {
|
2016-11-19 13:50:08 +01:00
|
|
|
ItemStack stack = player.getHeldItem(hand);
|
2016-10-08 21:46:16 +02:00
|
|
|
if (player.isSneaking()) {
|
2016-05-16 06:24:35 +02:00
|
|
|
stack.setTagCompound(null);
|
2016-10-08 21:46:16 +02:00
|
|
|
if (!world.isRemote && ConfigTechReborn.FreqTransmitterChat) {
|
2016-05-22 06:51:26 +02:00
|
|
|
ChatUtils.sendNoSpamMessages(MessageIDs.freqTransmitterID, new TextComponentString(
|
2016-10-08 21:46:16 +02:00
|
|
|
TextFormatting.GRAY + I18n.translateToLocal("techreborn.message.coordsHaveBeen") + " "
|
|
|
|
+ TextFormatting.GOLD + I18n.translateToLocal("techreborn.message.cleared")));
|
2016-05-16 06:24:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return new ActionResult<>(EnumActionResult.SUCCESS, stack);
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4) {
|
|
|
|
if (ConfigTechReborn.FreqTransmitterTooltip) {
|
2016-12-10 02:01:19 +01:00
|
|
|
if (stack.hasTagCompound() && stack.getTagCompound() != null && stack.getTagCompound().hasKey("x") && stack.getTagCompound().hasKey("y") && stack.getTagCompound().hasKey("z") && stack.getTagCompound().hasKey("dim")) {
|
2016-05-11 07:35:09 +02:00
|
|
|
int x = stack.getTagCompound().getInteger("x");
|
|
|
|
int y = stack.getTagCompound().getInteger("y");
|
|
|
|
int z = stack.getTagCompound().getInteger("z");
|
|
|
|
int dim = stack.getTagCompound().getInteger("dim");
|
|
|
|
|
2016-12-11 19:07:56 +01:00
|
|
|
list.add(TextFormatting.GRAY + "X: " + TextFormatting.GOLD + x);
|
|
|
|
list.add(TextFormatting.GRAY + "Y: " + TextFormatting.GOLD + y);
|
|
|
|
list.add(TextFormatting.GRAY + "Z: " + TextFormatting.GOLD + z);
|
2016-05-13 08:46:17 +02:00
|
|
|
list.add(TextFormatting.DARK_GRAY + DimensionManager.getProviderType(dim).getName());
|
2016-05-11 07:35:09 +02:00
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
} else {
|
2016-05-16 06:24:35 +02:00
|
|
|
list.add(TextFormatting.GRAY + I18n.translateToLocal("techreborn.message.noCoordsSet"));
|
2016-05-11 07:35:09 +02:00
|
|
|
}
|
|
|
|
}
|
2016-03-30 07:45:15 +02:00
|
|
|
}
|
|
|
|
|
2016-12-08 07:09:13 +01:00
|
|
|
public static class StackInfoFreqTransmitter extends StackInfoElement {
|
|
|
|
public StackInfoFreqTransmitter() {
|
2017-01-01 08:29:32 +01:00
|
|
|
super(ModItems.FREQUENCY_TRANSMITTER);
|
2016-12-08 07:09:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getText(ItemStack stack) {
|
|
|
|
String text = "";
|
|
|
|
Color gold = Color.GOLD;
|
|
|
|
Color grey = Color.GRAY;
|
|
|
|
if (stack.getItem() instanceof ItemFrequencyTransmitter) {
|
2016-12-10 02:01:19 +01:00
|
|
|
if (stack.hasTagCompound() && stack.getTagCompound() != null && stack.getTagCompound().hasKey("x") && stack.getTagCompound().hasKey("y") && stack.getTagCompound().hasKey("z") && stack.getTagCompound().hasKey("dim")) {
|
2016-12-08 07:09:13 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2016-03-30 07:45:15 +02:00
|
|
|
}
|