package micdoodle8.mods.galacticraft.core.items; import micdoodle8.mods.galacticraft.api.entity.IRocketType.EnumRocketType; import micdoodle8.mods.galacticraft.api.item.IHoldableItem; import micdoodle8.mods.galacticraft.core.GCBlocks; import micdoodle8.mods.galacticraft.core.GCFluids; import micdoodle8.mods.galacticraft.core.GalacticraftCore; import micdoodle8.mods.galacticraft.core.entities.EntityTier1Rocket; import micdoodle8.mods.galacticraft.core.proxy.ClientProxyCore; import micdoodle8.mods.galacticraft.core.tile.TileEntityLandingPad; import micdoodle8.mods.galacticraft.core.util.EnumColor; import micdoodle8.mods.galacticraft.core.util.EnumSortCategoryItem; import micdoodle8.mods.galacticraft.core.util.GCCoreUtil; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.EnumRarity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fml.client.FMLClientHandler; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import java.util.List; public class ItemTier1Rocket extends Item implements IHoldableItem, ISortableItem { public ItemTier1Rocket(String assetName) { super(); this.setMaxDamage(0); this.setHasSubtypes(true); this.setMaxStackSize(1); //this.setTextureName("arrow"); this.setUnlocalizedName(assetName); } @Override public CreativeTabs getCreativeTab() { return GalacticraftCore.galacticraftItemsTab; } @Override public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) { boolean padFound = false; TileEntity tile = null; if (worldIn.isRemote && playerIn instanceof EntityPlayerSP) { ClientProxyCore.playerClientHandler.onBuild(8, (EntityPlayerSP) playerIn); return false; } else { float centerX = -1; float centerY = -1; float centerZ = -1; for (int i = -1; i < 2; i++) { for (int j = -1; j < 2; j++) { BlockPos pos1 = pos.add(i, 0, j); IBlockState state = worldIn.getBlockState(pos1); final Block id = state.getBlock(); int meta = id.getMetaFromState(state); if (id == GCBlocks.landingPadFull && meta == 0) { padFound = true; tile = worldIn.getTileEntity(pos.add(i, 0, j)); centerX = pos.getX() + i + 0.5F; centerY = pos.getY() + 0.4F; centerZ = pos.getZ() + j + 0.5F; break; } } if (padFound) { break; } } if (padFound) { //Check whether there is already a rocket on the pad if (tile instanceof TileEntityLandingPad) { if (((TileEntityLandingPad) tile).getDockedEntity() != null) { return false; } } else { return false; } final EntityTier1Rocket spaceship = new EntityTier1Rocket(worldIn, centerX, centerY, centerZ, EnumRocketType.values()[stack.getItemDamage()]); spaceship.setPosition(spaceship.posX, spaceship.posY + spaceship.getOnPadYOffset(), spaceship.posZ); worldIn.spawnEntityInWorld(spaceship); if (stack.hasTagCompound() && stack.getTagCompound().hasKey("RocketFuel")) { spaceship.fuelTank.fill(new FluidStack(GCFluids.fluidFuel, stack.getTagCompound().getInteger("RocketFuel")), true); } if (!playerIn.capabilities.isCreativeMode) { stack.stackSize--; if (stack.stackSize <= 0) { stack = null; } } if (spaceship.rocketType.getPreFueled()) { spaceship.fuelTank.fill(new FluidStack(GCFluids.fluidFuel, spaceship.getMaxFuel()), true); } } else { return false; } } return true; } @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public void getSubItems(Item par1, CreativeTabs par2CreativeTabs, List par3List) { for (int i = 0; i < EnumRocketType.values().length; i++) { par3List.add(new ItemStack(par1, 1, i)); } } @Override @SideOnly(Side.CLIENT) public EnumRarity getRarity(ItemStack par1ItemStack) { return ClientProxyCore.galacticraftItem; } @SuppressWarnings({ "unchecked", "rawtypes" }) @Override @SideOnly(Side.CLIENT) public void addInformation(ItemStack par1ItemStack, EntityPlayer player, List<String> tooltip, boolean b) { EnumRocketType type = EnumRocketType.values()[par1ItemStack.getItemDamage()]; if (!type.getTooltip().isEmpty()) { tooltip.add(type.getTooltip()); } if (type.getPreFueled()) { tooltip.add(EnumColor.RED + "\u00a7o" + GCCoreUtil.translate("gui.creative_only.desc")); } if (par1ItemStack.hasTagCompound() && par1ItemStack.getTagCompound().hasKey("RocketFuel")) { EntityTier1Rocket rocket = new EntityTier1Rocket(FMLClientHandler.instance().getWorldClient(), 0, 0, 0, EnumRocketType.values()[par1ItemStack.getItemDamage()]); tooltip.add(GCCoreUtil.translate("gui.message.fuel.name") + ": " + par1ItemStack.getTagCompound().getInteger("RocketFuel") + " / " + rocket.fuelTank.getCapacity()); } } @Override public boolean shouldHoldLeftHandUp(EntityPlayer player) { return true; } @Override public boolean shouldHoldRightHandUp(EntityPlayer player) { return true; } @Override public boolean shouldCrouch(EntityPlayer player) { return true; } @Override public EnumSortCategoryItem getCategory(int meta) { return EnumSortCategoryItem.ROCKET; } }