package net.tropicraft.item.placeable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.MovingObjectPosition.MovingObjectType;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import net.tropicraft.entity.placeable.EntityUmbrella;
import net.tropicraft.info.TCNames;
import net.tropicraft.item.ItemTropicraftColored;
import net.tropicraft.registry.TCBlockRegistry;
import net.tropicraft.util.ColorHelper;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ItemUmbrella extends ItemTropicraftColored {
@SideOnly(Side.CLIENT)
private IIcon overlayIcon;
public ItemUmbrella() {
super();
this.setTextureName(TCNames.umbrella);
}
@Override
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) {
int color = ColorHelper.getColorFromDamage(itemstack.getItemDamage());
float f = 1.0F;
float f1 = entityplayer.prevRotationPitch + (entityplayer.rotationPitch - entityplayer.prevRotationPitch) * f;
float f2 = entityplayer.prevRotationYaw + (entityplayer.rotationYaw - entityplayer.prevRotationYaw) * f;
double d = entityplayer.prevPosX + (entityplayer.posX - entityplayer.prevPosX) * (double) f;
double d1 = (entityplayer.prevPosY + (entityplayer.posY - entityplayer.prevPosY) * (double) f + 1.6200000000000001D) - (double) entityplayer.yOffset;
double d2 = entityplayer.prevPosZ + (entityplayer.posZ - entityplayer.prevPosZ) * (double) f;
Vec3 vec3d = Vec3.createVectorHelper(d, d1, d2);
float f3 = MathHelper.cos(-f2 * 0.01745329F - 3.141593F);
float f4 = MathHelper.sin(-f2 * 0.01745329F - 3.141593F);
float f5 = -MathHelper.cos(-f1 * 0.01745329F);
float f6 = MathHelper.sin(-f1 * 0.01745329F);
float f7 = f4 * f5;
float f8 = f6;
float f9 = f3 * f5;
double d3 = 5D;
Vec3 vec3d1 = vec3d.addVector((double) f7 * d3, (double) f8 * d3, (double) f9 * d3);
MovingObjectPosition movingobjectposition = world.rayTraceBlocks(vec3d, vec3d1, true);
if (movingobjectposition == null) {
return itemstack;
}
if (movingobjectposition.typeOfHit == MovingObjectType.BLOCK && movingobjectposition.sideHit == 1) {
int i = movingobjectposition.blockX;
int j = movingobjectposition.blockY;
int k = movingobjectposition.blockZ;
if (!world.isRemote) {
if (world.getBlock(i, j, k) == Blocks.snow) {
j--;
}
world.spawnEntityInWorld(new EntityUmbrella(world, i, j + 1.01, k, color));
// Place RAIN STOPPERS!!!
int y = j + 4;
for (int x = i - 3; x <= i + 2; x++) {
for (int z = k - 3; z <= k + 2; z++) {
world.setBlock(x, y, z, TCBlockRegistry.rainStopper);
}
}
}
if(!entityplayer.capabilities.isCreativeMode)
itemstack.stackSize--;
}
return itemstack;
}
}