2012-12-17 21:21:53 +01:00
|
|
|
package com.pahimar.ee3.item;
|
|
|
|
|
2012-12-19 19:09:56 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.EnumRarity;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.ForgeDirection;
|
|
|
|
|
2012-12-17 21:21:53 +01:00
|
|
|
import com.pahimar.ee3.EquivalentExchange3;
|
2012-12-20 22:45:50 +01:00
|
|
|
import com.pahimar.ee3.configuration.ConfigurationSettings;
|
2012-12-17 21:21:53 +01:00
|
|
|
import com.pahimar.ee3.core.helper.NBTHelper;
|
|
|
|
import com.pahimar.ee3.core.helper.TransmutationHelper;
|
2012-12-19 19:09:56 +01:00
|
|
|
import com.pahimar.ee3.lib.ActionTypes;
|
2012-12-17 21:21:53 +01:00
|
|
|
import com.pahimar.ee3.lib.CustomItemRarity;
|
|
|
|
import com.pahimar.ee3.lib.GuiIds;
|
|
|
|
import com.pahimar.ee3.lib.Sounds;
|
|
|
|
import com.pahimar.ee3.lib.Strings;
|
2012-08-25 08:07:59 +02:00
|
|
|
|
2012-12-18 14:41:49 +01:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2012-08-25 08:07:59 +02:00
|
|
|
|
2012-08-25 08:46:51 +02:00
|
|
|
/**
|
|
|
|
* ItemPhilosopherStone
|
|
|
|
*
|
|
|
|
* The Philosophers Stone
|
|
|
|
*
|
|
|
|
* @author pahimar
|
|
|
|
* @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
|
|
|
|
*
|
|
|
|
*/
|
2012-11-30 21:45:32 +01:00
|
|
|
public class ItemPhilosopherStone extends ItemEE
|
|
|
|
implements ITransmutationStone, IChargeable, IKeyBound {
|
2012-08-25 08:07:59 +02:00
|
|
|
|
2012-10-29 04:16:32 +01:00
|
|
|
private int maxChargeLevel;
|
2012-11-30 16:47:18 +01:00
|
|
|
|
2012-08-25 08:46:51 +02:00
|
|
|
public ItemPhilosopherStone(int id) {
|
2012-11-30 16:47:18 +01:00
|
|
|
|
2012-08-25 08:46:51 +02:00
|
|
|
super(id);
|
2012-11-20 01:49:39 +01:00
|
|
|
this.setIconCoord(2, 0);
|
2012-11-06 21:49:43 +01:00
|
|
|
this.setItemName(Strings.PHILOSOPHER_STONE_NAME);
|
|
|
|
this.setCreativeTab(EquivalentExchange3.tabsEE3);
|
2012-12-05 20:33:03 +01:00
|
|
|
this.setMaxDamage(ConfigurationSettings.PHILOSOPHERS_STONE_MAX_DURABILITY - 1);
|
2012-11-30 20:03:36 +01:00
|
|
|
this.maxChargeLevel = 3;
|
2012-08-25 08:46:51 +02:00
|
|
|
}
|
2012-08-25 08:07:59 +02:00
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public boolean hasEffect(ItemStack stack) {
|
2012-11-30 16:47:18 +01:00
|
|
|
|
2012-08-25 08:07:59 +02:00
|
|
|
return true;
|
|
|
|
}
|
2012-08-25 08:46:51 +02:00
|
|
|
|
2012-08-25 08:07:59 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public EnumRarity getRarity(ItemStack stack) {
|
2012-11-30 16:47:18 +01:00
|
|
|
|
2012-08-25 08:46:51 +02:00
|
|
|
return EquivalentExchange3.proxy.getCustomRarityType(CustomItemRarity.RARE);
|
2012-08-25 08:07:59 +02:00
|
|
|
}
|
2012-11-30 16:47:18 +01:00
|
|
|
|
2012-09-24 21:58:15 +02:00
|
|
|
@Override
|
|
|
|
public boolean doesContainerItemLeaveCraftingGrid(ItemStack itemStack) {
|
2012-11-30 16:47:18 +01:00
|
|
|
|
|
|
|
return false;
|
2012-09-24 21:58:15 +02:00
|
|
|
}
|
2012-11-30 16:47:18 +01:00
|
|
|
|
2012-09-24 21:58:15 +02:00
|
|
|
@Override
|
|
|
|
public boolean getShareTag() {
|
2012-11-30 16:47:18 +01:00
|
|
|
|
|
|
|
return true;
|
2012-09-24 21:58:15 +02:00
|
|
|
}
|
2012-11-30 16:47:18 +01:00
|
|
|
|
2012-12-05 20:33:03 +01:00
|
|
|
@Override
|
|
|
|
public ItemStack getContainerItemStack(ItemStack itemStack) {
|
|
|
|
|
|
|
|
itemStack.setItemDamage(itemStack.getItemDamage() + 1);
|
|
|
|
|
|
|
|
return itemStack;
|
|
|
|
}
|
|
|
|
|
2012-10-29 04:16:32 +01:00
|
|
|
@Override
|
2012-12-06 22:04:20 +01:00
|
|
|
public boolean onItemUse(ItemStack itemStack, EntityPlayer entityPlayer, World world, int x, int y, int z, int sideHit, float hitVecX, float hitVecY, float hitVecZ) {
|
2012-11-30 16:47:18 +01:00
|
|
|
|
2012-12-19 19:09:56 +01:00
|
|
|
transmuteBlocks(itemStack, entityPlayer, world, x, y, z, sideHit);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void openPortableCrafting(EntityPlayer thePlayer) {
|
|
|
|
|
|
|
|
thePlayer.openGui(EquivalentExchange3.instance, GuiIds.PORTABLE_CRAFTING, thePlayer.worldObj, (int) thePlayer.posX, (int) thePlayer.posY, (int) thePlayer.posZ);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void transmuteBlocks(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int sideHit) {
|
|
|
|
|
2012-12-07 03:06:16 +01:00
|
|
|
if (!world.isRemote) {
|
2012-12-18 23:06:00 +01:00
|
|
|
if (TransmutationHelper.targetBlockStack != null) {
|
2012-12-19 03:57:38 +01:00
|
|
|
int pnX = 1;
|
|
|
|
int pnY = 1;
|
|
|
|
int pnZ = 1;
|
|
|
|
switch (ForgeDirection.getOrientation(sideHit)) {
|
|
|
|
case UP: {
|
|
|
|
pnX = 1 + getCharge(itemStack) * 2;
|
|
|
|
pnZ = 1 + getCharge(itemStack) * 2;
|
|
|
|
break;
|
|
|
|
}
|
2012-12-19 19:09:56 +01:00
|
|
|
case DOWN: {
|
2012-12-19 03:57:38 +01:00
|
|
|
pnX = 1 + getCharge(itemStack) * 2;
|
|
|
|
pnZ = 1 + getCharge(itemStack) * 2;
|
|
|
|
break;
|
|
|
|
}
|
2012-12-19 19:09:56 +01:00
|
|
|
case NORTH: {
|
|
|
|
pnX = 1 + getCharge(itemStack) * 2;
|
|
|
|
pnY = 1 + getCharge(itemStack) * 2;
|
2012-12-19 03:57:38 +01:00
|
|
|
break;
|
|
|
|
}
|
2012-12-19 19:09:56 +01:00
|
|
|
case SOUTH: {
|
2012-12-19 03:57:38 +01:00
|
|
|
pnX = 1 + getCharge(itemStack) * 2;
|
|
|
|
pnY = 1 + getCharge(itemStack) * 2;
|
|
|
|
break;
|
|
|
|
}
|
2012-12-19 19:09:56 +01:00
|
|
|
case EAST: {
|
2012-12-19 03:57:38 +01:00
|
|
|
pnY = 1 + getCharge(itemStack) * 2;
|
|
|
|
pnZ = 1 + getCharge(itemStack) * 2;
|
|
|
|
break;
|
|
|
|
}
|
2012-12-19 19:09:56 +01:00
|
|
|
case WEST: {
|
2012-12-19 03:57:38 +01:00
|
|
|
pnY = 1 + getCharge(itemStack) * 2;
|
|
|
|
pnZ = 1 + getCharge(itemStack) * 2;
|
|
|
|
break;
|
|
|
|
}
|
2012-12-19 19:09:56 +01:00
|
|
|
case UNKNOWN: {
|
2012-12-19 03:57:38 +01:00
|
|
|
pnX = 0;
|
|
|
|
pnY = 0;
|
|
|
|
pnZ = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-12-19 19:09:56 +01:00
|
|
|
|
|
|
|
EquivalentExchange3.proxy.sendWorldEventPacket(ActionTypes.TRANSMUTATION, x, y, z, (byte) sideHit, (byte) pnX, (byte) pnY, (byte) pnZ, TransmutationHelper.formatTargetBlockInfo(TransmutationHelper.targetBlockStack));
|
2012-12-18 23:06:00 +01:00
|
|
|
}
|
2012-12-05 20:33:03 +01:00
|
|
|
}
|
2012-10-29 04:16:32 +01:00
|
|
|
}
|
2012-11-30 16:47:18 +01:00
|
|
|
|
2012-11-26 03:11:12 +01:00
|
|
|
@Override
|
|
|
|
public short getCharge(ItemStack stack) {
|
2012-11-30 16:47:18 +01:00
|
|
|
|
2012-12-05 20:33:03 +01:00
|
|
|
return NBTHelper.getShort(stack, Strings.NBT_ITEM_CHARGE_LEVEL_KEY);
|
2012-11-26 03:11:12 +01:00
|
|
|
}
|
2012-10-29 04:16:32 +01:00
|
|
|
|
|
|
|
@Override
|
2012-11-26 03:11:12 +01:00
|
|
|
public void setCharge(ItemStack stack, short charge) {
|
2012-11-30 16:47:18 +01:00
|
|
|
|
2012-10-29 04:16:32 +01:00
|
|
|
if (charge <= maxChargeLevel) {
|
2012-12-05 20:33:03 +01:00
|
|
|
NBTHelper.setShort(stack, Strings.NBT_ITEM_CHARGE_LEVEL_KEY, charge);
|
2012-10-29 04:16:32 +01:00
|
|
|
}
|
|
|
|
}
|
2012-11-30 16:47:18 +01:00
|
|
|
|
2012-10-29 04:16:32 +01:00
|
|
|
@Override
|
2012-11-26 03:11:12 +01:00
|
|
|
public void increaseCharge(ItemStack stack) {
|
2012-11-30 16:47:18 +01:00
|
|
|
|
2012-12-05 20:33:03 +01:00
|
|
|
if (NBTHelper.getShort(stack, Strings.NBT_ITEM_CHARGE_LEVEL_KEY) < maxChargeLevel) {
|
|
|
|
NBTHelper.setShort(stack, Strings.NBT_ITEM_CHARGE_LEVEL_KEY, (short) (NBTHelper.getShort(stack, Strings.NBT_ITEM_CHARGE_LEVEL_KEY) + 1));
|
2012-10-29 04:16:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-26 03:11:12 +01:00
|
|
|
public void decreaseCharge(ItemStack stack) {
|
2012-11-30 16:47:18 +01:00
|
|
|
|
2012-12-05 20:33:03 +01:00
|
|
|
if (NBTHelper.getShort(stack, Strings.NBT_ITEM_CHARGE_LEVEL_KEY) > 0) {
|
|
|
|
NBTHelper.setShort(stack, Strings.NBT_ITEM_CHARGE_LEVEL_KEY, (short) (NBTHelper.getShort(stack, Strings.NBT_ITEM_CHARGE_LEVEL_KEY) - 1));
|
2012-10-29 04:16:32 +01:00
|
|
|
}
|
|
|
|
}
|
2012-08-25 08:46:51 +02:00
|
|
|
|
2012-11-30 16:47:18 +01:00
|
|
|
@Override
|
2012-11-30 20:03:36 +01:00
|
|
|
public void doKeyBindingAction(EntityPlayer thePlayer, ItemStack itemStack, String keyBinding) {
|
2012-11-30 16:47:18 +01:00
|
|
|
|
2012-12-05 20:33:03 +01:00
|
|
|
if (keyBinding.equals(ConfigurationSettings.KEYBINDING_EXTRA)) {
|
2012-11-30 16:47:18 +01:00
|
|
|
openPortableCrafting(thePlayer);
|
|
|
|
}
|
2012-12-18 23:06:00 +01:00
|
|
|
else if (keyBinding.equals(ConfigurationSettings.KEYBINDING_TOGGLE)) {
|
2012-12-19 22:56:49 +01:00
|
|
|
if (TransmutationHelper.targetBlockStack != null) {
|
2012-12-21 20:01:23 +01:00
|
|
|
TransmutationHelper.targetBlockStack = TransmutationHelper.getNextBlock(TransmutationHelper.targetBlockStack.itemID, TransmutationHelper.targetBlockStack.getItemDamage());
|
2012-12-19 22:56:49 +01:00
|
|
|
}
|
2012-12-18 23:06:00 +01:00
|
|
|
}
|
2012-12-05 20:33:03 +01:00
|
|
|
else if (keyBinding.equals(ConfigurationSettings.KEYBINDING_CHARGE)) {
|
2012-11-30 20:03:36 +01:00
|
|
|
if (!thePlayer.isSneaking()) {
|
2012-12-19 22:56:49 +01:00
|
|
|
if (getCharge(itemStack) == maxChargeLevel) {
|
|
|
|
thePlayer.worldObj.playSoundAtEntity(thePlayer, Sounds.CHARGE_FAIL, 0.5F, 0.5F + (0.5F * (getCharge(itemStack) * 1.0F / maxChargeLevel)));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
increaseCharge(itemStack);
|
|
|
|
thePlayer.worldObj.playSoundAtEntity(thePlayer, Sounds.CHARGE_UP, 0.5F, 0.5F + (0.5F * (getCharge(itemStack) * 1.0F / maxChargeLevel)));
|
|
|
|
}
|
2012-11-30 20:03:36 +01:00
|
|
|
}
|
|
|
|
else {
|
2012-12-19 22:56:49 +01:00
|
|
|
if (getCharge(itemStack) == 0) {
|
|
|
|
thePlayer.worldObj.playSoundAtEntity(thePlayer, Sounds.CHARGE_FAIL, 0.5F, 0.5F + (0.5F * (getCharge(itemStack) * 1.0F / maxChargeLevel)));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
decreaseCharge(itemStack);
|
|
|
|
thePlayer.worldObj.playSoundAtEntity(thePlayer, Sounds.CHARGE_DOWN, 0.5F, 1.0F - (0.5F - (0.5F * (getCharge(itemStack) * 1.0F / maxChargeLevel))));
|
|
|
|
}
|
2012-11-30 20:03:36 +01:00
|
|
|
}
|
|
|
|
}
|
2012-11-30 21:45:32 +01:00
|
|
|
|
2012-11-30 16:47:18 +01:00
|
|
|
}
|
|
|
|
|
2012-08-25 08:07:59 +02:00
|
|
|
}
|